diff --git a/internal/services/sync/qt_settings.go b/internal/services/sync/qt_settings.go new file mode 100644 index 0000000..835ddc6 --- /dev/null +++ b/internal/services/sync/qt_settings.go @@ -0,0 +1,15 @@ +package sync + +import "fmt" + +// SyncQtSettings pulls qt_settings (tab_config, config_types, etc.) from +// MariaDB into the local cache so the configurator picks up server-driven +// category/tab changes without requiring a client rebuild. +func (s *Service) SyncQtSettings() error { + mariaDB, err := s.getDB() + if err != nil { + return fmt.Errorf("database not available: %w", err) + } + + return s.localDB.SyncQtSettings(mariaDB) +} diff --git a/internal/services/sync/worker.go b/internal/services/sync/worker.go index a2a752e..c175b6b 100644 --- a/internal/services/sync/worker.go +++ b/internal/services/sync/worker.go @@ -100,5 +100,10 @@ func (w *Worker) runSync() { w.logger.Warn("background sync: failed to pull partnumber books", "error", err) } + // Pull configurator settings (tab_config, categories, etc.) + if err := w.service.SyncQtSettings(); err != nil { + w.logger.Warn("background sync: failed to sync qt_settings", "error", err) + } + w.logger.Info("background sync cycle completed") } diff --git a/web/templates/index.html b/web/templates/index.html index 9da15eb..1c2dd24 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -832,13 +832,13 @@ async function loadCategoriesFromAPI() { .sort((a, b) => a.display_order - b.display_order) .map(cat => cat.code); + // Rebuild ASSIGNED_CATEGORIES from known (non-"other") tabs before + // populating "other", so unassigned categories aren't immediately + // excluded from the "other" tab by their own assignment. + ASSIGNED_CATEGORIES = knownCodes; + // Update "other" tab with unassigned categories TAB_CONFIG.other.categories = unassignedCategories; - - // Rebuild ASSIGNED_CATEGORIES - ASSIGNED_CATEGORIES = Object.values(TAB_CONFIG) - .flatMap(t => t.categories) - .map(c => ciStr(c)); } catch(e) { console.error('Failed to load categories, using defaults', e); // Will use default configuration if API fails @@ -882,8 +882,12 @@ function applyServerSettings(settings) { sections: tab.sections || undefined }; }); - TAB_CONFIG.other = otherTab || { categories: [], singleSelect: false, label: 'Other' }; + // Rebuild ASSIGNED_CATEGORIES from the known (non-"other") tabs only, + // before restoring .other — otherwise categories already parked in + // .other (e.g. by loadCategoriesFromAPI) get counted as "assigned" + // and immediately excluded from the "other" tab again. ASSIGNED_CATEGORIES = Object.values(TAB_CONFIG).flatMap(t => t.categories).map(c => ciStr(c)); + TAB_CONFIG.other = otherTab || { categories: [], singleSelect: false, label: 'Other' }; } // always_visible_tabs