Deduplicate configuration revisions and update revisions UI
This commit is contained in:
@@ -42,6 +42,35 @@ function escapeHtml(text) {
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function formatMoney(value) {
|
||||
const num = Number(value);
|
||||
if (!Number.isFinite(num)) return '—';
|
||||
return '$\u00A0' + num.toLocaleString('ru-RU', {minimumFractionDigits: 0, maximumFractionDigits: 2});
|
||||
}
|
||||
|
||||
function parseVersionSnapshot(version) {
|
||||
try {
|
||||
const raw = typeof version.data === 'string' ? version.data : '';
|
||||
if (!raw) return { article: '—', price: null, serverCount: 1 };
|
||||
const parsed = JSON.parse(raw);
|
||||
return {
|
||||
article: parsed.article || '—',
|
||||
price: typeof parsed.total_price === 'number' ? parsed.total_price : null,
|
||||
serverCount: Number.isFinite(Number(parsed.server_count)) && Number(parsed.server_count) > 0
|
||||
? Number(parsed.server_count)
|
||||
: 1
|
||||
};
|
||||
} catch (_) {
|
||||
return { article: '—', price: null, serverCount: 1 };
|
||||
}
|
||||
}
|
||||
|
||||
function truncateBreadcrumbSpecName(name) {
|
||||
const maxLength = 16;
|
||||
if (!name || name.length <= maxLength) return name;
|
||||
return name.slice(0, maxLength - 1) + '…';
|
||||
}
|
||||
|
||||
async function loadConfigInfo() {
|
||||
try {
|
||||
const resp = await fetch('/api/configs/' + configUUID);
|
||||
@@ -52,7 +81,10 @@ async function loadConfigInfo() {
|
||||
}
|
||||
configData = await resp.json();
|
||||
|
||||
document.getElementById('breadcrumb-config').textContent = configData.name || 'Конфигурация';
|
||||
const fullConfigName = configData.name || 'Конфигурация';
|
||||
const configBreadcrumbEl = document.getElementById('breadcrumb-config');
|
||||
configBreadcrumbEl.textContent = truncateBreadcrumbSpecName(fullConfigName);
|
||||
configBreadcrumbEl.title = fullConfigName;
|
||||
document.getElementById('breadcrumb-config-link').href = '/configurator?uuid=' + configUUID;
|
||||
|
||||
if (configData.project_uuid) {
|
||||
@@ -114,14 +146,16 @@ function renderVersions(versions) {
|
||||
html += '<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Версия</th>';
|
||||
html += '<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Дата</th>';
|
||||
html += '<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Автор</th>';
|
||||
html += '<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Примечание</th>';
|
||||
html += '<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Артикул</th>';
|
||||
html += '<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Цена</th>';
|
||||
html += '<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Серверов</th>';
|
||||
html += '<th class="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase">Действия</th>';
|
||||
html += '</tr></thead><tbody class="divide-y">';
|
||||
|
||||
versions.forEach((v, idx) => {
|
||||
const date = new Date(v.created_at).toLocaleString('ru-RU');
|
||||
const author = v.created_by || '—';
|
||||
const note = v.change_note || '—';
|
||||
const snapshot = parseVersionSnapshot(v);
|
||||
const isCurrent = idx === 0;
|
||||
|
||||
html += '<tr class="hover:bg-gray-50' + (isCurrent ? ' bg-blue-50' : '') + '">';
|
||||
@@ -131,7 +165,9 @@ function renderVersions(versions) {
|
||||
html += '</td>';
|
||||
html += '<td class="px-4 py-3 text-sm text-gray-500">' + escapeHtml(date) + '</td>';
|
||||
html += '<td class="px-4 py-3 text-sm text-gray-500">' + escapeHtml(author) + '</td>';
|
||||
html += '<td class="px-4 py-3 text-sm text-gray-500">' + escapeHtml(note) + '</td>';
|
||||
html += '<td class="px-4 py-3 text-sm text-gray-500">' + escapeHtml(snapshot.article) + '</td>';
|
||||
html += '<td class="px-4 py-3 text-sm text-gray-500">' + formatMoney(snapshot.price) + '</td>';
|
||||
html += '<td class="px-4 py-3 text-sm text-gray-500">' + escapeHtml(String(snapshot.serverCount)) + '</td>';
|
||||
html += '<td class="px-4 py-3 text-sm text-right space-x-2">';
|
||||
|
||||
// Open in configurator (readonly view)
|
||||
|
||||
Reference in New Issue
Block a user