Merge branch 'master' of 10.55.228.171:/home/mipt-user/projects/vna_system
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
* Handles Plotly.js chart creation, updates, and management
|
* 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 { renderIcons } from './icons.js';
|
||||||
import { ChartSettingsManager } from './charts/chart-settings.js';
|
import { ChartSettingsManager } from './charts/chart-settings.js';
|
||||||
import { BScanClickHandler } from './charts/bscan-click-handler.js';
|
import { BScanClickHandler } from './charts/bscan-click-handler.js';
|
||||||
@ -705,6 +705,25 @@ export class ChartManager {
|
|||||||
return;
|
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
|
// Send load_history message via WebSocket
|
||||||
const websocket = window.vnaDashboard?.websocket;
|
const websocket = window.vnaDashboard?.websocket;
|
||||||
if (websocket && websocket.ws && websocket.ws.readyState === WebSocket.OPEN) {
|
if (websocket && websocket.ws && websocket.ws.readyState === WebSocket.OPEN) {
|
||||||
@ -712,13 +731,14 @@ export class ChartManager {
|
|||||||
type: 'load_history',
|
type: 'load_history',
|
||||||
processor_id: processorId,
|
processor_id: processorId,
|
||||||
history_data: sweepHistory,
|
history_data: sweepHistory,
|
||||||
config: processorConfig
|
config: configToSend
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const settingsMsg = configToSend ? ' (с обновлением настроек)' : ' (без изменения настроек)';
|
||||||
this.notifications?.show?.({
|
this.notifications?.show?.({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
title: 'История загружена',
|
title: 'История загружена',
|
||||||
message: `Загружено ${sweepHistory.length} записей для ${formatProcessorName(processorId)}`
|
message: `Загружено ${sweepHistory.length} записей для ${formatProcessorName(processorId)}${settingsMsg}`
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.notifications?.show?.({
|
this.notifications?.show?.({
|
||||||
|
|||||||
@ -311,3 +311,77 @@ export function formatBytes(bytes) {
|
|||||||
|
|
||||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
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<Object>} options.buttons - Array of button configurations
|
||||||
|
* @returns {Promise<string>} 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 =>
|
||||||
|
`<button class="btn ${btn.class || 'btn--secondary'}" data-value="${btn.value}">${btn.text}</button>`
|
||||||
|
).join('');
|
||||||
|
|
||||||
|
modal.innerHTML = `
|
||||||
|
<div class="modal__backdrop" style="background-color: rgba(0, 0, 0, 0.85);"></div>
|
||||||
|
<div class="modal__content" style="background-color: #1e293b;">
|
||||||
|
<div class="modal__header">
|
||||||
|
<h3 class="modal__title">${escapeHtml(title)}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="modal__body" style="padding: var(--space-6);">
|
||||||
|
<p style="margin: 0; color: var(--color-text-secondary);">${escapeHtml(message)}</p>
|
||||||
|
</div>
|
||||||
|
<div style="padding: var(--space-6); padding-top: 0; display: flex; gap: var(--space-3); justify-content: flex-end;">
|
||||||
|
${buttonsHtml}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user