Add project variants and UI updates
This commit is contained in:
@@ -5,14 +5,25 @@
|
||||
<!-- Header with config name and back button -->
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center space-x-4">
|
||||
<a href="/configs" class="text-gray-500 hover:text-gray-700">
|
||||
<a href="/projects" class="text-gray-500 hover:text-gray-700" title="Все проекты">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 9.75L12 3l9 6.75v9A2.25 2.25 0 0118.75 21h-13.5A2.25 2.25 0 013 18.75v-9z"></path>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 21v-6h6v6"></path>
|
||||
</svg>
|
||||
</a>
|
||||
<h1 class="text-2xl font-bold">
|
||||
<span id="config-name">Конфигуратор</span>
|
||||
</h1>
|
||||
<div class="text-2xl font-bold flex items-center gap-2" id="config-breadcrumbs">
|
||||
<a id="breadcrumb-project-code-link" href="/projects" class="text-blue-700 hover:underline">
|
||||
<span id="breadcrumb-project-code">—</span>
|
||||
</a>
|
||||
<span class="text-gray-400">-</span>
|
||||
<a id="breadcrumb-project-variant-link" href="/projects" class="text-blue-700 hover:underline">
|
||||
<span id="breadcrumb-project-variant">main</span>
|
||||
</a>
|
||||
<span class="text-gray-400">-</span>
|
||||
<span id="breadcrumb-config-name">Конфигуратор</span>
|
||||
<span class="text-gray-400">-</span>
|
||||
<span id="breadcrumb-config-version">v1</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="save-buttons" class="hidden flex items-center space-x-2">
|
||||
<button id="refresh-prices-btn" onclick="refreshPrices()" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">
|
||||
@@ -329,6 +340,67 @@ let configUUID = '{{.ConfigUUID}}';
|
||||
let configName = '';
|
||||
let projectUUID = '';
|
||||
let projectName = '';
|
||||
let projectCode = '';
|
||||
let projectVariant = '';
|
||||
let projectIndexLoaded = false;
|
||||
let projectByUUID = {};
|
||||
let projectMainByCode = {};
|
||||
|
||||
async function loadProjectIndex() {
|
||||
if (projectIndexLoaded) return;
|
||||
try {
|
||||
const resp = await fetch('/api/projects/all');
|
||||
if (!resp.ok) return;
|
||||
const data = await resp.json();
|
||||
const allProjects = Array.isArray(data) ? data : (data.projects || []);
|
||||
projectByUUID = {};
|
||||
projectMainByCode = {};
|
||||
allProjects.forEach(p => {
|
||||
projectByUUID[p.uuid] = p;
|
||||
const code = (p.code || '').trim();
|
||||
const variant = (p.variant || '').trim();
|
||||
if (code && (variant === '' || variant === 'main')) {
|
||||
if (!projectMainByCode[code]) {
|
||||
projectMainByCode[code] = p.uuid;
|
||||
}
|
||||
}
|
||||
});
|
||||
projectIndexLoaded = true;
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
function updateConfigBreadcrumbs() {
|
||||
const codeEl = document.getElementById('breadcrumb-project-code');
|
||||
const variantEl = document.getElementById('breadcrumb-project-variant');
|
||||
const configEl = document.getElementById('breadcrumb-config-name');
|
||||
const versionEl = document.getElementById('breadcrumb-config-version');
|
||||
const projectCodeLinkEl = document.getElementById('breadcrumb-project-code-link');
|
||||
const projectVariantLinkEl = document.getElementById('breadcrumb-project-variant-link');
|
||||
|
||||
let code = 'Без проекта';
|
||||
let variant = 'main';
|
||||
if (projectUUID && projectByUUID[projectUUID]) {
|
||||
code = (projectByUUID[projectUUID].code || '').trim() || 'Без проекта';
|
||||
const rawVariant = (projectByUUID[projectUUID].variant || '').trim();
|
||||
variant = rawVariant === '' ? 'main' : rawVariant;
|
||||
if (projectCodeLinkEl) {
|
||||
const mainUUID = projectMainByCode[code];
|
||||
projectCodeLinkEl.href = mainUUID ? ('/projects/' + mainUUID) : ('/projects/' + projectUUID);
|
||||
}
|
||||
if (projectVariantLinkEl) {
|
||||
projectVariantLinkEl.href = '/projects/' + projectUUID;
|
||||
}
|
||||
} else {
|
||||
if (projectCodeLinkEl) projectCodeLinkEl.href = '/projects';
|
||||
if (projectVariantLinkEl) projectVariantLinkEl.href = '/projects';
|
||||
}
|
||||
codeEl.textContent = code;
|
||||
variantEl.textContent = variant;
|
||||
configEl.textContent = configName || 'Конфигурация';
|
||||
versionEl.textContent = 'v1';
|
||||
}
|
||||
let currentTab = 'base';
|
||||
let allComponents = [];
|
||||
let cart = [];
|
||||
@@ -617,7 +689,8 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
const config = await resp.json();
|
||||
configName = config.name;
|
||||
projectUUID = config.project_uuid || '';
|
||||
document.getElementById('config-name').textContent = config.name;
|
||||
await loadProjectIndex();
|
||||
updateConfigBreadcrumbs();
|
||||
document.getElementById('save-buttons').classList.remove('hidden');
|
||||
|
||||
// Set server count from config
|
||||
|
||||
Reference in New Issue
Block a user