()
| 16582 | if (!seenTags.has(tag)) { |
| 16583 | seenTags.add(tag); |
| 16584 | finalUniqueTags.push(tag); |
| 16585 | } |
| 16586 | }); |
| 16587 | |
| 16588 | // Populate dropdown |
| 16589 | if (finalUniqueTags.length === 0) { |
| 16590 | const noTagsOption = document.createElement('option'); |
| 16591 | noTagsOption.value = ''; |
| 16592 | noTagsOption.textContent = 'No tags to remove'; |
| 16593 | noTagsOption.disabled = true; |
| 16594 | removeTagSelect.appendChild(noTagsOption); |
| 16595 | } else { |
| 16596 | finalUniqueTags.forEach(tagName => { |
| 16597 | // Additional check to prevent duplicate options in the DOM |
| 16598 | const existingOption = Array.from(removeTagSelect.options).find(opt => opt.value === tagName); |
| 16599 | if (!existingOption) { |
| 16600 | const option = document.createElement('option'); |
| 16601 | option.value = tagName; |
| 16602 | option.textContent = tagName; |
| 16603 | removeTagSelect.appendChild(option); |
| 16604 | } |
| 16605 | }); |
| 16606 | } |
| 16607 | } catch (error) { |
| 16608 | console.error('Error populating remove tag select:', error); |
| 16609 | const errorOption = document.createElement('option'); |
| 16610 | errorOption.value = ''; |
| 16611 | errorOption.textContent = 'Error loading tags'; |
| 16612 | errorOption.disabled = true; |
| 16613 | removeTagSelect.appendChild(errorOption); |
| 16614 | } |
| 16615 | } |
| 16616 | |
| 16617 | // Update the addTagToModel function |
| 16618 | // skipSave: use when populating tags from DB (showModelDetails / loadModelTags) to avoid redundant saves |
| 16619 | async function addTagToModel(tagName, containerId, options = {}) { |
| 16620 | const { skipSave = false } = options; |
| 16621 | const tagContainer = document.getElementById(containerId); |
| 16622 | if (!tagContainer) { |
| 16623 | console.error(`Tag container with ID ${containerId} not found`); |
| 16624 | return; |
| 16625 | } |
| 16626 | |
| 16627 | // Check if tag already exists visually |
| 16628 | const existingTag = Array.from(tagContainer.children) |
| 16629 | .find(tag => tag.getAttribute('data-tag-name') === tagName); |
| 16630 | |
| 16631 | if (existingTag) return; // Don't add visual duplicates |
| 16632 | |
| 16633 | // Create new tag element |
| 16634 | const tag = document.createElement('div'); |
| 16635 | tag.className = 'tag'; |
| 16636 | tag.setAttribute('data-tag-name', tagName); |
| 16637 | tag.setAttribute('title', tagName); // Show full tag name on hover |
| 16638 | tag.innerHTML = ` |
| 16639 | <span class="tag-text">${tagName}</span> |
| 16640 | <span class=\"tag-remove\">×</span> |
| 16641 | `; |
no test coverage detected