MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / clearMultiEditFormFields

Function clearMultiEditFormFields

renderer.js:17135–17184  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17133async function autoSaveMultipleModels(field, value, options = {}) {
17134 try {
17135 // No models selected
17136 if (selectedModels.size === 0) {
17137 console.warn('No models selected for autoSaveMultipleModels');
17138 return false; // Indicate failure/no-op
17139 }
17140
17141 // Handle designer field default value (will be reapplied next)
17142 if (field === 'designer' && !value) {
17143 value = 'Unknown';
17144 }
17145
17146 // Create a copy of selectedModels to avoid issues if the set changes during iteration
17147 const modelsToUpdate = Array.from(selectedModels);
17148 console.log(`autoSaveMultipleModels: Updating ${modelsToUpdate.length} models for field ${field}`);
17149
17150 // Load all models in parallel for better performance
17151 const modelLoadPromises = modelsToUpdate.map(async (filePath, index) => {
17152 try {
17153 console.log(`[${index}] Loading model: ${filePath}`);
17154 const model = await window.electron.getModel(filePath);
17155 if (model) {
17156 console.log(`[${index}] Successfully loaded model: ${filePath}`);
17157 return { filePath, model };
17158 } else {
17159 console.warn(`[${index}] Could not find model for ${filePath} during autoSaveMultipleModels`);
17160 return null;
17161 }
17162 } catch (error) {
17163 console.error(`[${index}] Error loading model ${filePath} in autoSaveMultipleModels:`, error);
17164 return null;
17165 }
17166 });
17167
17168 // Wait for all models to load in parallel
17169 const loadedModels = await Promise.all(modelLoadPromises);
17170 console.log(`Loaded ${loadedModels.length} models, ${loadedModels.filter(r => r !== null).length} successful`);
17171
17172 // Filter out null results and prepare updates
17173 const modelUpdates = [];
17174 for (let i = 0; i < loadedModels.length; i++) {
17175 const result = loadedModels[i];
17176 if (result) {
17177 const { filePath, model } = result;
17178 console.log(`[${i}] Processing model update for: ${filePath}`);
17179 // Special handling for tags - MERGE or REPLACE based on options
17180 if (field === 'tags') {
17181 const newTags = Array.isArray(value) ? value : [];
17182 if (options.replaceTags) {
17183 // Replace tags completely (used when removing tags)
17184 model.tags = newTags.sort();
17185 console.log(`[${i}] Replacing tags with: ${newTags.join(', ')}`);
17186 } else {
17187 // Merge tags (used when adding tags)

Callers 3

showModelDetailsFunction · 0.85
updateSelectedCountFunction · 0.85
renderer.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected