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

@@ -68,14 +68,16 @@ def get_dashboard_stats() -> Dict[str, Any]:
PharmacyInfo.status == 'active'
).count()
# 머신 상태
total_machines = farmq_session.query(MachineProfile).filter(
MachineProfile.status == 'active'
).count()
# 머신 상태 - Headscale 노드 기준으로 계산
from models.headscale_models import Node
online_machines = farmq_session.query(MachineProfile).filter(
MachineProfile.status == 'active',
MachineProfile.tailscale_status == 'online'
# 전체 머신 수 (Headscale 노드 기준)
total_machines = headscale_session.query(Node).count()
# 온라인 머신 수 (last_seen이 최근 5분 이내)
cutoff_time = datetime.now() - timedelta(minutes=5)
online_machines = headscale_session.query(Node).filter(
Node.last_seen > cutoff_time
).count()
offline_machines = total_machines - online_machines
@@ -226,6 +228,8 @@ def get_all_machines_with_details() -> List[Dict[str, Any]]:
Node.deleted_at.is_(None)
).all()
print(f"🔍 Found {len(nodes)} nodes in Headscale database")
result = []
for node in nodes:
# 기본 머신 정보