feat: 구매/안전 시스템 전면 개편 — tkpurchase 개편 + tksafety 신규 + 권한 보강
Phase 1: tkuser 협력업체 CRUD 이관 (읽기전용 → 전체 CRUD) Phase 2: tkpurchase 개편 — 일용공 신청/확정, 작업일정, 업무현황, 계정관리, 협력업체 포털 Phase 3: tksafety 신규 시스템 — 방문관리 + 안전교육 신고 Phase 4: SSO 인증 보강 (partner_company_id JWT, 만료일 체크), 권한 테이블 기반 접근 제어 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
7
tksafety/web/Dockerfile
Normal file
7
tksafety/web/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM nginx:alpine
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY index.html /usr/share/nginx/html/index.html
|
||||
COPY education.html /usr/share/nginx/html/education.html
|
||||
COPY static/ /usr/share/nginx/html/static/
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
194
tksafety/web/education.html
Normal file
194
tksafety/web/education.html
Normal file
@@ -0,0 +1,194 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>안전교육 - TK 안전관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tksafety.css?v=20260312">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
<header class="bg-orange-700 text-white sticky top-0 z-50">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div class="flex justify-between items-center h-14">
|
||||
<div class="flex items-center gap-3">
|
||||
<i class="fas fa-shield-alt text-xl text-orange-200"></i>
|
||||
<h1 class="text-lg font-semibold">TK 안전관리</h1>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<div id="headerUserName" class="text-sm font-medium hidden sm:block">-</div>
|
||||
<div id="headerUserAvatar" class="w-8 h-8 bg-orange-600 rounded-full flex items-center justify-center text-sm font-semibold">-</div>
|
||||
<button onclick="doLogout()" class="text-orange-200 hover:text-white" title="로그아웃"><i class="fas fa-sign-out-alt"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4 fade-in">
|
||||
<div class="flex gap-6">
|
||||
<!-- Sidebar Nav -->
|
||||
<nav id="sideNav" class="hidden lg:flex flex-col gap-1 w-48 flex-shrink-0 pt-2"></nav>
|
||||
|
||||
<!-- Main -->
|
||||
<div class="flex-1 min-w-0">
|
||||
<!-- 필터 & 추가 -->
|
||||
<div class="bg-white rounded-xl shadow-sm p-5 mb-5">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h2 class="text-base font-semibold text-gray-800"><i class="fas fa-graduation-cap text-orange-500 mr-2"></i>안전교육 관리</h2>
|
||||
<button onclick="openAddEducation()" class="px-4 py-2 bg-orange-600 text-white rounded-lg hover:bg-orange-700 text-sm font-medium">
|
||||
<i class="fas fa-plus mr-1"></i>교육 등록
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-end gap-3">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">시작일</label>
|
||||
<input type="date" id="eduDateFrom" class="input-field px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">종료일</label>
|
||||
<input type="date" id="eduDateTo" class="input-field px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">구분</label>
|
||||
<select id="eduTargetType" class="input-field px-3 py-2 rounded-lg text-sm">
|
||||
<option value="">전체</option>
|
||||
<option value="day_labor">일용공</option>
|
||||
<option value="partner_schedule">협력업체</option>
|
||||
<option value="manual">수동등록</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 교육 목록 -->
|
||||
<div class="bg-white rounded-xl shadow-sm p-5">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="visit-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>교육일</th>
|
||||
<th>구분</th>
|
||||
<th>교육자</th>
|
||||
<th class="text-center">참석인원</th>
|
||||
<th>상태</th>
|
||||
<th class="hide-mobile">비고</th>
|
||||
<th class="text-right">관리</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="educationTableBody">
|
||||
<tr><td colspan="7" class="text-center text-gray-400 py-8">로딩 중...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 교육 등록 모달 -->
|
||||
<div id="addEducationModal" class="hidden modal-overlay" onclick="if(event.target===this)closeAddEducation()">
|
||||
<div class="modal-content p-6">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<h3 class="text-lg font-semibold">안전교육 등록</h3>
|
||||
<button onclick="closeAddEducation()" class="text-gray-400 hover:text-gray-600"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
<form id="addEducationForm">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">구분 <span class="text-red-400">*</span></label>
|
||||
<select id="newTargetType" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
|
||||
<option value="day_labor">일용공</option>
|
||||
<option value="partner_schedule">협력업체</option>
|
||||
<option value="manual">수동등록</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">교육일 <span class="text-red-400">*</span></label>
|
||||
<input type="date" id="newEducationDate" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">교육자</label>
|
||||
<input type="text" id="newEducator" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="교육 담당자">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">상태</label>
|
||||
<select id="newEduStatus" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
<option value="planned">예정</option>
|
||||
<option value="completed">완료</option>
|
||||
<option value="cancelled">취소</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">참석자 (한 줄에 한 명, 이름, 업체 형식)</label>
|
||||
<textarea id="newAttendees" class="input-field w-full px-3 py-2 rounded-lg text-sm" rows="4" placeholder="홍길동, ABC건설 김철수, XYZ설비"></textarea>
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">비고</label>
|
||||
<input type="text" id="newEduNotes" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="메모">
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end mt-4 gap-2">
|
||||
<button type="button" onclick="closeAddEducation()" class="px-4 py-2 border rounded-lg text-sm hover:bg-gray-50">취소</button>
|
||||
<button type="submit" class="px-4 py-2 bg-orange-600 text-white rounded-lg text-sm hover:bg-orange-700">등록</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 교육 수정 모달 -->
|
||||
<div id="editEducationModal" class="hidden modal-overlay" onclick="if(event.target===this)closeEditEducation()">
|
||||
<div class="modal-content p-6">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<h3 class="text-lg font-semibold">안전교육 수정</h3>
|
||||
<button onclick="closeEditEducation()" class="text-gray-400 hover:text-gray-600"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
<form id="editEducationForm">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">구분</label>
|
||||
<select id="editTargetType" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
<option value="day_labor">일용공</option>
|
||||
<option value="partner_schedule">협력업체</option>
|
||||
<option value="manual">수동등록</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">교육일</label>
|
||||
<input type="date" id="editEducationDate" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">교육자</label>
|
||||
<input type="text" id="editEducator" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">상태</label>
|
||||
<select id="editEduStatus" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
<option value="planned">예정</option>
|
||||
<option value="completed">완료</option>
|
||||
<option value="cancelled">취소</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">참석자 (한 줄에 한 명, 이름, 업체 형식)</label>
|
||||
<textarea id="editAttendees" class="input-field w-full px-3 py-2 rounded-lg text-sm" rows="4"></textarea>
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">비고</label>
|
||||
<input type="text" id="editEduNotes" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end mt-4 gap-2">
|
||||
<button type="button" onclick="closeEditEducation()" class="px-4 py-2 border rounded-lg text-sm hover:bg-gray-50">취소</button>
|
||||
<button type="submit" class="px-4 py-2 bg-orange-600 text-white rounded-lg text-sm hover:bg-orange-700">저장</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tksafety-core.js?v=20260312"></script>
|
||||
<script src="/static/js/tksafety-education.js?v=20260312"></script>
|
||||
<script>initEducationPage();</script>
|
||||
</body>
|
||||
</html>
|
||||
281
tksafety/web/index.html
Normal file
281
tksafety/web/index.html
Normal file
@@ -0,0 +1,281 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>방문 관리 - TK 안전관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tksafety.css?v=20260312">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
<header class="bg-orange-700 text-white sticky top-0 z-50">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div class="flex justify-between items-center h-14">
|
||||
<div class="flex items-center gap-3">
|
||||
<i class="fas fa-shield-alt text-xl text-orange-200"></i>
|
||||
<h1 class="text-lg font-semibold">TK 안전관리</h1>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<div id="headerUserName" class="text-sm font-medium hidden sm:block">-</div>
|
||||
<div id="headerUserAvatar" class="w-8 h-8 bg-orange-600 rounded-full flex items-center justify-center text-sm font-semibold">-</div>
|
||||
<button onclick="doLogout()" class="text-orange-200 hover:text-white" title="로그아웃"><i class="fas fa-sign-out-alt"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4 fade-in">
|
||||
<div class="flex gap-6">
|
||||
<!-- Sidebar Nav -->
|
||||
<nav id="sideNav" class="hidden lg:flex flex-col gap-1 w-48 flex-shrink-0 pt-2"></nav>
|
||||
|
||||
<!-- Main -->
|
||||
<div class="flex-1 min-w-0">
|
||||
<!-- 통계 카드 -->
|
||||
<div class="grid grid-cols-2 sm:grid-cols-4 gap-3 mb-5">
|
||||
<div class="stat-card">
|
||||
<div class="stat-value text-orange-600" id="statTotal">0</div>
|
||||
<div class="stat-label">오늘 방문</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value text-blue-600" id="statCheckedIn">0</div>
|
||||
<div class="stat-label">체크인 중</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value text-gray-600" id="statCheckedOut">0</div>
|
||||
<div class="stat-label">체크아웃</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value text-purple-600" id="statVisitors">0</div>
|
||||
<div class="stat-label">총 인원</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 빠른 등록 폼 -->
|
||||
<div class="bg-white rounded-xl shadow-sm p-5 mb-5">
|
||||
<h2 class="text-base font-semibold text-gray-800 mb-4"><i class="fas fa-plus-circle text-orange-500 mr-2"></i>방문 등록</h2>
|
||||
<form id="visitForm">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3">
|
||||
<!-- 업체 -->
|
||||
<div class="sm:col-span-2 relative">
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">업체</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="flex-1 relative">
|
||||
<input type="text" id="companySearch" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="업체명 검색...">
|
||||
<div id="companyDropdown" class="hidden absolute z-10 w-full mt-1 bg-white border rounded-lg shadow-lg max-h-48 overflow-y-auto"></div>
|
||||
</div>
|
||||
<div class="hidden flex-1">
|
||||
<input type="text" id="manualCompanyName" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="업체명 직접입력">
|
||||
</div>
|
||||
<label class="flex items-center gap-1 text-xs text-gray-500 whitespace-nowrap cursor-pointer">
|
||||
<input type="checkbox" id="manualCompanyToggle" class="rounded">
|
||||
<span>직접입력</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 방문자명 -->
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">방문자명 <span class="text-red-400">*</span></label>
|
||||
<input type="text" id="visitorName" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="대표 방문자" required>
|
||||
</div>
|
||||
<!-- 인원 -->
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">인원</label>
|
||||
<div class="flex items-center gap-1">
|
||||
<button type="button" id="countMinus" class="w-9 h-9 flex items-center justify-center border rounded-lg hover:bg-gray-50 text-gray-600"><i class="fas fa-minus text-xs"></i></button>
|
||||
<input type="number" id="visitorCount" value="1" min="1" class="input-field w-14 text-center px-1 py-2 rounded-lg text-sm">
|
||||
<button type="button" id="countPlus" class="w-9 h-9 flex items-center justify-center border rounded-lg hover:bg-gray-50 text-gray-600"><i class="fas fa-plus text-xs"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 목적 -->
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">방문 목적 <span class="text-red-400">*</span></label>
|
||||
<select id="visitPurpose" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
|
||||
<option value="">선택</option>
|
||||
<option value="day_labor">일용공</option>
|
||||
<option value="equipment_repair">설비수리</option>
|
||||
<option value="inspection">검사</option>
|
||||
<option value="delivery">납품/배송</option>
|
||||
<option value="safety_audit">안전점검</option>
|
||||
<option value="client_audit">고객심사</option>
|
||||
<option value="construction">공사</option>
|
||||
<option value="other">기타</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- 작업장 -->
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">작업장</label>
|
||||
<input type="text" id="workplaceName" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="작업장소">
|
||||
</div>
|
||||
<!-- 안전교육 -->
|
||||
<div class="flex items-end pb-1">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="checkbox" id="safetyCheck" class="h-5 w-5 text-orange-500 rounded border-gray-300">
|
||||
<span class="text-sm text-gray-700">안전교육 이수</span>
|
||||
</label>
|
||||
</div>
|
||||
<!-- 목적 상세 -->
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">목적 상세</label>
|
||||
<input type="text" id="purposeDetail" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="상세 내용">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 추가 정보 (접이식) -->
|
||||
<div class="mt-3">
|
||||
<button type="button" onclick="toggleExtra()" class="text-sm text-gray-500 hover:text-gray-700 flex items-center gap-1">
|
||||
<i id="extraToggleIcon" class="fas fa-chevron-down text-xs"></i>추가 정보
|
||||
</button>
|
||||
<div id="extraFields" class="collapsible-content">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3 mt-2">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">차량번호</label>
|
||||
<input type="text" id="vehicleNumber" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="12가 3456">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">담당부서</label>
|
||||
<select id="managingDept" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
<option value="">선택</option>
|
||||
<option value="생산">생산</option>
|
||||
<option value="품질">품질</option>
|
||||
<option value="구매">구매</option>
|
||||
<option value="설계">설계</option>
|
||||
<option value="영업">영업</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">비고</label>
|
||||
<input type="text" id="visitNotes" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="메모">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end mt-4">
|
||||
<button type="submit" class="px-6 py-2.5 bg-orange-600 text-white rounded-lg hover:bg-orange-700 text-sm font-medium">
|
||||
<i class="fas fa-check mr-2"></i>등록
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 오늘 방문 현황 -->
|
||||
<div class="bg-white rounded-xl shadow-sm p-5 mb-5">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h2 class="text-base font-semibold text-gray-800"><i class="fas fa-list text-orange-500 mr-2"></i>오늘 방문 현황</h2>
|
||||
<div class="flex gap-2">
|
||||
<button onclick="doBulkCheckout()" class="text-xs text-blue-600 hover:text-blue-800 border border-blue-200 px-3 py-1.5 rounded-lg hover:bg-blue-50">
|
||||
<i class="fas fa-check-double mr-1"></i>전체 마감
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="visit-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>업체</th>
|
||||
<th>방문자</th>
|
||||
<th class="text-center">인원</th>
|
||||
<th>목적</th>
|
||||
<th class="hide-mobile">안전교육</th>
|
||||
<th>체크인</th>
|
||||
<th>상태</th>
|
||||
<th class="text-right">관리</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="visitTableBody">
|
||||
<tr><td colspan="8" class="text-center text-gray-400 py-8">로딩 중...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CSV 내보내기 -->
|
||||
<div class="bg-white rounded-xl shadow-sm p-5">
|
||||
<h2 class="text-base font-semibold text-gray-800 mb-4"><i class="fas fa-download text-orange-500 mr-2"></i>CSV 내보내기</h2>
|
||||
<div class="flex flex-wrap items-end gap-3">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">시작일</label>
|
||||
<input type="date" id="exportDateFrom" class="input-field px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">종료일</label>
|
||||
<input type="date" id="exportDateTo" class="input-field px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<button onclick="exportVisits()" class="px-4 py-2 border border-gray-300 rounded-lg text-sm hover:bg-gray-50">
|
||||
<i class="fas fa-file-csv mr-1"></i>내보내기
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 수정 모달 -->
|
||||
<div id="editVisitModal" class="hidden modal-overlay" onclick="if(event.target===this)closeEditVisit()">
|
||||
<div class="modal-content p-6">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<h3 class="text-lg font-semibold">방문 수정</h3>
|
||||
<button onclick="closeEditVisit()" class="text-gray-400 hover:text-gray-600"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
<form id="editVisitForm">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">방문자명</label>
|
||||
<input type="text" id="editVisitorName" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">인원</label>
|
||||
<input type="number" id="editVisitorCount" min="1" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">목적</label>
|
||||
<select id="editPurpose" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
<option value="day_labor">일용공</option>
|
||||
<option value="equipment_repair">설비수리</option>
|
||||
<option value="inspection">검사</option>
|
||||
<option value="delivery">납품/배송</option>
|
||||
<option value="safety_audit">안전점검</option>
|
||||
<option value="client_audit">고객심사</option>
|
||||
<option value="construction">공사</option>
|
||||
<option value="other">기타</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">목적 상세</label>
|
||||
<input type="text" id="editPurposeDetail" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">작업장</label>
|
||||
<input type="text" id="editWorkplace" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">차량번호</label>
|
||||
<input type="text" id="editVehicle" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div class="flex items-end pb-1">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="checkbox" id="editSafetyCheck" class="h-5 w-5 text-orange-500 rounded">
|
||||
<span class="text-sm">안전교육 이수</span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">비고</label>
|
||||
<input type="text" id="editNotes" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end mt-4 gap-2">
|
||||
<button type="button" onclick="closeEditVisit()" class="px-4 py-2 border rounded-lg text-sm hover:bg-gray-50">취소</button>
|
||||
<button type="submit" class="px-4 py-2 bg-orange-600 text-white rounded-lg text-sm hover:bg-orange-700">저장</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tksafety-core.js?v=20260312"></script>
|
||||
<script src="/static/js/tksafety-visit.js?v=20260312"></script>
|
||||
<script>initVisitPage();</script>
|
||||
</body>
|
||||
</html>
|
||||
45
tksafety/web/nginx.conf
Normal file
45
tksafety/web/nginx.conf
Normal file
@@ -0,0 +1,45 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
charset utf-8;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/javascript application/json;
|
||||
gzip_min_length 1024;
|
||||
|
||||
location ~* \.html$ {
|
||||
expires -1;
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
||||
}
|
||||
|
||||
location ~* \.(js|css)$ {
|
||||
expires 1h;
|
||||
add_header Cache-Control "public, no-transform";
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://tksafety-api:3000/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location /static/ {
|
||||
expires 1h;
|
||||
add_header Cache-Control "public, no-transform";
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 'ok';
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
63
tksafety/web/static/css/tksafety.css
Normal file
63
tksafety/web/static/css/tksafety.css
Normal file
@@ -0,0 +1,63 @@
|
||||
/* tksafety global styles */
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f8fafc; margin: 0; }
|
||||
.fade-in { opacity: 0; transition: opacity 0.3s; }
|
||||
.fade-in.visible { opacity: 1; }
|
||||
|
||||
/* Input */
|
||||
.input-field { border: 1px solid #e2e8f0; transition: border-color 0.15s; outline: none; }
|
||||
.input-field:focus { border-color: #f97316; box-shadow: 0 0 0 3px rgba(249,115,22,0.1); }
|
||||
|
||||
/* Toast */
|
||||
.toast-message { transition: opacity 0.3s; }
|
||||
|
||||
/* Nav active */
|
||||
.nav-link.active { background: rgba(249,115,22,0.15); color: #ea580c; font-weight: 600; }
|
||||
|
||||
/* Stat card */
|
||||
.stat-card { background: white; border-radius: 0.75rem; padding: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
|
||||
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
|
||||
.stat-card .stat-label { font-size: 0.8rem; color: #6b7280; margin-top: 0.25rem; }
|
||||
|
||||
/* Table */
|
||||
.visit-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
|
||||
.visit-table th { background: #f1f5f9; padding: 0.625rem 0.75rem; text-align: left; font-weight: 600; color: #475569; white-space: nowrap; border-bottom: 2px solid #e2e8f0; }
|
||||
.visit-table td { padding: 0.625rem 0.75rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
|
||||
.visit-table tr:hover { background: #f8fafc; }
|
||||
|
||||
/* Badge */
|
||||
.badge { display: inline-flex; align-items: center; padding: 0.125rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; }
|
||||
.badge-green { background: #ecfdf5; color: #059669; }
|
||||
.badge-blue { background: #eff6ff; color: #2563eb; }
|
||||
.badge-amber { background: #fffbeb; color: #d97706; }
|
||||
.badge-red { background: #fef2f2; color: #dc2626; }
|
||||
.badge-gray { background: #f3f4f6; color: #6b7280; }
|
||||
|
||||
/* Purpose badges */
|
||||
.purpose-day_labor { background: #dbeafe; color: #1d4ed8; }
|
||||
.purpose-equipment_repair { background: #fef3c7; color: #92400e; }
|
||||
.purpose-inspection { background: #ede9fe; color: #6d28d9; }
|
||||
.purpose-delivery { background: #d1fae5; color: #065f46; }
|
||||
.purpose-safety_audit { background: #fee2e2; color: #991b1b; }
|
||||
.purpose-client_audit { background: #fce7f3; color: #9d174d; }
|
||||
.purpose-construction { background: #e0e7ff; color: #3730a3; }
|
||||
.purpose-other { background: #f3f4f6; color: #374151; }
|
||||
|
||||
/* Collapsible */
|
||||
.collapsible-content { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
|
||||
.collapsible-content.open { max-height: 500px; }
|
||||
|
||||
/* Modal */
|
||||
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
|
||||
.modal-content { background: white; border-radius: 0.75rem; max-width: 40rem; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
|
||||
|
||||
/* Safety warning */
|
||||
.safety-warning { animation: pulse 2s infinite; }
|
||||
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
.stat-card .stat-value { font-size: 1.25rem; }
|
||||
.visit-table { font-size: 0.8rem; }
|
||||
.visit-table th, .visit-table td { padding: 0.5rem; }
|
||||
.hide-mobile { display: none; }
|
||||
}
|
||||
123
tksafety/web/static/js/tksafety-core.js
Normal file
123
tksafety/web/static/js/tksafety-core.js
Normal file
@@ -0,0 +1,123 @@
|
||||
/* ===== 서비스 워커 해제 ===== */
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.getRegistrations().then(function(regs) { regs.forEach(function(r) { r.unregister(); }); });
|
||||
if (typeof caches !== 'undefined') { caches.keys().then(function(ns) { ns.forEach(function(n) { caches.delete(n); }); }); }
|
||||
}
|
||||
|
||||
/* ===== Config ===== */
|
||||
const API_BASE = '/api';
|
||||
const PURPOSE_LABELS = {
|
||||
day_labor: '일용공', equipment_repair: '설비수리', inspection: '검사',
|
||||
delivery: '납품/배송', safety_audit: '안전점검', client_audit: '고객심사',
|
||||
construction: '공사', other: '기타'
|
||||
};
|
||||
|
||||
/* ===== Token ===== */
|
||||
function _cookieGet(n) { const m = document.cookie.match(new RegExp('(?:^|; )' + n + '=([^;]*)')); return m ? decodeURIComponent(m[1]) : null; }
|
||||
function _cookieRemove(n) { let c = n + '=; path=/; max-age=0'; if (location.hostname.includes('technicalkorea.net')) c += '; domain=.technicalkorea.net; secure; samesite=lax'; document.cookie = c; }
|
||||
function getToken() { return _cookieGet('sso_token') || localStorage.getItem('sso_token'); }
|
||||
function getLoginUrl() {
|
||||
const h = location.hostname;
|
||||
const t = Date.now();
|
||||
if (h.includes('technicalkorea.net')) return location.protocol + '//tkfb.technicalkorea.net/login?redirect=' + encodeURIComponent(location.href) + '&_t=' + t;
|
||||
return location.protocol + '//' + h + ':30000/login?redirect=' + encodeURIComponent(location.href) + '&_t=' + t;
|
||||
}
|
||||
function decodeToken(t) { try { const b = atob(t.split('.')[1].replace(/-/g,'+').replace(/_/g,'/')); return JSON.parse(new TextDecoder().decode(Uint8Array.from(b, c => c.charCodeAt(0)))); } catch { return null; } }
|
||||
|
||||
/* ===== 리다이렉트 루프 방지 ===== */
|
||||
const _REDIRECT_KEY = '_sso_redirect_ts';
|
||||
function _safeRedirect() {
|
||||
const last = parseInt(sessionStorage.getItem(_REDIRECT_KEY) || '0', 10);
|
||||
if (Date.now() - last < 5000) { console.warn('[tksafety] 리다이렉트 루프 감지'); return; }
|
||||
sessionStorage.setItem(_REDIRECT_KEY, String(Date.now()));
|
||||
location.href = getLoginUrl();
|
||||
}
|
||||
|
||||
/* ===== API ===== */
|
||||
async function api(path, opts = {}) {
|
||||
const token = getToken();
|
||||
const headers = { 'Authorization': token ? `Bearer ${token}` : '', ...(opts.headers||{}) };
|
||||
if (!(opts.body instanceof FormData)) headers['Content-Type'] = 'application/json';
|
||||
const res = await fetch(API_BASE + path, { ...opts, headers });
|
||||
if (res.status === 401) { _safeRedirect(); throw new Error('인증 만료'); }
|
||||
if (res.headers.get('content-type')?.includes('text/csv')) return res;
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || '요청 실패');
|
||||
return data;
|
||||
}
|
||||
|
||||
/* ===== Toast ===== */
|
||||
function showToast(msg, type = 'success') {
|
||||
document.querySelector('.toast-message')?.remove();
|
||||
const el = document.createElement('div');
|
||||
el.className = `toast-message fixed bottom-4 right-4 px-4 py-3 rounded-lg text-white z-[10000] shadow-lg ${type==='success'?'bg-orange-500':'bg-red-500'}`;
|
||||
el.innerHTML = `<i class="fas ${type==='success'?'fa-check-circle':'fa-exclamation-circle'} mr-2"></i>${escapeHtml(msg)}`;
|
||||
document.body.appendChild(el);
|
||||
setTimeout(() => { el.classList.add('opacity-0'); setTimeout(() => el.remove(), 300); }, 3000);
|
||||
}
|
||||
|
||||
/* ===== Escape ===== */
|
||||
function escapeHtml(str) { if (!str) return ''; const d = document.createElement('div'); d.textContent = str; return d.innerHTML; }
|
||||
|
||||
/* ===== Helpers ===== */
|
||||
function formatDate(d) { if (!d) return ''; return String(d).substring(0, 10); }
|
||||
function formatTime(d) { if (!d) return ''; return String(d).substring(11, 16); }
|
||||
function formatDateTime(d) { if (!d) return ''; return String(d).substring(0, 16).replace('T', ' '); }
|
||||
function purposeLabel(p) { return PURPOSE_LABELS[p] || p || ''; }
|
||||
function purposeBadge(p) { return `<span class="badge purpose-${p}">${purposeLabel(p)}</span>`; }
|
||||
function statusBadge(s) {
|
||||
const m = { checked_in: ['badge-green', '체크인'], checked_out: ['badge-blue', '체크아웃'], auto_checkout: ['badge-amber', '자동마감'], cancelled: ['badge-gray', '취소'] };
|
||||
const [cls, label] = m[s] || ['badge-gray', s];
|
||||
return `<span class="badge ${cls}">${label}</span>`;
|
||||
}
|
||||
|
||||
/* ===== Logout ===== */
|
||||
function doLogout() {
|
||||
if (!confirm('로그아웃?')) return;
|
||||
_cookieRemove('sso_token'); _cookieRemove('sso_user'); _cookieRemove('sso_refresh_token');
|
||||
['sso_token','sso_user','sso_refresh_token','token','user','access_token','currentUser','current_user','userInfo','userPageAccess'].forEach(k => localStorage.removeItem(k));
|
||||
location.href = getLoginUrl();
|
||||
}
|
||||
|
||||
/* ===== Navbar ===== */
|
||||
function renderNavbar() {
|
||||
const currentPage = location.pathname.replace(/\//g, '') || 'index.html';
|
||||
const links = [
|
||||
{ href: '/', icon: 'fa-door-open', label: '방문 관리', match: ['', 'index.html'] },
|
||||
{ href: '/education.html', icon: 'fa-graduation-cap', label: '안전교육', match: ['education.html'] },
|
||||
];
|
||||
const nav = document.getElementById('sideNav');
|
||||
if (!nav) return;
|
||||
nav.innerHTML = links.map(l => {
|
||||
const active = l.match.some(m => currentPage === m || currentPage.endsWith(m));
|
||||
return `<a href="${l.href}" class="nav-link flex items-center gap-3 px-4 py-2.5 rounded-lg text-sm transition-colors ${active ? 'active' : 'text-gray-600 hover:bg-gray-100'}">
|
||||
<i class="fas ${l.icon} w-5 text-center"></i><span>${l.label}</span></a>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
/* ===== State ===== */
|
||||
let currentUser = null;
|
||||
|
||||
/* ===== Init ===== */
|
||||
function initAuth() {
|
||||
const token = getToken();
|
||||
if (!token) { _safeRedirect(); return false; }
|
||||
const decoded = decodeToken(token);
|
||||
if (!decoded) { _safeRedirect(); return false; }
|
||||
sessionStorage.removeItem(_REDIRECT_KEY);
|
||||
if (!localStorage.getItem('sso_token')) localStorage.setItem('sso_token', token);
|
||||
currentUser = {
|
||||
id: decoded.user_id || decoded.id,
|
||||
username: decoded.username || decoded.sub,
|
||||
name: decoded.name || decoded.full_name,
|
||||
role: (decoded.role || decoded.access_level || '').toLowerCase()
|
||||
};
|
||||
const dn = currentUser.name || currentUser.username;
|
||||
const nameEl = document.getElementById('headerUserName');
|
||||
const avatarEl = document.getElementById('headerUserAvatar');
|
||||
if (nameEl) nameEl.textContent = dn;
|
||||
if (avatarEl) avatarEl.textContent = dn.charAt(0).toUpperCase();
|
||||
renderNavbar();
|
||||
setTimeout(() => document.querySelector('.fade-in')?.classList.add('visible'), 50);
|
||||
return true;
|
||||
}
|
||||
143
tksafety/web/static/js/tksafety-education.js
Normal file
143
tksafety/web/static/js/tksafety-education.js
Normal file
@@ -0,0 +1,143 @@
|
||||
/* ===== Education Management ===== */
|
||||
let educationList = [];
|
||||
let editingEducationId = null;
|
||||
|
||||
async function loadEducation() {
|
||||
try {
|
||||
const dateFrom = document.getElementById('eduDateFrom')?.value || '';
|
||||
const dateTo = document.getElementById('eduDateTo')?.value || '';
|
||||
const targetType = document.getElementById('eduTargetType')?.value || '';
|
||||
const params = new URLSearchParams();
|
||||
if (dateFrom) params.set('date_from', dateFrom);
|
||||
if (dateTo) params.set('date_to', dateTo);
|
||||
if (targetType) params.set('target_type', targetType);
|
||||
const r = await api('/education?' + params.toString());
|
||||
educationList = r.data || [];
|
||||
renderEducationList();
|
||||
} catch (e) {
|
||||
showToast('교육 목록 로드 실패: ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function renderEducationList() {
|
||||
const tbody = document.getElementById('educationTableBody');
|
||||
if (!educationList.length) {
|
||||
tbody.innerHTML = '<tr><td colspan="7" class="text-center text-gray-400 py-8">등록된 안전교육이 없습니다</td></tr>';
|
||||
return;
|
||||
}
|
||||
const typeLabels = { day_labor: '일용공', partner_schedule: '협력업체', manual: '수동등록' };
|
||||
const statusLabels = { planned: '예정', completed: '완료', cancelled: '취소' };
|
||||
const statusColors = { planned: 'badge-amber', completed: 'badge-green', cancelled: 'badge-gray' };
|
||||
tbody.innerHTML = educationList.map(e => {
|
||||
const attendeeCount = e.attendees ? (typeof e.attendees === 'string' ? JSON.parse(e.attendees) : e.attendees).length : 0;
|
||||
return `<tr>
|
||||
<td>${formatDate(e.education_date)}</td>
|
||||
<td><span class="badge ${e.target_type === 'day_labor' ? 'badge-blue' : e.target_type === 'partner_schedule' ? 'badge-green' : 'badge-gray'}">${typeLabels[e.target_type] || e.target_type}</span></td>
|
||||
<td>${escapeHtml(e.educator) || '-'}</td>
|
||||
<td class="text-center">${attendeeCount}명</td>
|
||||
<td><span class="badge ${statusColors[e.status] || 'badge-gray'}">${statusLabels[e.status] || e.status}</span></td>
|
||||
<td class="hide-mobile">${escapeHtml(e.notes) || '-'}</td>
|
||||
<td class="text-right">
|
||||
<button onclick="openEditEducation(${e.id})" class="text-gray-400 hover:text-gray-600 text-xs" title="수정"><i class="fas fa-pen"></i></button>
|
||||
<button onclick="doDeleteEducation(${e.id})" class="text-gray-400 hover:text-red-500 text-xs ml-1" title="삭제"><i class="fas fa-trash"></i></button>
|
||||
</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
/* ===== Add education modal ===== */
|
||||
function openAddEducation() {
|
||||
document.getElementById('addEducationModal').classList.remove('hidden');
|
||||
}
|
||||
function closeAddEducation() {
|
||||
document.getElementById('addEducationModal').classList.add('hidden');
|
||||
document.getElementById('addEducationForm').reset();
|
||||
}
|
||||
|
||||
async function submitAddEducation(e) {
|
||||
e.preventDefault();
|
||||
const attendeesRaw = document.getElementById('newAttendees').value.trim();
|
||||
const attendees = attendeesRaw ? attendeesRaw.split('\n').map(line => {
|
||||
const parts = line.split(',').map(s => s.trim());
|
||||
return { name: parts[0] || '', company: parts[1] || '' };
|
||||
}).filter(a => a.name) : [];
|
||||
|
||||
const data = {
|
||||
target_type: document.getElementById('newTargetType').value,
|
||||
education_date: document.getElementById('newEducationDate').value,
|
||||
educator: document.getElementById('newEducator').value.trim() || null,
|
||||
attendees: attendees,
|
||||
status: document.getElementById('newEduStatus').value || 'planned',
|
||||
notes: document.getElementById('newEduNotes').value.trim() || null,
|
||||
};
|
||||
if (!data.education_date) { showToast('교육일은 필수입니다', 'error'); return; }
|
||||
try {
|
||||
await api('/education', { method: 'POST', body: JSON.stringify(data) });
|
||||
showToast('안전교육이 등록되었습니다');
|
||||
closeAddEducation();
|
||||
await loadEducation();
|
||||
} catch (e) { showToast(e.message, 'error'); }
|
||||
}
|
||||
|
||||
/* ===== Edit education ===== */
|
||||
function openEditEducation(id) {
|
||||
const edu = educationList.find(x => x.id === id);
|
||||
if (!edu) return;
|
||||
editingEducationId = id;
|
||||
document.getElementById('editTargetType').value = edu.target_type;
|
||||
document.getElementById('editEducationDate').value = formatDate(edu.education_date);
|
||||
document.getElementById('editEducator').value = edu.educator || '';
|
||||
document.getElementById('editEduStatus').value = edu.status;
|
||||
document.getElementById('editEduNotes').value = edu.notes || '';
|
||||
const attendees = edu.attendees ? (typeof edu.attendees === 'string' ? JSON.parse(edu.attendees) : edu.attendees) : [];
|
||||
document.getElementById('editAttendees').value = attendees.map(a => `${a.name}${a.company ? ', ' + a.company : ''}`).join('\n');
|
||||
document.getElementById('editEducationModal').classList.remove('hidden');
|
||||
}
|
||||
function closeEditEducation() {
|
||||
document.getElementById('editEducationModal').classList.add('hidden');
|
||||
editingEducationId = null;
|
||||
}
|
||||
|
||||
async function submitEditEducation(e) {
|
||||
e.preventDefault();
|
||||
if (!editingEducationId) return;
|
||||
const attendeesRaw = document.getElementById('editAttendees').value.trim();
|
||||
const attendees = attendeesRaw ? attendeesRaw.split('\n').map(line => {
|
||||
const parts = line.split(',').map(s => s.trim());
|
||||
return { name: parts[0] || '', company: parts[1] || '' };
|
||||
}).filter(a => a.name) : [];
|
||||
|
||||
const data = {
|
||||
target_type: document.getElementById('editTargetType').value,
|
||||
education_date: document.getElementById('editEducationDate').value,
|
||||
educator: document.getElementById('editEducator').value.trim() || null,
|
||||
attendees: attendees,
|
||||
status: document.getElementById('editEduStatus').value,
|
||||
notes: document.getElementById('editEduNotes').value.trim() || null,
|
||||
};
|
||||
try {
|
||||
await api(`/education/${editingEducationId}`, { method: 'PUT', body: JSON.stringify(data) });
|
||||
showToast('수정되었습니다');
|
||||
closeEditEducation();
|
||||
await loadEducation();
|
||||
} catch (e) { showToast(e.message, 'error'); }
|
||||
}
|
||||
|
||||
async function doDeleteEducation(id) {
|
||||
if (!confirm('이 교육 기록을 삭제하시겠습니까?')) return;
|
||||
try {
|
||||
await api(`/education/${id}`, { method: 'DELETE' });
|
||||
showToast('삭제되었습니다');
|
||||
await loadEducation();
|
||||
} catch (e) { showToast(e.message, 'error'); }
|
||||
}
|
||||
|
||||
function initEducationPage() {
|
||||
if (!initAuth()) return;
|
||||
document.getElementById('addEducationForm').addEventListener('submit', submitAddEducation);
|
||||
document.getElementById('editEducationForm').addEventListener('submit', submitEditEducation);
|
||||
document.getElementById('eduDateFrom')?.addEventListener('change', loadEducation);
|
||||
document.getElementById('eduDateTo')?.addEventListener('change', loadEducation);
|
||||
document.getElementById('eduTargetType')?.addEventListener('change', loadEducation);
|
||||
loadEducation();
|
||||
}
|
||||
272
tksafety/web/static/js/tksafety-visit.js
Normal file
272
tksafety/web/static/js/tksafety-visit.js
Normal file
@@ -0,0 +1,272 @@
|
||||
/* ===== Visit Management ===== */
|
||||
let todayVisits = [];
|
||||
let editingVisitId = null;
|
||||
|
||||
async function loadTodayVisits() {
|
||||
try {
|
||||
const r = await api('/daily-visits/today');
|
||||
const { visits, stats } = r.data;
|
||||
todayVisits = visits;
|
||||
renderStats(stats);
|
||||
renderVisitTable(visits);
|
||||
} catch (e) {
|
||||
showToast('데이터 로드 실패: ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function renderStats(s) {
|
||||
document.getElementById('statTotal').textContent = s.total || 0;
|
||||
document.getElementById('statCheckedIn').textContent = s.checked_in || 0;
|
||||
document.getElementById('statCheckedOut').textContent = s.checked_out || 0;
|
||||
document.getElementById('statVisitors').textContent = s.total_visitors || 0;
|
||||
}
|
||||
|
||||
function renderVisitTable(visits) {
|
||||
const tbody = document.getElementById('visitTableBody');
|
||||
if (!visits.length) {
|
||||
tbody.innerHTML = '<tr><td colspan="8" class="text-center text-gray-400 py-8">오늘 방문 기록이 없습니다</td></tr>';
|
||||
return;
|
||||
}
|
||||
tbody.innerHTML = visits.map(v => {
|
||||
const companyName = v.partner_company_name || v.company_name || '-';
|
||||
const safetyIcon = v.safety_education_yn
|
||||
? '<i class="fas fa-check-circle text-orange-500"></i>'
|
||||
: '<i class="fas fa-exclamation-triangle text-amber-500 safety-warning" title="안전교육 미이수"></i>';
|
||||
const actions = v.status === 'checked_in'
|
||||
? `<button onclick="doCheckout(${v.id})" class="text-blue-600 hover:text-blue-800 text-xs px-2 py-1 border border-blue-200 rounded hover:bg-blue-50">체크아웃</button>`
|
||||
: '';
|
||||
return `<tr>
|
||||
<td>${escapeHtml(companyName)}</td>
|
||||
<td>${escapeHtml(v.visitor_name)}</td>
|
||||
<td class="text-center">${v.visitor_count}</td>
|
||||
<td>${purposeBadge(v.purpose)}</td>
|
||||
<td class="hide-mobile">${safetyIcon}</td>
|
||||
<td>${formatTime(v.check_in_time)}</td>
|
||||
<td>${statusBadge(v.status)}</td>
|
||||
<td class="text-right">
|
||||
${actions}
|
||||
<button onclick="openEditVisit(${v.id})" class="text-gray-400 hover:text-gray-600 text-xs ml-1" title="수정"><i class="fas fa-pen"></i></button>
|
||||
<button onclick="doDeleteVisit(${v.id})" class="text-gray-400 hover:text-red-500 text-xs ml-1" title="삭제"><i class="fas fa-trash"></i></button>
|
||||
</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
/* ===== 업체 자동완성 ===== */
|
||||
let companySearchTimeout = null;
|
||||
let selectedCompanyId = null;
|
||||
|
||||
function initCompanySearch() {
|
||||
const input = document.getElementById('companySearch');
|
||||
const dropdown = document.getElementById('companyDropdown');
|
||||
const manualToggle = document.getElementById('manualCompanyToggle');
|
||||
const manualInput = document.getElementById('manualCompanyName');
|
||||
|
||||
input.addEventListener('input', () => {
|
||||
clearTimeout(companySearchTimeout);
|
||||
selectedCompanyId = null;
|
||||
const q = input.value.trim();
|
||||
if (q.length < 1) { dropdown.classList.add('hidden'); return; }
|
||||
companySearchTimeout = setTimeout(async () => {
|
||||
try {
|
||||
const r = await api('/partners/search?q=' + encodeURIComponent(q));
|
||||
const items = r.data || [];
|
||||
if (items.length === 0) {
|
||||
dropdown.innerHTML = '<div class="px-3 py-2 text-sm text-gray-400">검색 결과 없음</div>';
|
||||
} else {
|
||||
dropdown.innerHTML = items.map(c =>
|
||||
`<div class="px-3 py-2 text-sm hover:bg-orange-50 cursor-pointer" onclick="selectCompany(${c.id}, '${escapeHtml(c.company_name).replace(/'/g, "\\'")}')">
|
||||
<span class="font-medium">${escapeHtml(c.company_name)}</span>
|
||||
${c.business_number ? `<span class="text-gray-400 text-xs ml-2">${c.business_number}</span>` : ''}
|
||||
</div>`
|
||||
).join('');
|
||||
}
|
||||
dropdown.classList.remove('hidden');
|
||||
} catch (e) { dropdown.classList.add('hidden'); }
|
||||
}, 300);
|
||||
});
|
||||
|
||||
input.addEventListener('blur', () => setTimeout(() => dropdown.classList.add('hidden'), 200));
|
||||
|
||||
manualToggle.addEventListener('change', () => {
|
||||
if (manualToggle.checked) {
|
||||
input.parentElement.classList.add('hidden');
|
||||
manualInput.parentElement.classList.remove('hidden');
|
||||
selectedCompanyId = null;
|
||||
input.value = '';
|
||||
} else {
|
||||
input.parentElement.classList.remove('hidden');
|
||||
manualInput.parentElement.classList.add('hidden');
|
||||
manualInput.value = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function selectCompany(id, name) {
|
||||
selectedCompanyId = id;
|
||||
document.getElementById('companySearch').value = name;
|
||||
document.getElementById('companyDropdown').classList.add('hidden');
|
||||
}
|
||||
|
||||
/* ===== 인원수 +- ===== */
|
||||
function initCounterButtons() {
|
||||
document.getElementById('countMinus').addEventListener('click', () => {
|
||||
const el = document.getElementById('visitorCount');
|
||||
const v = parseInt(el.value) || 1;
|
||||
if (v > 1) el.value = v - 1;
|
||||
});
|
||||
document.getElementById('countPlus').addEventListener('click', () => {
|
||||
const el = document.getElementById('visitorCount');
|
||||
el.value = (parseInt(el.value) || 0) + 1;
|
||||
});
|
||||
}
|
||||
|
||||
/* ===== 추가정보 접이식 ===== */
|
||||
function toggleExtra() {
|
||||
document.getElementById('extraFields').classList.toggle('open');
|
||||
const icon = document.getElementById('extraToggleIcon');
|
||||
icon.classList.toggle('fa-chevron-down');
|
||||
icon.classList.toggle('fa-chevron-up');
|
||||
}
|
||||
|
||||
/* ===== 방문 등록 ===== */
|
||||
async function submitVisit(e) {
|
||||
e.preventDefault();
|
||||
const manualMode = document.getElementById('manualCompanyToggle').checked;
|
||||
const company_id = manualMode ? null : selectedCompanyId;
|
||||
const company_name = manualMode ? document.getElementById('manualCompanyName').value.trim() : null;
|
||||
|
||||
if (!company_id && !company_name) {
|
||||
showToast('업체를 선택하거나 입력해주세요', 'error'); return;
|
||||
}
|
||||
|
||||
const data = {
|
||||
company_id,
|
||||
company_name: company_name || document.getElementById('companySearch').value.trim(),
|
||||
visitor_name: document.getElementById('visitorName').value.trim(),
|
||||
visitor_count: parseInt(document.getElementById('visitorCount').value) || 1,
|
||||
purpose: document.getElementById('visitPurpose').value,
|
||||
purpose_detail: document.getElementById('purposeDetail').value.trim() || null,
|
||||
workplace_name: document.getElementById('workplaceName').value.trim() || null,
|
||||
safety_education_yn: document.getElementById('safetyCheck').checked,
|
||||
vehicle_number: document.getElementById('vehicleNumber').value.trim() || null,
|
||||
notes: document.getElementById('visitNotes').value.trim() || null,
|
||||
managing_department: document.getElementById('managingDept').value || null,
|
||||
};
|
||||
|
||||
if (!data.visitor_name) { showToast('방문자명을 입력해주세요', 'error'); return; }
|
||||
if (!data.purpose) { showToast('방문 목적을 선택해주세요', 'error'); return; }
|
||||
|
||||
try {
|
||||
await api('/daily-visits/', { method: 'POST', body: JSON.stringify(data) });
|
||||
showToast('방문이 등록되었습니다');
|
||||
document.getElementById('visitForm').reset();
|
||||
selectedCompanyId = null;
|
||||
document.getElementById('manualCompanyToggle').checked = false;
|
||||
document.getElementById('companySearch').parentElement.classList.remove('hidden');
|
||||
document.getElementById('manualCompanyName').parentElement.classList.add('hidden');
|
||||
document.getElementById('visitorCount').value = '1';
|
||||
await loadTodayVisits();
|
||||
} catch (e) {
|
||||
showToast(e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 체크아웃 ===== */
|
||||
async function doCheckout(id) {
|
||||
try {
|
||||
await api(`/daily-visits/${id}/checkout`, { method: 'PUT', body: JSON.stringify({}) });
|
||||
showToast('체크아웃 완료');
|
||||
await loadTodayVisits();
|
||||
} catch (e) { showToast(e.message, 'error'); }
|
||||
}
|
||||
|
||||
async function doBulkCheckout() {
|
||||
const checkedIn = todayVisits.filter(v => v.status === 'checked_in');
|
||||
if (checkedIn.length === 0) { showToast('체크인 중인 방문이 없습니다', 'error'); return; }
|
||||
if (!confirm(`체크인 중인 ${checkedIn.length}건을 모두 체크아웃 하시겠습니까?`)) return;
|
||||
try {
|
||||
const r = await api('/daily-visits/bulk-checkout', { method: 'POST', body: JSON.stringify({}) });
|
||||
showToast(`${r.data.affected}건 체크아웃 완료`);
|
||||
await loadTodayVisits();
|
||||
} catch (e) { showToast(e.message, 'error'); }
|
||||
}
|
||||
|
||||
/* ===== 수정 ===== */
|
||||
function openEditVisit(id) {
|
||||
const v = todayVisits.find(x => x.id === id);
|
||||
if (!v) return;
|
||||
editingVisitId = id;
|
||||
document.getElementById('editVisitorName').value = v.visitor_name;
|
||||
document.getElementById('editVisitorCount').value = v.visitor_count;
|
||||
document.getElementById('editPurpose').value = v.purpose;
|
||||
document.getElementById('editPurposeDetail').value = v.purpose_detail || '';
|
||||
document.getElementById('editWorkplace').value = v.workplace_name || '';
|
||||
document.getElementById('editSafetyCheck').checked = v.safety_education_yn;
|
||||
document.getElementById('editVehicle').value = v.vehicle_number || '';
|
||||
document.getElementById('editNotes').value = v.notes || '';
|
||||
document.getElementById('editVisitModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeEditVisit() {
|
||||
document.getElementById('editVisitModal').classList.add('hidden');
|
||||
editingVisitId = null;
|
||||
}
|
||||
|
||||
async function submitEditVisit(e) {
|
||||
e.preventDefault();
|
||||
if (!editingVisitId) return;
|
||||
const data = {
|
||||
visitor_name: document.getElementById('editVisitorName').value.trim(),
|
||||
visitor_count: parseInt(document.getElementById('editVisitorCount').value) || 1,
|
||||
purpose: document.getElementById('editPurpose').value,
|
||||
purpose_detail: document.getElementById('editPurposeDetail').value.trim() || null,
|
||||
workplace_name: document.getElementById('editWorkplace').value.trim() || null,
|
||||
safety_education_yn: document.getElementById('editSafetyCheck').checked,
|
||||
vehicle_number: document.getElementById('editVehicle').value.trim() || null,
|
||||
notes: document.getElementById('editNotes').value.trim() || null,
|
||||
};
|
||||
try {
|
||||
await api(`/daily-visits/${editingVisitId}`, { method: 'PUT', body: JSON.stringify(data) });
|
||||
showToast('수정되었습니다');
|
||||
closeEditVisit();
|
||||
await loadTodayVisits();
|
||||
} catch (e) { showToast(e.message, 'error'); }
|
||||
}
|
||||
|
||||
/* ===== 삭제 ===== */
|
||||
async function doDeleteVisit(id) {
|
||||
if (!confirm('이 방문 기록을 삭제하시겠습니까?')) return;
|
||||
try {
|
||||
await api(`/daily-visits/${id}`, { method: 'DELETE' });
|
||||
showToast('삭제되었습니다');
|
||||
await loadTodayVisits();
|
||||
} catch (e) { showToast(e.message, 'error'); }
|
||||
}
|
||||
|
||||
/* ===== CSV 내보내기 ===== */
|
||||
async function exportVisits() {
|
||||
const token = getToken();
|
||||
const dateFrom = document.getElementById('exportDateFrom')?.value || '';
|
||||
const dateTo = document.getElementById('exportDateTo')?.value || '';
|
||||
let url = API_BASE + '/daily-visits/export?';
|
||||
if (dateFrom) url += 'date_from=' + dateFrom + '&';
|
||||
if (dateTo) url += 'date_to=' + dateTo + '&';
|
||||
const res = await fetch(url, { headers: { 'Authorization': `Bearer ${token}` } });
|
||||
if (!res.ok) { showToast('내보내기 실패', 'error'); return; }
|
||||
const blob = await res.blob();
|
||||
const a = document.createElement('a');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = `visits_${dateFrom || 'all'}_${dateTo || 'all'}.csv`;
|
||||
a.click();
|
||||
}
|
||||
|
||||
/* ===== Init ===== */
|
||||
function initVisitPage() {
|
||||
if (!initAuth()) return;
|
||||
initCompanySearch();
|
||||
initCounterButtons();
|
||||
document.getElementById('visitForm').addEventListener('submit', submitVisit);
|
||||
document.getElementById('editVisitForm').addEventListener('submit', submitEditVisit);
|
||||
loadTodayVisits();
|
||||
}
|
||||
Reference in New Issue
Block a user