From 20666e894fdb4a813b85d2e42392964978124326 Mon Sep 17 00:00:00 2001 From: ayzen Date: Wed, 19 Nov 2025 16:22:21 +0300 Subject: [PATCH] added settings load window --- vna_system/web_ui/static/js/modules/charts.js | 26 ++++++- vna_system/web_ui/static/js/modules/utils.js | 74 +++++++++++++++++++ 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/vna_system/web_ui/static/js/modules/charts.js b/vna_system/web_ui/static/js/modules/charts.js index b5a849e..c060aae 100644 --- a/vna_system/web_ui/static/js/modules/charts.js +++ b/vna_system/web_ui/static/js/modules/charts.js @@ -3,7 +3,7 @@ * Handles Plotly.js chart creation, updates, and management */ -import { formatProcessorName, safeClone, downloadJSON } from './utils.js'; +import { formatProcessorName, safeClone, downloadJSON, showConfirmDialog } from './utils.js'; import { renderIcons } from './icons.js'; import { ChartSettingsManager } from './charts/chart-settings.js'; import { BScanClickHandler } from './charts/bscan-click-handler.js'; @@ -705,6 +705,25 @@ export class ChartManager { return; } + // Show dialog to choose whether to update settings or not + const choice = await showConfirmDialog({ + title: 'Загрузка истории', + message: 'Обновить параметры процессора из файла или сохранить текущие настройки?', + buttons: [ + { value: 'cancel', text: 'Отмена', class: 'btn--secondary' }, + { value: 'data_only', text: 'Только данные', class: 'btn--primary' }, + { value: 'with_settings', text: 'Данные и настройки', class: 'btn--primary' } + ] + }); + + // User cancelled + if (!choice || choice === 'cancel') { + return; + } + + // Determine whether to include config + const configToSend = (choice === 'with_settings' && processorConfig) ? processorConfig : null; + // Send load_history message via WebSocket const websocket = window.vnaDashboard?.websocket; if (websocket && websocket.ws && websocket.ws.readyState === WebSocket.OPEN) { @@ -712,13 +731,14 @@ export class ChartManager { type: 'load_history', processor_id: processorId, history_data: sweepHistory, - config: processorConfig + config: configToSend })); + const settingsMsg = configToSend ? ' (с обновлением настроек)' : ' (без изменения настроек)'; this.notifications?.show?.({ type: 'success', title: 'История загружена', - message: `Загружено ${sweepHistory.length} записей для ${formatProcessorName(processorId)}` + message: `Загружено ${sweepHistory.length} записей для ${formatProcessorName(processorId)}${settingsMsg}` }); } else { this.notifications?.show?.({ diff --git a/vna_system/web_ui/static/js/modules/utils.js b/vna_system/web_ui/static/js/modules/utils.js index ee39f87..b1bd8db 100644 --- a/vna_system/web_ui/static/js/modules/utils.js +++ b/vna_system/web_ui/static/js/modules/utils.js @@ -311,3 +311,77 @@ export function formatBytes(bytes) { return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`; } + +/** + * Show a confirmation dialog with custom options + * @param {Object} options - Dialog options + * @param {string} options.title - Dialog title + * @param {string} options.message - Dialog message + * @param {Array} options.buttons - Array of button configurations + * @returns {Promise} Resolves with the button value that was clicked + */ +export function showConfirmDialog({ title, message, buttons }) { + return new Promise((resolve) => { + // Create modal structure + const modal = document.createElement('div'); + modal.className = 'modal modal--active'; + + const buttonsHtml = buttons.map(btn => + `` + ).join(''); + + modal.innerHTML = ` + + + `; + + document.body.appendChild(modal); + + // Handle button clicks + const handleClick = (e) => { + const button = e.target.closest('[data-value]'); + if (button) { + const value = button.dataset.value; + cleanup(); + resolve(value); + } + }; + + // Handle backdrop click + const handleBackdrop = (e) => { + if (e.target.classList.contains('modal__backdrop')) { + cleanup(); + resolve(null); + } + }; + + // Handle escape key + const handleEscape = (e) => { + if (e.key === 'Escape') { + cleanup(); + resolve(null); + } + }; + + const cleanup = () => { + modal.removeEventListener('click', handleClick); + modal.removeEventListener('click', handleBackdrop); + document.removeEventListener('keydown', handleEscape); + modal.remove(); + }; + + modal.addEventListener('click', handleClick); + modal.addEventListener('click', handleBackdrop); + document.addEventListener('keydown', handleEscape); + }); +}