newvera
parent
587887c759
commit
8fac444974
|
|
@ -14,6 +14,7 @@
|
|||
.form-container { margin-bottom: 20px; }
|
||||
.jstree-node { position: relative; }
|
||||
.folder-actions { display: inline; margin-left: 10px; }
|
||||
#search-input, #sort-select { margin-bottom: 10px; width: 200px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -31,12 +32,23 @@
|
|||
<input type="text" id="installTime" placeholder="Время (опционально)">
|
||||
<button onclick="addInstall()">Добавить</button>
|
||||
</div>
|
||||
<input type="text" id="search-input" placeholder="Поиск по ID или имени" onkeyup="filterInstalls()">
|
||||
<select id="sort-select" onchange="sortInstalls()">
|
||||
<option value="">Без сортировки</option>
|
||||
<option value="rust_id_asc">Rust ID (А-Я)</option>
|
||||
<option value="rust_id_desc">Rust ID (Я-А)</option>
|
||||
<option value="computer_name_asc">Имя (А-Я)</option>
|
||||
<option value="computer_name_desc">Имя (Я-А)</option>
|
||||
<option value="install_time_asc">Время (ранее-позже)</option>
|
||||
<option value="install_time_desc">Время (позже-ранее)</option>
|
||||
</select>
|
||||
<div id="installs-list"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_URL = "/api";
|
||||
let selectedFolderId = null;
|
||||
let allInstalls = []; // Храним все записи для поиска и сортировки
|
||||
|
||||
$(document).ready(function () {
|
||||
// Инициализация дерева папок
|
||||
|
|
@ -92,19 +104,57 @@
|
|||
|
||||
function loadInstalls(folderId) {
|
||||
$.getJSON(`${API_URL}/installs`, function (data) {
|
||||
const filtered = folderId ? data.filter(i => i.folder_id == folderId) : data;
|
||||
$('#installs-list').html(filtered.map(item => `
|
||||
<div class="install-item" data-id="${item.id}" draggable="true">
|
||||
<a href="rustdesk://${item.rust_id}" onclick="openRustDesk('${item.rust_id}'); return false;">${item.rust_id}</a>
|
||||
- ${item.computer_name} (${item.install_time})
|
||||
<button onclick="editInstall(${item.id}, '${item.rust_id}', '${item.computer_name}', '${item.install_time}')">Редактировать</button>
|
||||
<button onclick="deleteInstall(${item.id})">Удалить</button>
|
||||
</div>
|
||||
`).join(''));
|
||||
allInstalls = data; // Сохраняем все записи
|
||||
let filtered = folderId ? data.filter(i => i.folder_id == folderId) : data.filter(i => i.folder_id === null);
|
||||
displayInstalls(filtered);
|
||||
});
|
||||
selectedFolderId = folderId; // Обновляем текущую папку
|
||||
}
|
||||
|
||||
function displayInstalls(installs) {
|
||||
$('#installs-list').html(installs.map(item => `
|
||||
<div class="install-item" data-id="${item.id}" draggable="true">
|
||||
<a href="rustdesk://${item.rust_id}" onclick="openRustDesk('${item.rust_id}'); return false;">${item.rust_id}</a>
|
||||
- ${item.computer_name} (${item.install_time})
|
||||
<button onclick="editInstall(${item.id}, '${item.rust_id}', '${item.computer_name}', '${item.install_time}')">Редактировать</button>
|
||||
<button onclick="deleteInstall(${item.id})">Удалить</button>
|
||||
</div>
|
||||
`).join(''));
|
||||
}
|
||||
|
||||
function filterInstalls() {
|
||||
const query = $('#search-input').val().toLowerCase();
|
||||
let filtered = selectedFolderId
|
||||
? allInstalls.filter(i => i.folder_id == selectedFolderId)
|
||||
: allInstalls.filter(i => i.folder_id === null);
|
||||
filtered = filtered.filter(i =>
|
||||
i.rust_id.toLowerCase().includes(query) ||
|
||||
i.computer_name.toLowerCase().includes(query)
|
||||
);
|
||||
sortInstalls(filtered);
|
||||
}
|
||||
|
||||
function sortInstalls(filteredInstalls = null) {
|
||||
let installs = filteredInstalls || (selectedFolderId
|
||||
? allInstalls.filter(i => i.folder_id == selectedFolderId)
|
||||
: allInstalls.filter(i => i.folder_id === null));
|
||||
const sortBy = $('#sort-select').val();
|
||||
|
||||
if (sortBy) {
|
||||
const [field, direction] = sortBy.split('_');
|
||||
installs.sort((a, b) => {
|
||||
let valA = a[field], valB = b[field];
|
||||
if (field === 'install_time') {
|
||||
valA = new Date(valA);
|
||||
valB = new Date(valB);
|
||||
}
|
||||
if (direction === 'asc') return valA > valB ? 1 : -1;
|
||||
return valA < valB ? 1 : -1;
|
||||
});
|
||||
}
|
||||
displayInstalls(installs);
|
||||
}
|
||||
|
||||
function addFolder() {
|
||||
const name = prompt("Введите имя папки:");
|
||||
if (name) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue