From 6a904b76f017697b327e4f8419e6af3f3f829813 Mon Sep 17 00:00:00 2001 From: "Satur@it-depot.ru" Date: Thu, 6 Mar 2025 14:25:10 +0300 Subject: [PATCH] fix drag --- app.py | 1 + templates/index.html | 63 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index 76ceff0..617269c 100644 --- a/app.py +++ b/app.py @@ -168,6 +168,7 @@ def update_install(install_id: int, data: InstallData): new_computer_name = data.computer_name if data.computer_name is not None else current[1] new_install_time = data.install_time if data.install_time is not None else current[2] new_folder_id = data.folder_id if data.folder_id is not None else current[3] + # Используем текущее значение protocol, если data.protocol не передано (None) new_protocol = data.protocol if data.protocol is not None else current[4] new_note = data.note if data.note is not None else current[5] diff --git a/templates/index.html b/templates/index.html index c94dd5a..f9af0cd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -787,24 +787,64 @@ } function moveInstallToFolder(installId, folderId) { + const install = allInstalls.find(i => i.id === installId); + if (install) { + $.ajax({ + url: `${API_URL}/install/${installId}`, + type: 'PUT', + contentType: 'application/json', + data: JSON.stringify({ + folder_id: folderId, + protocol: install.protocol + }), + success: function () { + loadInstalls(selectedFolderId); + }, + error: function (xhr, status, error) { + console.error("Ошибка переноса:", status, error); + } + }); + } + } + + function exportCSV() { + const folderId = $('#folder-select').val() || ''; + window.location.href = `${API_URL}/export/csv?folder_id=${folderId}`; + } + + function importCSV(file) { + if (!file) return; + + const folderId = $('#folder-select').val() || ''; + const formData = new FormData(); + formData.append('file', file); + if (folderId) { + formData.append('folder_id', folderId); + } + $.ajax({ - url: `${API_URL}/install/${installId}`, - type: 'PUT', - contentType: 'application/json', - data: JSON.stringify({ - folder_id: folderId, - // Добавляем текущее значение protocol - protocol: allInstalls.find(i => i.id === installId)?.protocol || 'rustdesk' - }), - success: function () { + url: `${API_URL}/import/csv`, + type: 'POST', + data: formData, + processData: false, + contentType: false, + success: function (response) { + alert(response.message); loadInstalls(selectedFolderId); }, error: function (xhr, status, error) { - console.error("Ошибка переноса:", status, error); + alert(`Ошибка импорта: ${xhr.responseJSON.detail || error}`); } }); } + function openNoteModal(installId, currentNote) { + selectedInstallId = installId; + $('#note-textarea').val(currentNote); + $('#note-modal').show(); + $('#modal-overlay').show(); + } + function saveNote() { const note = $('#note-textarea').val() || ''; const install = allInstalls.find(i => i.id === selectedInstallId); @@ -815,7 +855,6 @@ contentType: 'application/json', data: JSON.stringify({ note: note, - // Добавляем текущее значение protocol protocol: install.protocol }), success: function () { @@ -888,7 +927,7 @@ function formatItalic() { const textarea = $('#note-textarea'); const start = textarea[0].selectionStart; - end: textarea[0].selectionEnd; + const end = textarea[0].selectionEnd; const text = textarea.val(); const selected = text.substring(start, end); const newText = `*${selected}*`;