diff --git a/bible-local/02-architecture.md b/bible-local/02-architecture.md index e5a18e7..19dac45 100644 --- a/bible-local/02-architecture.md +++ b/bible-local/02-architecture.md @@ -203,12 +203,17 @@ Configurations have a `config_type` field: `"server"` (default) or `"storage"`. Rules: - `config_type` defaults to `"server"` for all existing and new configurations unless explicitly set; +- `config_type` is a free-form code (no enum on client or server); every write path — update, clone, + clone-from-version, rollback, sync push/pull — must carry it unchanged, including codes this client + does not know; - the configurator page is shared for both types; the SW tab is always visible regardless of type; - storage configurations use the same vendor_spec + PN→LOT + pricing flow as server configurations; - storage component categories map to existing tabs: `ENC`/`DKC`/`CTL` → Base, `HIC` → PCI (HIC-карты СХД; `HBA`/`NIC` — серверные, не смешивать), `SSD`/`HDD` → Storage (используют существующие серверные LOT), `ACC` → Accessories (используют существующие серверные LOT), `SW` → SW. - `DKC` = контроллерная полка (модель СХД + тип дисков + кол-во слотов + кол-во контроллеров); `CTL` = контроллер (кэш + встроенные порты); `ENC` = дисковая полка без контроллера. - the available config types and their localized names flow from `qt_settings.config_types` on the server; - QF falls back to hardcoded "server/Сервер" and "storage/СХД" when the setting is absent. + QF falls back to hardcoded "server/Сервер" and "storage/СХД" when the setting is absent; +- every "new configuration" type picker (`/configs` and the project page) renders its buttons from + `config_types` — a new type added on the server appears without a client release. ## Server-driven configurator settings (`qt_settings`) @@ -225,7 +230,8 @@ full contract and JSON schemas. | `support_pricing` | Price data for the Base tab's support-level picker (see below) | Rules: -- sync runs as part of the pricelist pull; failure is non-fatal (Warn log only); +- sync runs in the background sync worker (after the pricelist pull) and in the manual full sync + (`POST /api/sync/all`); failure is non-fatal (Warn log only); - `local_qt_settings` is a read-only cache — never written by user actions; - absent or unparseable settings: QF uses hardcoded fallbacks for that key only; - `config_types[].categories` is an allowlist: a category absent from all types is shown everywhere; diff --git a/internal/handlers/sync.go b/internal/handlers/sync.go index 366a772..061bcee 100644 --- a/internal/handlers/sync.go +++ b/internal/handlers/sync.go @@ -240,7 +240,7 @@ type SyncAllResponse struct { // SyncAll performs full bidirectional sync: // - push pending local changes (projects/configurations) to server -// - pull components, pricelists, projects, and configurations from server +// - pull components, pricelists, qt_settings, projects, and configurations from server // POST /api/sync/all func (h *SyncHandler) SyncAll(c *gin.Context) { if !h.ensureSyncReadiness(c) { @@ -282,6 +282,12 @@ func (h *SyncHandler) SyncAll(c *gin.Context) { slog.Warn("partnumber books pull failed during full sync", "error", err) } + // Configurator settings (config_types, tab_config, ...): non-fatal, the + // local cache is kept on failure. + if err := h.syncService.SyncQtSettings(); err != nil { + slog.Warn("qt_settings sync failed during full sync", "error", err) + } + projectsResult, err := h.syncService.ImportProjectsToLocal() if err != nil { slog.Error("project import failed during full sync", "error", err) diff --git a/internal/services/local_configuration.go b/internal/services/local_configuration.go index e754ccb..72dd50d 100644 --- a/internal/services/local_configuration.go +++ b/internal/services/local_configuration.go @@ -334,6 +334,7 @@ func (s *LocalConfigurationService) CloneToProject(configUUID string, ownerUsern PricelistID: original.PricelistID, WarehousePricelistID: original.WarehousePricelistID, CompetitorPricelistID: original.CompetitorPricelistID, + ConfigType: original.ConfigType, DisablePriceRefresh: original.DisablePriceRefresh, CreatedAt: time.Now(), } @@ -660,6 +661,7 @@ func (s *LocalConfigurationService) CloneNoAuthToProjectFromVersion(configUUID s return nil, fmt.Errorf("decode version snapshot for clone: %w", decErr) } snapshotCfg := localdb.LocalToConfiguration(snapshot) + snapshotCfg.ConfigType = original.ConfigType // not part of version snapshots original = snapshotCfg original.UUID = configUUID // preserve original UUID for project resolution } @@ -695,6 +697,7 @@ func (s *LocalConfigurationService) CloneNoAuthToProjectFromVersion(configUUID s PricelistID: original.PricelistID, WarehousePricelistID: original.WarehousePricelistID, CompetitorPricelistID: original.CompetitorPricelistID, + ConfigType: original.ConfigType, DisablePriceRefresh: original.DisablePriceRefresh, CreatedAt: time.Now(), } diff --git a/internal/services/local_configuration_config_type_test.go b/internal/services/local_configuration_config_type_test.go new file mode 100644 index 0000000..6de0200 --- /dev/null +++ b/internal/services/local_configuration_config_type_test.go @@ -0,0 +1,51 @@ +package services + +import ( + "testing" + + "git.mchus.pro/mchus/quoteforge/internal/models" +) + +// config_type is free-form (codes come from qt_settings.config_types), so an +// unknown code like "networking" must survive every write path unchanged. +func TestConfigTypeSurvivesUpdateAndClone(t *testing.T) { + service, local := newLocalConfigServiceForTest(t) + + created, err := service.Create("tester", &CreateConfigRequest{ + Name: "net", + Items: models.ConfigItems{{LotName: "CPU_A", Quantity: 1, UnitPrice: 1000}}, + ConfigType: "networking", + }) + if err != nil { + t.Fatalf("create: %v", err) + } + + // The configurator's save payload carries no config_type. + if _, err := service.UpdateNoAuth(created.UUID, &CreateConfigRequest{ + Name: "net", + Items: models.ConfigItems{{LotName: "CPU_A", Quantity: 2, UnitPrice: 1000}}, + }); err != nil { + t.Fatalf("update: %v", err) + } + if stored, _ := local.GetConfigurationByUUID(created.UUID); stored.ConfigType != "networking" { + t.Fatalf("config_type after update = %q, want networking", stored.ConfigType) + } + + for _, fromVersion := range []int{0, 1} { + clone, err := service.CloneNoAuthToProjectFromVersion(created.UUID, "copy", "tester", nil, fromVersion) + if err != nil { + t.Fatalf("clone from version %d: %v", fromVersion, err) + } + if stored, _ := local.GetConfigurationByUUID(clone.UUID); stored.ConfigType != "networking" { + t.Fatalf("clone from version %d: config_type = %q, want networking", fromVersion, stored.ConfigType) + } + } + + clone, err := service.CloneToProject(created.UUID, "tester", "copy2", nil) + if err != nil { + t.Fatalf("clone to project: %v", err) + } + if stored, _ := local.GetConfigurationByUUID(clone.UUID); stored.ConfigType != "networking" { + t.Fatalf("CloneToProject: config_type = %q, want networking", stored.ConfigType) + } +} diff --git a/web/templates/project_detail.html b/web/templates/project_detail.html index ace694b..dd6f5b4 100644 --- a/web/templates/project_detail.html +++ b/web/templates/project_detail.html @@ -82,12 +82,12 @@