From a939a5f36c40ad6b466eaebc2d0aec4b487bcc67 Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Thu, 24 Sep 2026 16:59:42 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D1=82=D0=B8=D0=BF=D1=8B=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=B8=D0=B7=20qt=5Fsettings=20=D0=B2=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=BA=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0,=20=D0=BA=D0=BE=D0=BF=D0=B8=D1=8F=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D1=8F=D0=B5=D1=82=20config=5Ftype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - модалка «Новая конфигурация в проекте» строит кнопки типа из qt_settings.config_types (новый тип «Сеть» появляется без релиза); - ручная полная синхронизация (/api/sync/all) тянет qt_settings; - копирование конфигурации (в т.ч. из версии) сохраняет config_type — раньше копия СХД/сети становилась «сервером». Co-Authored-By: Claude Opus 5.5 --- bible-local/02-architecture.md | 10 +++- internal/handlers/sync.go | 8 ++- internal/services/local_configuration.go | 3 ++ .../local_configuration_config_type_test.go | 51 +++++++++++++++++++ web/templates/project_detail.html | 47 ++++++++++++++--- 5 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 internal/services/local_configuration_config_type_test.go 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 @@
-
- - @@ -626,17 +626,50 @@ async function loadConfigs() { let pdCreateConfigType = 'server'; +let pdConfigTypesLoaded = false; + +// Config types come from qt_settings.config_types (server-driven, see +// bible-local/server-contract-qt-settings.md); the two static buttons in the +// markup are only a fallback until/unless the settings load. +async function pdLoadConfigTypeButtons() { + if (pdConfigTypesLoaded) return; + let types = null; + try { + const r = await fetch('/api/configurator-settings'); + if (r.ok) types = (await r.json()).config_types; + } catch (e) { /* keep static fallback buttons */ } + if (!Array.isArray(types) || !types.length) return; + const el = document.getElementById('pd-config-type-buttons'); + if (!el) return; + el.replaceChildren(...[...types] + .sort((a, b) => (a.display_order || 0) - (b.display_order || 0)) + .map(t => { + const btn = document.createElement('button'); + btn.type = 'button'; + btn.dataset.type = t.code; + btn.textContent = t.name_ru || t.code; + btn.addEventListener('click', () => pdSetCreateType(t.code)); + return btn; + })); + pdConfigTypesLoaded = true; + const codes = types.map(t => t.code); + pdSetCreateType(codes.includes(pdCreateConfigType) ? pdCreateConfigType : codes[0]); +} + function pdSetCreateType(type) { pdCreateConfigType = type; - document.getElementById('pd-type-server-btn').className = 'flex-1 py-2 text-sm font-medium ' + - (type === 'server' ? 'bg-blue-600 text-white' : 'bg-white text-gray-700 hover:bg-gray-50'); - document.getElementById('pd-type-storage-btn').className = 'flex-1 py-2 text-sm font-medium border-l border-gray-200 ' + - (type === 'storage' ? 'bg-blue-600 text-white' : 'bg-white text-gray-700 hover:bg-gray-50'); + document.querySelectorAll('#pd-config-type-buttons button').forEach((btn, i) => { + const active = btn.dataset.type === type; + btn.className = 'flex-1 py-2 text-sm font-medium ' + + (i > 0 ? 'border-l border-gray-200 ' : '') + + (active ? 'bg-blue-600 text-white' : 'bg-white text-gray-700 hover:bg-gray-50'); + }); } function openCreateModal() { pdCreateConfigType = 'server'; pdSetCreateType('server'); + pdLoadConfigTypeButtons(); document.getElementById('create-name').value = ''; document.getElementById('create-modal').classList.remove('hidden'); document.getElementById('create-modal').classList.add('flex');