This commit is contained in:
backuppc
2025-07-08 13:29:40 +09:00
parent 8efe357430
commit 0d2da98470
4 changed files with 113 additions and 47 deletions

View File

@@ -63,34 +63,37 @@
<h3 id="modalTitle" class="text-lg font-semibold text-gray-800">서버 추가</h3>
</div>
<form id="serverForm" class="p-6">
<div class="mb-4">
<label for="serverUser" class="block text-sm font-medium text-gray-700 mb-2">사용자</label>
<input type="text" id="serverUser" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" required>
</div>
<div class="mb-4">
<label for="serverIp" class="block text-sm font-medium text-gray-700 mb-2">IP 주소</label>
<input type="text" id="serverIp" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" required>
</div>
<div class="mb-4">
<label for="serverCategory" class="block text-sm font-medium text-gray-700 mb-2">카테고리</label>
<input type="text" id="serverCategory" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label for="serverIp" class="block text-sm font-medium text-gray-700 mb-2">IP 주소</label>
<input type="text" id="serverIp" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" required>
</div>
<div>
<label for="serverPassword" class="block text-sm font-medium text-gray-700 mb-2">비밀번호</label>
<input type="password" id="serverPassword" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
</div>
</div>
<div class="mb-4">
<label for="serverTitle" class="block text-sm font-medium text-gray-700 mb-2">제목</label>
<input type="text" id="serverTitle" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div >
<label for="serverCategory" class="block text-sm font-medium text-gray-700 mb-2">카테고리</label>
<input type="text" id="serverCategory" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
</div>
<div>
<label for="serverArgument" class="block text-sm font-medium text-gray-700 mb-2">VNC 인수</label>
<input type="text" id="serverArgument" placeholder="-port=5900" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
</div>
</div>
<div class="mb-4">
<label for="serverDescription" class="block text-sm font-medium text-gray-700 mb-2">설명</label>
<textarea id="serverDescription" rows="2" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"></textarea>
</div>
<div class="mb-4">
<label for="serverPassword" class="block text-sm font-medium text-gray-700 mb-2">비밀번호</label>
<input type="password" id="serverPassword" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
</div>
<div class="mb-6">
<label for="serverArgument" class="block text-sm font-medium text-gray-700 mb-2">VNC 인수</label>
<input type="text" id="serverArgument" placeholder="-port=5900" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
</div>
<div class="flex justify-end space-x-3">
<button type="button" id="cancelBtn" class="px-4 py-2 text-gray-700 bg-gray-200 rounded-md hover:bg-gray-300 transition duration-200">취소</button>
<button type="submit" class="px-4 py-2 bg-primary text-white rounded-md hover:bg-blue-700 transition duration-200">저장</button>

View File

@@ -205,19 +205,29 @@ class VNCServerApp {
const modal = document.getElementById('serverModal');
const title = document.getElementById('modalTitle');
const form = document.getElementById('serverForm');
console.log('서버 정보2:', server); // 디버깅용
if (server) {
title.textContent = '서버 편집';
document.getElementById('serverUser').value = server.user;
document.getElementById('serverIp').value = server.ip;
document.getElementById('serverCategory').value = server.category || '';
document.getElementById('serverTitle').value = server.title || '';
document.getElementById('serverDescription').value = server.description || '';
document.getElementById('serverPassword').value = server.password || '';
document.getElementById('serverArgument').value = server.argument || '';
document.getElementById('serverIp').value = server.IP;
document.getElementById('serverCategory').value = server.Category || '';
document.getElementById('serverTitle').value = server.Title || '';
document.getElementById('serverDescription').value = server.Description || '';
document.getElementById('serverPassword').value = server.Password || '';
document.getElementById('serverArgument').value = server.Argument || '';
// 편집 모드 플래그 설정
modal.dataset.editMode = 'true';
modal.dataset.editUser = server.User;
modal.dataset.editIp = server.IP;
} else {
title.textContent = '서버 추가';
form.reset();
// 추가 모드 플래그 설정
modal.dataset.editMode = 'false';
delete modal.dataset.editUser;
delete modal.dataset.editIp;
}
modal.classList.remove('hidden');
@@ -346,10 +356,18 @@ class VNCServerApp {
}
async saveServer() {
const serverUser = document.getElementById('serverUser').value;
const serverIp = document.getElementById('serverIp').value;
const userName = document.getElementById('userName')?.value || '';
const modal = document.getElementById('serverModal');
const isEditMode = modal.dataset.editMode === 'true';
if (!userName) {
this.showError('사용자 이름이 설정되지 않았습니다. 먼저 설정에서 사용자 이름을 입력해주세요.');
return;
}
const serverData = {
user: serverUser,
user: userName,
ip: serverIp,
category: document.getElementById('serverCategory').value,
title: document.getElementById('serverTitle').value,
@@ -359,8 +377,19 @@ class VNCServerApp {
};
try {
const url = serverUser && serverIp ? `${this.apiBase}/update` : `${this.apiBase}/add`;
const method = serverUser && serverIp ? 'PUT' : 'POST';
let url, method;
if (isEditMode) {
// 편집 모드: 원본 사용자명과 IP를 쿼리 파라미터로 전달
const originalUser = modal.dataset.editUser;
const originalIp = modal.dataset.editIp;
url = `${this.apiBase}/update/${encodeURIComponent(originalUser)}/${encodeURIComponent(originalIp)}`;
method = 'PUT';
} else {
// 추가 모드
url = `${this.apiBase}/add`;
method = 'POST';
}
const response = await fetch(url, {
method: method,
@@ -382,13 +411,16 @@ class VNCServerApp {
}
async editServer(user, ip) {
console.log('편집 서버 호출:', { user, ip }); // 디버깅용
try {
const response = await fetch(`${this.apiBase}/get/${encodeURIComponent(user)}/${encodeURIComponent(ip)}`);
if (!response.ok) throw new Error('서버 정보를 불러올 수 없습니다.');
const server = await response.json();
console.log('서버 정보:', server); // 디버깅용
this.showServerModal(server);
} catch (error) {
console.error('편집 서버 오류:', error); // 디버깅용
this.showError('서버 정보를 불러오는 중 오류가 발생했습니다: ' + error.message);
}
}
@@ -533,6 +565,7 @@ class VNCServerApp {
// 서버 목록 렌더링
if (hasServers) {
categoryData.servers.forEach(server => {
console.log('서버 데이터:', server); // 디버깅용
const serverData = {
serverName: `${server.User || server.user}@${server.Title || server.title}`,
userName: server.User || server.user,
@@ -542,6 +575,7 @@ class VNCServerApp {
serverDescription: server.Description || server.description,
serverArgument: server.Argument || server.argument
};
console.log('렌더링할 서버 데이터:', serverData); // 디버깅용
html += this.renderTemplate('serverItemTemplate', serverData);
});
}