new ver
parent
9c3b36cb6f
commit
64931747cf
21
app.py
21
app.py
|
|
@ -41,8 +41,8 @@ class FolderUpdate(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
class InstallData(BaseModel):
|
class InstallData(BaseModel):
|
||||||
rust_id: str
|
rust_id: str | None = None
|
||||||
computer_name: str
|
computer_name: str | None = None
|
||||||
install_time: str | None = None
|
install_time: str | None = None
|
||||||
folder_id: int | None = None
|
folder_id: int | None = None
|
||||||
|
|
||||||
|
|
@ -107,15 +107,24 @@ def add_install(data: InstallData):
|
||||||
|
|
||||||
@app.put("/api/install/{install_id}")
|
@app.put("/api/install/{install_id}")
|
||||||
def update_install(install_id: int, data: InstallData):
|
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("""
|
cursor.execute("""
|
||||||
UPDATE installs
|
UPDATE installs
|
||||||
SET rust_id = ?, computer_name = ?, install_time = ?, folder_id = ?
|
SET rust_id = ?, computer_name = ?, install_time = ?, folder_id = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
""", (data.rust_id, data.computer_name, data.install_time or datetime.datetime.now().isoformat(),
|
""", (new_rust_id, new_computer_name, new_install_time, new_folder_id, install_id))
|
||||||
data.folder_id, install_id))
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
if cursor.rowcount == 0:
|
|
||||||
raise HTTPException(status_code=404, detail="Запись не найдена")
|
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
|
|
||||||
@app.delete("/api/install/{install_id}")
|
@app.delete("/api/install/{install_id}")
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
.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>
|
||||||
|
|
@ -22,7 +21,6 @@
|
||||||
<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>
|
||||||
|
|
@ -46,13 +44,19 @@
|
||||||
'core': {
|
'core': {
|
||||||
'data': function (node, cb) {
|
'data': function (node, cb) {
|
||||||
$.getJSON(`${API_URL}/folders`, function (data) {
|
$.getJSON(`${API_URL}/folders`, function (data) {
|
||||||
const treeData = data.map(folder => ({
|
const treeData = [
|
||||||
|
{
|
||||||
|
id: "root",
|
||||||
|
text: "Корень",
|
||||||
|
parent: "#"
|
||||||
|
}
|
||||||
|
].concat(data.map(folder => ({
|
||||||
id: folder.id,
|
id: folder.id,
|
||||||
text: `${folder.name} <span class="folder-actions">` +
|
text: `${folder.name} <span class="folder-actions">` +
|
||||||
`<button onclick="editFolder(${folder.id}, '${folder.name}')">✏️</button>` +
|
`<button onclick="editFolder(${folder.id}, '${folder.name}')">✏️</button>` +
|
||||||
`<button onclick="deleteFolder(${folder.id})">🗑️</button></span>`,
|
`<button onclick="deleteFolder(${folder.id})">🗑️</button></span>`,
|
||||||
parent: folder.parent_id ? folder.parent_id : '#'
|
parent: folder.parent_id ? folder.parent_id : "root"
|
||||||
}));
|
})));
|
||||||
cb(treeData);
|
cb(treeData);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -60,7 +64,7 @@
|
||||||
},
|
},
|
||||||
'plugins': ['dnd', 'html_data']
|
'plugins': ['dnd', 'html_data']
|
||||||
}).on('select_node.jstree', function (e, data) {
|
}).on('select_node.jstree', function (e, data) {
|
||||||
selectedFolderId = data.node.id;
|
selectedFolderId = data.node.id === "root" ? null : data.node.id;
|
||||||
loadInstalls(selectedFolderId);
|
loadInstalls(selectedFolderId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -74,14 +78,16 @@
|
||||||
}).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 targetFolderId = $(e.target).closest('.jstree-node').attr('id');
|
let targetFolderId = $(e.target).closest('.jstree-node').attr('id');
|
||||||
if (installId && targetFolderId && targetFolderId !== 'undefined') {
|
if (installId && targetFolderId) {
|
||||||
|
targetFolderId = targetFolderId === "root" ? null : targetFolderId;
|
||||||
moveInstallToFolder(installId, targetFolderId);
|
moveInstallToFolder(installId, targetFolderId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Загрузка всех записей при старте
|
// Загрузка всех записей при старте
|
||||||
loadInstalls(null);
|
loadInstalls(null);
|
||||||
|
$('#folder-tree').jstree('select_node', 'root'); // Выбираем корень по умолчанию
|
||||||
});
|
});
|
||||||
|
|
||||||
function loadInstalls(folderId) {
|
function loadInstalls(folderId) {
|
||||||
|
|
@ -135,7 +141,6 @@
|
||||||
url: `${API_URL}/folders/${folderId}`,
|
url: `${API_URL}/folders/${folderId}`,
|
||||||
type: 'DELETE',
|
type: 'DELETE',
|
||||||
success: function () {
|
success: function () {
|
||||||
// Перемещаем записи в корень
|
|
||||||
$.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 => {
|
||||||
|
|
@ -200,12 +205,7 @@
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
data: JSON.stringify({ folder_id: 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);
|
||||||
|
|
@ -218,12 +218,6 @@
|
||||||
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>
|
||||||
Loading…
Reference in New Issue