Fix machine count display and pharmacy edit functionality

🔧 Machine Management Fixes:
- Fix duplicate machine counting (was showing 10 instead of 5)
- Update dashboard stats to use Headscale nodes instead of FARMQ profiles
- Fix JavaScript counting to only count active view (List/Card)
- Add view change listeners to update counters correctly

🏥 Pharmacy Management Fixes:
- Add API endpoint for individual pharmacy data retrieval
- Fix pharmacy edit modal to load existing data as form values
- Add proper form validation and error handling
- Implement edit vs add mode detection

📊 Database Integration:
- Improve machine counting logic using Headscale Node table
- Fix online/offline status calculation with 5-minute threshold
- Add debug logging for machine data retrieval

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-11 09:41:55 +09:00
parent 5d89277e5c
commit 1f0afd4cae
4 changed files with 287 additions and 17 deletions

View File

@@ -205,7 +205,14 @@ document.addEventListener('DOMContentLoaded', function() {
function showAddModal() {
document.getElementById('pharmacyModalTitle').innerHTML =
'<i class="fas fa-plus"></i> 새 약국 등록';
// 폼 초기화
document.getElementById('pharmacyForm').reset();
// 새 등록 모드임을 표시
document.getElementById('pharmacyForm').dataset.pharmacyId = '';
document.getElementById('pharmacyForm').dataset.mode = 'add';
pharmacyModal.show();
}
@@ -213,8 +220,31 @@ function showEditModal(pharmacyId) {
document.getElementById('pharmacyModalTitle').innerHTML =
'<i class="fas fa-edit"></i> 약국 정보 수정';
// TODO: 기존 데이터를 로드하여 폼에 채우기
// fetch(`/api/pharmacy/${pharmacyId}`)
// 기존 데이터를 로드하여 폼에 채우기
fetch(`/api/pharmacy/${pharmacyId}`)
.then(response => response.json())
.then(data => {
if (data.pharmacy) {
const pharmacy = data.pharmacy;
// 폼 필드에 기존 값들을 채우기 (value로 설정하여 수정 가능하게)
document.getElementById('pharmacy_name').value = pharmacy.pharmacy_name || '';
document.getElementById('business_number').value = pharmacy.business_number || '';
document.getElementById('manager_name').value = pharmacy.manager_name || '';
document.getElementById('phone').value = pharmacy.phone || '';
document.getElementById('address').value = pharmacy.address || '';
document.getElementById('proxmox_host').value = pharmacy.proxmox_host || '';
document.getElementById('user_id').value = pharmacy.user_id || '';
// 수정 모드임을 표시하기 위해 pharmacy ID를 form에 저장
document.getElementById('pharmacyForm').dataset.pharmacyId = pharmacyId;
document.getElementById('pharmacyForm').dataset.mode = 'edit';
}
})
.catch(error => {
console.error('약국 정보 로드 실패:', error);
showToast('약국 정보를 불러오는데 실패했습니다.', 'error');
});
pharmacyModal.show();
}
@@ -222,15 +252,49 @@ function showEditModal(pharmacyId) {
document.getElementById('pharmacyForm').addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const data = Object.fromEntries(formData);
const form = e.target;
const mode = form.dataset.mode;
const pharmacyId = form.dataset.pharmacyId;
// TODO: API를 통한 약국 정보 저장
showToast('약국 정보가 저장되었습니다.', 'success');
pharmacyModal.hide();
// 폼 데이터 수집
const data = {
pharmacy_name: document.getElementById('pharmacy_name').value,
business_number: document.getElementById('business_number').value,
manager_name: document.getElementById('manager_name').value,
phone: document.getElementById('phone').value,
address: document.getElementById('address').value,
proxmox_host: document.getElementById('proxmox_host').value,
user_id: document.getElementById('user_id').value
};
// 페이지 새로고침 (임시)
setTimeout(() => location.reload(), 1000);
if (mode === 'edit' && pharmacyId) {
// 수정 모드: PUT 요청
fetch(`/api/pharmacy/${pharmacyId}/update`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => {
if (result.error) {
showToast(result.error, 'error');
} else {
showToast('약국 정보가 수정되었습니다.', 'success');
pharmacyModal.hide();
setTimeout(() => location.reload(), 1000);
}
})
.catch(error => {
console.error('약국 정보 수정 실패:', error);
showToast('약국 정보 수정에 실패했습니다.', 'error');
});
} else {
// 새 등록 모드: POST 요청 (향후 구현)
showToast('새 약국 등록 기능은 아직 구현 중입니다.', 'warning');
pharmacyModal.hide();
}
});
// 테이블 정렬 및 검색 기능 추가 (향후)