main
Satur@it-depot.ru 2025-03-04 17:50:37 +03:00
parent 01b1515172
commit 9c3b36cb6f
1 changed files with 23 additions and 9 deletions

View File

@ -14,6 +14,7 @@
.form-container { margin-bottom: 20px; } .form-container { margin-bottom: 20px; }
.jstree-node { position: relative; } .jstree-node { position: relative; }
.folder-actions { display: inline; margin-left: 10px; } .folder-actions { display: inline; margin-left: 10px; }
#root-btn { margin-top: 10px; }
</style> </style>
</head> </head>
<body> <body>
@ -21,6 +22,7 @@
<h2>Папки</h2> <h2>Папки</h2>
<div id="folder-tree"></div> <div id="folder-tree"></div>
<button onclick="addFolder()">Добавить папку</button> <button onclick="addFolder()">Добавить папку</button>
<button id="root-btn" onclick="showRoot()">Показать все записи</button>
</div> </div>
<div id="installs-container"> <div id="installs-container">
<h1>Органайзер RustDesk</h1> <h1>Органайзер RustDesk</h1>
@ -72,13 +74,13 @@
}).on('drop', function (e) { }).on('drop', function (e) {
e.preventDefault(); e.preventDefault();
const installId = e.originalEvent.dataTransfer.getData('text'); const installId = e.originalEvent.dataTransfer.getData('text');
const folderId = $(e.target).closest('.jstree-node').attr('id'); const targetFolderId = $(e.target).closest('.jstree-node').attr('id');
if (installId && folderId) { if (installId && targetFolderId && targetFolderId !== 'undefined') {
updateInstallFolder(installId, folderId); moveInstallToFolder(installId, targetFolderId);
} }
}); });
// Загрузка записей без выбранной папки // Загрузка всех записей при старте
loadInstalls(null); loadInstalls(null);
}); });
@ -94,6 +96,7 @@
</div> </div>
`).join('')); `).join(''));
}); });
selectedFolderId = folderId; // Обновляем текущую папку
} }
function addFolder() { function addFolder() {
@ -132,11 +135,11 @@
url: `${API_URL}/folders/${folderId}`, url: `${API_URL}/folders/${folderId}`,
type: 'DELETE', type: 'DELETE',
success: function () { success: function () {
// Перемещаем записи в корень (folder_id = null) // Перемещаем записи в корень
$.getJSON(`${API_URL}/installs`, function (data) { $.getJSON(`${API_URL}/installs`, function (data) {
const folderInstalls = data.filter(i => i.folder_id == folderId); const folderInstalls = data.filter(i => i.folder_id == folderId);
folderInstalls.forEach(item => { folderInstalls.forEach(item => {
updateInstallFolder(item.id, null); moveInstallToFolder(item.id, null);
}); });
}); });
$('#folder-tree').jstree(true).refresh(); $('#folder-tree').jstree(true).refresh();
@ -190,14 +193,19 @@
} }
} }
function updateInstallFolder(installId, folderId) { function moveInstallToFolder(installId, folderId) {
$.ajax({ $.ajax({
url: `${API_URL}/install/${installId}`, url: `${API_URL}/install/${installId}`,
type: 'PUT', type: 'PUT',
contentType: 'application/json', contentType: 'application/json',
data: JSON.stringify({ folder_id: folderId === 'undefined' ? null : folderId }), data: JSON.stringify({ folder_id: folderId }),
success: function () { success: function () {
loadInstalls(selectedFolderId); // Обновляем список после переноса // Если текущая папка выбрана, обновляем её, иначе показываем целевую
if (selectedFolderId === folderId) {
loadInstalls(selectedFolderId);
} else {
loadInstalls(selectedFolderId); // Остаемся в текущей папке
}
}, },
error: function (xhr, status, error) { error: function (xhr, status, error) {
console.error("Ошибка переноса:", status, error); console.error("Ошибка переноса:", status, error);
@ -210,6 +218,12 @@
window.location.href = `rustdesk://${rustId}`; window.location.href = `rustdesk://${rustId}`;
} }
} }
function showRoot() {
selectedFolderId = null;
loadInstalls(null);
$('#folder-tree').jstree('deselect_all'); // Снимаем выделение с папок
}
</script> </script>
</body> </body>
</html> </html>