feat: вкладки конфигуратора только из qt_settings, без JS-копии

- кнопки вкладок строятся из tab_config (порядок, label); удалённая на
  сервере вкладка (SW) больше не висит статической кнопкой;
- TAB_CONFIG на странице содержит только «Other», остальное — из
  /api/configurator-settings; убраны захардкоженные фильтры категорий по
  типу и ALWAYS_VISIBLE_TABS; тип без allowlist видит все категории;
- настройки грузятся до категорий и до фильтрации по типу конфигурации;
- единственный fallback — Go-дефолты в handlers/component.go;
  always_visible_tabs по умолчанию ["base"].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail ChusavitinandClaude Opus 5.5 committed 2026-09-24 17:23:48 +03:00
1 parent aefe167590
commit 8e633a2f12
4 files changed
+77 -110

No files matched your search

+3 -1
View File
@@ -233,7 +233,9 @@ Rules:
- 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;
- absent or unparseable settings: `GET /api/configurator-settings` serves the Go-side default for that
key only (`internal/handlers/component.go`); this is the single fallback — the configurator page
holds no copy of tabs/categories and builds its tab buttons from the served `tab_config`;
- `config_types[].categories` is an allowlist: a category absent from all types is shown everywhere;
- `qt_categories.name` and `qt_categories.name_ru` are not used by QF runtime; do not depend on them.
+28 -8
View File
@@ -43,7 +43,7 @@ category codes that are allowed for each type. QF uses this for:
"MB","CPU","MEM","RAID",
"SSD","HDD","M2","EDSFF","HHHL",
"GPU","NIC","HCA","DPU","HBA",
"PSU","PS","ACC","RISERS","CARD","BB"
"PSU","PS","ACC","RISERS","CARD","BB","SFP"
]
},
{
@@ -53,7 +53,7 @@ category codes that are allowed for each type. QF uses this for:
"categories": [
"DKC","CPU","MEM","PS",
"SSD","HDD","M2","EDSFF","HHHL",
"NIC","HBA","HCA","ACC","CARD"
"NIC","HBA","HCA","ACC","CARD","SFP"
]
}
]
@@ -109,7 +109,16 @@ single-select mode.
]
},
{ "key": "power", "label": "Power", "single_select": false, "categories": ["PS","PSU"] },
{ "key": "accessories", "label": "Accessories", "single_select": false, "categories": ["ACC","CARD"] },
{
"key": "accessories",
"label": "Accessories",
"single_select": false,
"categories": ["ACC","CARD","SFP"],
"sections": [
{ "title": "Аксессуары", "categories": ["ACC","CARD"] },
{ "title": "Трансиверы", "categories": ["SFP"] }
]
},
{ "key": "sw", "label": "SW", "single_select": false, "categories": ["SW"] }
]
```
@@ -126,9 +135,15 @@ contain any items. Other tabs are hidden when empty.
**Value format:** JSON string array.
```json
["base", "storage", "pci"]
["base"]
```
"Empty" is evaluated after the per-`config_type` category filter, so with only
`base` listed a tab such as Storage/PCI shows for a server configuration (its
categories have components) and hides for a type whose allowlist excludes all of
its categories (e.g. networking). Listing a tab here forces it visible for every
config type.
---
### `required_categories`
@@ -200,10 +215,15 @@ current as the regulation evolves.
## Backward compatibility
- If `qt_settings` does not exist (old server): QF logs `Warn` during sync and
leaves `local_qt_settings` empty. The frontend falls back to hardcoded defaults
for all four settings. No crash, no data loss.
- If a specific key is absent from `qt_settings`: QF falls back to the hardcoded
default for that key only.
leaves `local_qt_settings` empty. `GET /api/configurator-settings` then serves
the Go-side defaults (`internal/handlers/component.go`, `default*()`) for every
setting. No crash, no data loss.
- If a specific key is absent from `qt_settings`: the same Go-side default is served
for that key only.
- The Go-side defaults are the **only** fallback and are not kept in step with the
server — change tabs/categories in `qt_settings`, not in code. The configurator page
has no JS copy: `TAB_CONFIG` (except "Other") and the tab buttons are built from the
served `tab_config`; a config type with no `config_types` allowlist sees all categories.
- Old QF clients that do not know about `local_qt_settings` continue to use their
hardcoded JS constants unchanged.
+6 -1
View File
@@ -118,6 +118,11 @@ func (h *ComponentHandler) GetCategories(c *gin.Context) {
c.JSON(http.StatusOK, models.DefaultCategories)
}
// GetConfiguratorSettings serves the synced qt_settings. The default*() values
// below are the only client-side fallback, used per key when the local cache has
// no such setting (e.g. before the first sync); they are not kept in step with
// the server — edit qt_settings in MariaDB, not these. The configurator page has
// no fallback of its own.
func (h *ComponentHandler) GetConfiguratorSettings(c *gin.Context) {
s, _ := h.localDB.GetConfiguratorSettings()
if s == nil {
@@ -131,7 +136,7 @@ func (h *ComponentHandler) GetConfiguratorSettings(c *gin.Context) {
s.TabConfig = defaultTabConfig()
}
if len(s.AlwaysVisibleTabs) == 0 {
s.AlwaysVisibleTabs = []string{"base", "storage", "pci"}
s.AlwaysVisibleTabs = []string{"base"}
}
if len(s.RequiredCategories) == 0 {
s.RequiredCategories = map[string][]string{"server": {"CPU", "MEM", "BB"}}
+40 -100
View File
@@ -103,34 +103,7 @@
<div class="bg-white rounded-lg shadow">
<div class="border-b">
<nav class="flex overflow-x-auto" id="category-tabs">
<button onclick="switchTab('base')" data-tab="base"
class="tab-btn px-4 py-3 text-sm font-medium border-b-2 border-blue-600 text-blue-600 whitespace-nowrap">
Base
</button>
<button onclick="switchTab('storage')" data-tab="storage"
class="tab-btn px-4 py-3 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 whitespace-nowrap">
Storage
</button>
<button onclick="switchTab('pci')" data-tab="pci"
class="tab-btn px-4 py-3 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 whitespace-nowrap">
PCI
</button>
<button onclick="switchTab('power')" data-tab="power"
class="tab-btn px-4 py-3 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 whitespace-nowrap">
Power
</button>
<button onclick="switchTab('accessories')" data-tab="accessories"
class="tab-btn px-4 py-3 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 whitespace-nowrap">
Accessories
</button>
<button onclick="switchTab('sw')" data-tab="sw"
class="tab-btn px-4 py-3 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 whitespace-nowrap">
SW
</button>
<button onclick="switchTab('other')" data-tab="other"
class="tab-btn px-4 py-3 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 whitespace-nowrap">
Other
</button>
<!-- Buttons are rendered from TAB_CONFIG (qt_settings.tab_config) by renderTabButtons() -->
</nav>
</div>
@@ -431,48 +404,10 @@
</style>
<script>
// Tab configuration - will be populated dynamically
// Tab configuration comes from /api/configurator-settings (qt_settings.tab_config,
// or the Go-side fallback when the key is absent) — see applyServerSettings().
// Only "other" is client-owned: it collects categories not listed in any tab.
let TAB_CONFIG = {
base: {
categories: ['MB', 'CPU', 'MEM', 'ENC', 'DKC', 'CTL'],
singleSelect: true,
label: 'Base'
},
storage: {
categories: ['RAID', 'M2', 'SSD', 'HDD', 'EDSFF', 'HHHL'],
singleSelect: false,
label: 'Storage',
sections: [
{ title: 'RAID Контроллеры', categories: ['RAID'] },
{ title: 'Диски', categories: ['M2', 'SSD', 'HDD', 'EDSFF', 'HHHL'] }
]
},
pci: {
categories: ['GPU', 'DPU', 'NIC', 'HCA', 'HBA', 'HIC'],
singleSelect: false,
label: 'PCI',
sections: [
{ title: 'GPU / DPU', categories: ['GPU', 'DPU'] },
{ title: 'NIC / HCA', categories: ['NIC', 'HCA'] },
{ title: 'HBA', categories: ['HBA'] },
{ title: 'HIC', categories: ['HIC'] }
]
},
power: {
categories: ['PS', 'PSU'],
singleSelect: false,
label: 'Power'
},
accessories: {
categories: ['ACC', 'CARD'],
singleSelect: false,
label: 'Accessories'
},
sw: {
categories: ['SW'],
singleSelect: false,
label: 'SW'
},
other: {
categories: [],
singleSelect: false,
@@ -579,7 +514,7 @@ let allComponents = [];
let cart = [];
let categoryOrderMap = {}; // Category code -> display_order mapping
let configTypeCategoryMap = {}; // configTypeCode → Set<UPPER_CODE> of allowed categories (from server)
let alwaysVisibleTabsSet = null; // Set<tabKey> — null means use hardcoded fallback
let alwaysVisibleTabsSet = new Set(); // Set<tabKey> from qt_settings.always_visible_tabs
let requiredCategoriesMap = {}; // configTypeCode → Set<UPPER_CODE> of required categories
let autoSaveTimeout = null; // Timeout for debounced autosave
let hasUnsavedChanges = false;
@@ -975,6 +910,7 @@ function applyServerSettings(settings) {
supportPricingTable = settings.support_pricing;
}
renderTabButtons();
applyConfigTypeToTabs();
updateTabVisibility();
updateRequiredCategoryBadges();
@@ -1017,9 +953,10 @@ document.addEventListener('DOMContentLoaded', async function() {
return;
}
// Load categories and configurator settings in background (defaults are usable immediately).
const categoriesPromise = loadCategoriesFromAPI().catch(() => {});
loadCfgSettings().then(s => applyServerSettings(s)).catch(() => {});
// Tabs come from configurator settings; "other" is derived from them, so
// categories load after settings.
const settingsPromise = loadCfgSettings().then(s => applyServerSettings(s)).catch(() => {});
const categoriesPromise = settingsPromise.then(() => loadCategoriesFromAPI()).catch(() => {});
try {
const resp = await fetch('/api/configs/' + configUUID);
@@ -1033,6 +970,7 @@ document.addEventListener('DOMContentLoaded', async function() {
const config = await resp.json();
configName = config.name;
configType = config.config_type || 'server';
await settingsPromise;
applyConfigTypeToTabs();
currentVersionNo = config.current_version_no || 1;
projectUUID = config.project_uuid || '';
@@ -1388,6 +1326,26 @@ function getTabForCategory(category) {
return 'other';
}
// Tab buttons mirror TAB_CONFIG (qt_settings.tab_config order, "other" last), so
// tabs added, removed or relabelled on the server need no client release.
function renderTabButtons() {
const nav = document.getElementById('category-tabs');
if (!nav) return;
const keys = Object.keys(TAB_CONFIG).filter(k => k !== 'other');
keys.push('other');
if (!TAB_CONFIG[currentTab]) currentTab = firstTabKey();
nav.replaceChildren(...keys.map(key => {
const btn = document.createElement('button');
btn.type = 'button';
btn.dataset.tab = key;
btn.className = 'tab-btn px-4 py-3 text-sm font-medium border-b-2 whitespace-nowrap hover:text-gray-700 ' +
(key === currentTab ? 'border-blue-600 text-blue-600' : 'border-transparent text-gray-500');
btn.textContent = TAB_CONFIG[key]?.label || key;
btn.addEventListener('click', () => switchTab(key));
return btn;
}));
}
function switchTab(tab) {
currentTab = tab;
document.querySelectorAll('.tab-btn').forEach(btn => {
@@ -1403,35 +1361,15 @@ function switchTab(tab) {
renderTab();
}
// Hardcoded fallback constants — used only when server has not provided config_types data
const ALWAYS_VISIBLE_TABS = new Set(['base', 'storage', 'pci']);
const STORAGE_ONLY_BASE_CATEGORIES = ['DKC', 'CTL', 'ENC'];
const SERVER_ONLY_BASE_CATEGORIES = ['MB', 'CPU', 'MEM'];
const STORAGE_HIDDEN_STORAGE_CATEGORIES = ['RAID'];
const STORAGE_HIDDEN_PCI_CATEGORIES = ['GPU', 'DPU'];
const STORAGE_HIDDEN_POWER_CATEGORIES = ['PS', 'PSU'];
// A config type without an allowlist in config_types sees every category.
function isCategoryVisibleForConfigType(code, cfgType) {
const allowed = configTypeCategoryMap[cfgType];
if (!allowed || allowed.size === 0) return _hardcodedCategoryVisible(code, cfgType);
if (!allowed || allowed.size === 0) return true;
return allowed.has(code.toUpperCase());
}
function _hardcodedCategoryVisible(code, cfgType) {
if (cfgType === 'storage') {
if (STORAGE_ONLY_BASE_CATEGORIES.includes(code)) return true;
if (SERVER_ONLY_BASE_CATEGORIES.includes(code)) return false;
if (STORAGE_HIDDEN_STORAGE_CATEGORIES.includes(code)) return false;
if (STORAGE_HIDDEN_PCI_CATEGORIES.includes(code)) return false;
if (STORAGE_HIDDEN_POWER_CATEGORIES.includes(code)) return false;
} else {
if (STORAGE_ONLY_BASE_CATEGORIES.includes(code)) return false;
}
return true;
}
function _effectiveAlwaysVisibleTabs() {
return alwaysVisibleTabsSet || ALWAYS_VISIBLE_TABS;
function firstTabKey() {
return Object.keys(TAB_CONFIG).find(k => k !== 'other') || 'other';
}
function applyConfigTypeToTabs() {
@@ -1466,7 +1404,7 @@ function applyConfigTypeToTabs() {
}
function updateTabVisibility() {
const visibleTabs = _effectiveAlwaysVisibleTabs();
const visibleTabs = alwaysVisibleTabsSet;
for (const tabId of Object.keys(TAB_CONFIG)) {
if (visibleTabs.has(tabId)) continue;
const btn = document.querySelector(`[data-tab="${tabId}"]`);
@@ -1477,15 +1415,16 @@ function updateTabVisibility() {
});
const visible = hasComponents || hasCartItems;
btn.classList.toggle('hidden', !visible);
// If the current tab just got hidden, fall back to base
// If the current tab just got hidden, fall back to the first tab
if (!visible && currentTab === tabId) {
switchTab('base');
switchTab(firstTabKey());
}
}
}
function getComponentsForTab(tab) {
const config = TAB_CONFIG[tab];
if (!config) return [];
return allComponents.filter(comp => {
const category = getComponentCategory(comp);
if (tab === 'other') {
@@ -1503,6 +1442,7 @@ function getComponentsForCategory(category) {
function renderTab() {
const config = TAB_CONFIG[currentTab];
if (!config) return; // tab_config not loaded yet
const components = getComponentsForTab(currentTab);
if (config.singleSelect) {