fix: не терять новые категории (SYS) на вкладке «Прочее»

ASSIGNED_CATEGORIES пересчитывался из всех вкладок TAB_CONFIG уже после
того, как неизвестные категории попадали в TAB_CONFIG.other — из-за
этого они сами себя исключали из фильтра "not assigned" на вкладке
«Прочее». Баг был в двух местах (loadCategoriesFromAPI и
applyServerSettings), второе не проявлялось только потому, что синк
qt_settings с сервера никогда не был подключён к воркеру.

Заодно подключил Service.SyncQtSettings к фоновому синку (был мёртвым
кодом), чтобы tab_config/config_types и т.п. реально доезжали с сервера
до локального кеша.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-07-30 18:14:46 +03:00
co-authored by Claude Sonnet 5
parent e5aa1dfd38
commit dd70b6065b
3 changed files with 30 additions and 6 deletions
+15
View File
@@ -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)
}
+5
View File
@@ -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")
}
+10 -6
View File
@@ -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