diff --git a/app.py b/app.py index 6c40d9b..8e5ad0c 100644 --- a/app.py +++ b/app.py @@ -41,8 +41,8 @@ class FolderUpdate(BaseModel): name: str class InstallData(BaseModel): - rust_id: str - computer_name: str + rust_id: str | None = None + computer_name: str | None = None install_time: str | None = None folder_id: int | None = None @@ -107,15 +107,24 @@ def add_install(data: InstallData): @app.put("/api/install/{install_id}") def update_install(install_id: int, data: InstallData): + # Получаем текущие данные записи + cursor.execute("SELECT rust_id, computer_name, install_time, folder_id FROM installs WHERE id = ?", (install_id,)) + current = cursor.fetchone() + if not current: + raise HTTPException(status_code=404, detail="Запись не найдена") + + # Обновляем только те поля, которые переданы + new_rust_id = data.rust_id if data.rust_id is not None else current[0] + 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] + cursor.execute(""" UPDATE installs SET rust_id = ?, computer_name = ?, install_time = ?, folder_id = ? WHERE id = ? - """, (data.rust_id, data.computer_name, data.install_time or datetime.datetime.now().isoformat(), - data.folder_id, install_id)) + """, (new_rust_id, new_computer_name, new_install_time, new_folder_id, install_id)) conn.commit() - if cursor.rowcount == 0: - raise HTTPException(status_code=404, detail="Запись не найдена") return {"status": "success"} @app.delete("/api/install/{install_id}") diff --git a/templates/index.html b/templates/index.html index 6acd5dc..7932ed9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,7 +14,6 @@ .form-container { margin-bottom: 20px; } .jstree-node { position: relative; } .folder-actions { display: inline; margin-left: 10px; } - #root-btn { margin-top: 10px; } @@ -22,7 +21,6 @@

Папки

-

Органайзер RustDesk

@@ -46,13 +44,19 @@ 'core': { 'data': function (node, cb) { $.getJSON(`${API_URL}/folders`, function (data) { - const treeData = data.map(folder => ({ + const treeData = [ + { + id: "root", + text: "Корень", + parent: "#" + } + ].concat(data.map(folder => ({ id: folder.id, text: `${folder.name} ` + `` + ``, - parent: folder.parent_id ? folder.parent_id : '#' - })); + parent: folder.parent_id ? folder.parent_id : "root" + }))); cb(treeData); }); }, @@ -60,7 +64,7 @@ }, 'plugins': ['dnd', 'html_data'] }).on('select_node.jstree', function (e, data) { - selectedFolderId = data.node.id; + selectedFolderId = data.node.id === "root" ? null : data.node.id; loadInstalls(selectedFolderId); }); @@ -74,14 +78,16 @@ }).on('drop', function (e) { e.preventDefault(); const installId = e.originalEvent.dataTransfer.getData('text'); - const targetFolderId = $(e.target).closest('.jstree-node').attr('id'); - if (installId && targetFolderId && targetFolderId !== 'undefined') { + let targetFolderId = $(e.target).closest('.jstree-node').attr('id'); + if (installId && targetFolderId) { + targetFolderId = targetFolderId === "root" ? null : targetFolderId; moveInstallToFolder(installId, targetFolderId); } }); // Загрузка всех записей при старте loadInstalls(null); + $('#folder-tree').jstree('select_node', 'root'); // Выбираем корень по умолчанию }); function loadInstalls(folderId) { @@ -135,7 +141,6 @@ url: `${API_URL}/folders/${folderId}`, type: 'DELETE', success: function () { - // Перемещаем записи в корень $.getJSON(`${API_URL}/installs`, function (data) { const folderInstalls = data.filter(i => i.folder_id == folderId); folderInstalls.forEach(item => { @@ -200,12 +205,7 @@ contentType: 'application/json', data: JSON.stringify({ folder_id: folderId }), success: function () { - // Если текущая папка выбрана, обновляем её, иначе показываем целевую - if (selectedFolderId === folderId) { - loadInstalls(selectedFolderId); - } else { - loadInstalls(selectedFolderId); // Остаемся в текущей папке - } + loadInstalls(selectedFolderId); // Обновляем текущую папку }, error: function (xhr, status, error) { console.error("Ошибка переноса:", status, error); @@ -218,12 +218,6 @@ window.location.href = `rustdesk://${rustId}`; } } - - function showRoot() { - selectedFolderId = null; - loadInstalls(null); - $('#folder-tree').jstree('deselect_all'); // Снимаем выделение с папок - } \ No newline at end of file