feat: типы конфигураций из qt_settings в модалке проекта, копия сохраняет config_type
- модалка «Новая конфигурация в проекте» строит кнопки типа из qt_settings.config_types (новый тип «Сеть» появляется без релиза); - ручная полная синхронизация (/api/sync/all) тянет qt_settings; - копирование конфигурации (в т.ч. из версии) сохраняет config_type — раньше копия СХД/сети становилась «сервером». Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
54a7c7cc8d
commit
c26da6912f
5 files changed
+109
-10
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -82,12 +82,12 @@
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Тип оборудования</label>
|
||||
<div class="inline-flex rounded-lg border border-gray-200 overflow-hidden w-full">
|
||||
<button type="button" id="pd-type-server-btn" onclick="pdSetCreateType('server')"
|
||||
<div id="pd-config-type-buttons" class="inline-flex rounded-lg border border-gray-200 overflow-hidden w-full">
|
||||
<button type="button" data-type="server" onclick="pdSetCreateType('server')"
|
||||
class="flex-1 py-2 text-sm font-medium bg-blue-600 text-white">
|
||||
Сервер
|
||||
</button>
|
||||
<button type="button" id="pd-type-storage-btn" onclick="pdSetCreateType('storage')"
|
||||
<button type="button" data-type="storage" onclick="pdSetCreateType('storage')"
|
||||
class="flex-1 py-2 text-sm font-medium bg-white text-gray-700 hover:bg-gray-50 border-l border-gray-200">
|
||||
СХД
|
||||
</button>
|
||||
@@ -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');
|
||||
|
||||
Reference in new issue
Block a user