Satur@it-depot.ru 2025-03-05 12:45:23 +03:00
parent 9f39071732
commit c76f0a3020
1 changed files with 46 additions and 24 deletions

View File

@ -11,10 +11,11 @@
body { display: flex; font-family: Arial, sans-serif; margin: 0; }
#tree-container { width: 20%; padding: 10px; border-right: 1px solid #ccc; }
#installs-container { width: 50%; padding: 10px; position: relative; }
.install-item { padding: 5px; margin: 2px; border: 1px solid #ddd; cursor: move; }
.install-item { padding: 5px; margin: 2px; border: 1px solid #ddd; cursor: move; position: relative; }
.form-container { margin-bottom: 20px; }
.jstree-node { position: relative; }
.folder-actions { display: inline; margin-left: 10px; }
.folder-actions { display: none; margin-left: 10px; }
.jstree-node:hover .folder-actions { display: inline; }
#search-container { position: absolute; top: 10px; right: 10px; text-align: right; }
#search-input { width: 200px; }
#installs-list { margin-top: 20px; }
@ -24,6 +25,11 @@
.sort-arrow { font-size: 12px; margin-left: 5px; }
.protocol-icon { margin-right: 5px; height: 16px; width: 16px; vertical-align: middle; }
.connection-link { color: blue; text-decoration: underline; cursor: pointer; }
.edit-button { display: none; position: absolute; right: 5px; top: 50%; transform: translateY(-50%); background: #007bff; color: white; border: none; padding: 2px 5px; border-radius: 3px; cursor: pointer; }
.edit-button:hover { background: #0056b3; }
.install-item:hover .edit-button { display: inline-block; }
.action-buttons { display: none; }
.install-item:hover .action-buttons { display: inline; }
#import-form { margin-top: 10px; }
#import-file { display: none; }
#import-label { cursor: pointer; background: #007bff; color: white; padding: 5px 10px; border-radius: 5px; }
@ -222,14 +228,25 @@
function displayInstalls(installs) {
$('#installs-list').html(installs.map(item => `
<div class="install-item" data-id="${item.id}" draggable="true" style="display: flex; justify-content: space-between;">
<div style="flex: 1; text-align: center;"><span class="protocol-icon">${protocolIcons[item.protocol]}</span><a href="${protocolLinks[item.protocol]}${item.rust_id}" class="connection-link" onclick="openRemote('${item.rust_id}', '${item.protocol}'); return false;">${item.rust_id}</a></div>
<div style="flex: 1; text-align: center;">${item.computer_name}</div>
<div style="flex: 1; text-align: center;">${item.install_time}</div>
<div style="flex: 1; text-align: center;">
<button onclick="editInstall(${item.id}, '${item.rust_id}', '${item.computer_name}', '${item.install_time}', '${item.protocol}', '${item.note}')">Редактировать</button>
<button onclick="deleteInstall(${item.id})">Удалить</button>
<button onclick="openNoteModal(${item.id}, '${item.note}')">Заметка</button>
<div class="install-item" data-id="${item.id}" draggable="true" style="display: flex; justify-content: space-between; position: relative;">
<div style="flex: 1; text-align: center; position: relative;">
<span class="protocol-icon">${protocolIcons[item.protocol]}</span>
<a href="${protocolLinks[item.protocol]}${item.rust_id}" class="connection-link" onclick="openRemote('${item.rust_id}', '${item.protocol}'); return false;">${item.rust_id}</a>
<button class="edit-button" onclick="editField(${item.id}, 'rust_id', '${item.rust_id}')">✏️</button>
</div>
<div style="flex: 1; text-align: center; position: relative;">
${item.computer_name}
<button class="edit-button" onclick="editField(${item.id}, 'computer_name', '${item.computer_name}')">✏️</button>
</div>
<div style="flex: 1; text-align: center; position: relative;">
${item.install_time}
<button class="edit-button" onclick="editField(${item.id}, 'install_time', '${item.install_time}')">✏️</button>
</div>
<div style="flex: 1; text-align: center; position: relative;">
<span class="action-buttons">
<button onclick="deleteInstall(${item.id})">Удалить</button>
<button onclick="openNoteModal(${item.id}, '${item.note}')">Заметка</button>
</span>
</div>
</div>
`).join(''));
@ -367,24 +384,29 @@
});
}
function editInstall(id, rustId, computerName, installTime, protocol, note) {
const newRustId = prompt("ID подключения:", rustId);
const newComputerName = prompt("Имя компьютера:", computerName);
let newInstallTime = prompt("Время установки (опционально, формат: ГГГГ-ММ-ДД ЧЧ:ММ:СС):", installTime || '');
const newProtocol = prompt("Протокол (rustdesk, anydesk, ammyy, teamviewer, vnc, rdp):", protocol);
const newNote = prompt("Заметка (Markdown поддерживается):", note || '');
if (newInstallTime && !/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/.test(newInstallTime)) {
alert("Неверный формат времени. Используйте ГГГГ-ММ-ДД ЧЧ:ММ:СС (например, 2025-03-05 14:30:00)");
return;
function editField(installId, field, currentValue) {
let newValue;
if (field === 'install_time') {
newValue = prompt(`Новое ${field === 'rust_id' ? 'ID подключения' : field === 'computer_name' ? 'Имя компьютера' : 'Время установки'} (опционально, формат для времени: ГГГГ-ММ-ДД ЧЧ:ММ:СС):`, currentValue || '');
if (newValue && field === 'install_time' && !/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/.test(newValue)) {
alert("Неверный формат времени. Используйте ГГГГ-ММ-ДД ЧЧ:ММ:СС (например, 2025-03-05 14:30:00)");
return;
}
} else {
newValue = prompt(`Новое ${field === 'rust_id' ? 'ID подключения' : field === 'computer_name' ? 'Имя компьютера' : 'Время установки'}:`, currentValue || '');
}
if (newRustId && newComputerName) {
if (newValue !== null && newValue !== currentValue) { // Проверяем, что значение изменилось
let data = {};
data[field] = newValue;
if (field === 'install_time') {
data['folder_id'] = selectedFolderId; // Добавляем folder_id для обновления
}
$.ajax({
url: `${API_URL}/install/${id}`,
url: `${API_URL}/install/${installId}`,
type: 'PUT',
contentType: 'application/json',
data: JSON.stringify({ rust_id: newRustId, computer_name: newComputerName, install_time: newInstallTime, folder_id: selectedFolderId, protocol: newProtocol, note: newNote }),
data: JSON.stringify(data),
success: function () {
loadInstalls(selectedFolderId);
},
@ -392,7 +414,7 @@
if (xhr.status === 400) {
alert(xhr.responseJSON.detail);
} else {
console.error("Ошибка редактирования:", status, error);
console.error(`Ошибка редактирования ${field}:`, status, error);
}
}
});