MCPcopy Index your code
hub / github.com/TechJeeper/Printventory / addTagToModel

Function addTagToModel

renderer.js:14121–14190  ·  view source on GitHub ↗
(tagName, containerId, options = {})

Source from the content-addressed store, hash-verified

14119 }
14120 });
14121
14122 const allTagsArrays = await Promise.all(tagPromises);
14123
14124 // Collect unique tags across all selected files
14125 const uniqueTags = new Set();
14126 allTagsArrays.forEach(tags => {
14127 if (Array.isArray(tags)) {
14128 tags.forEach(tag => {
14129 if (tag && typeof tag === 'string') {
14130 const normalizedTag = tag.trim();
14131 if (normalizedTag) {
14132 uniqueTags.add(normalizedTag);
14133 }
14134 }
14135 });
14136 }
14137 });
14138
14139 // Sort tags alphabetically
14140 const sortedTags = Array.from(uniqueTags).sort((a, b) => a.localeCompare(b));
14141
14142 // Display tags in the container with remove functionality
14143 sortedTags.forEach(tagName => {
14144 // Check if tag already exists visually
14145 const existingTag = Array.from(multiTagsContainer.children)
14146 .find(tag => tag.getAttribute('data-tag-name') === tagName);
14147
14148 if (!existingTag) {
14149 // Create tag element with remove functionality
14150 const tag = document.createElement('div');
14151 tag.className = 'tag';
14152 tag.setAttribute('data-tag-name', tagName);
14153 tag.setAttribute('title', tagName);
14154 tag.innerHTML = `
14155 <span class="tag-text">${tagName}</span>
14156 <span class="tag-remove">×</span>
14157 `;
14158
14159 // Add remove handler with auto-save
14160 tag.querySelector('.tag-remove')?.addEventListener('click', async () => {
14161 tag.remove();
14162 // Auto-save the updated tags after REMOVAL
14163 const currentTags = Array.from(multiTagsContainer.querySelectorAll('.tag'))
14164 .map(t => t.getAttribute('data-tag-name'));
14165
14166 // Use replaceTags: true to replace tags instead of merging
14167 await autoSaveMultipleModels('tags', currentTags, { replaceTags: true });
14168
14169 // Refresh the remove tag dropdown after removal
14170 await populateRemoveTagSelect();
14171 });
14172
14173 multiTagsContainer.appendChild(tag);
14174 }
14175 });
14176 } catch (error) {
14177 console.error('Error refreshing multi-edit tags:', error);
14178 }

Callers 6

showModelDetailsFunction · 0.85
renderer.jsFile · 0.85
initializeTagsFunction · 0.85
loadModelTagsFunction · 0.85
handleItemClickFunction · 0.85
showMultiEditPanelFunction · 0.85

Calls 3

autoSaveMultipleModelsFunction · 0.85
getModelFilePathFunction · 0.85
autoSaveModelFunction · 0.85

Tested by

no test coverage detected