## 주요 변경사항
### 1. 미사용 페이지 아카이브 (24개)
- admin 폴더 전체 (8개) → .archived-admin/
- 분석 페이지 (5개) → .archived-*
- 공통 페이지 (5개) → .archived-*
- 대시보드 페이지 (2개) → .archived-*
- 기타 (4개) → .archived-*
### 2. 새로운 폴더 구조
```
pages/
├── dashboard.html (메인 대시보드)
├── work/ (작업 관련)
│ ├── report-create.html (작업보고서 작성)
│ ├── report-view.html (작업보고서 조회)
│ └── analysis.html (작업 분석)
├── admin/ (관리 기능)
│ ├── index.html (관리 메뉴 허브)
│ ├── projects.html (프로젝트 관리)
│ ├── workers.html (작업자 관리)
│ ├── codes.html (코드 관리)
│ └── accounts.html (계정 관리)
└── profile/ (프로필)
├── info.html (내 정보)
└── password.html (비밀번호 변경)
```
### 3. 파일명 개선
- group-leader.html → dashboard.html
- daily-work-report.html → work/report-create.html
- daily-work-report-viewer.html → work/report-view.html
- work-analysis.html → work/analysis.html
- work-management.html → admin/index.html
- project-management.html → admin/projects.html
- worker-management.html → admin/workers.html
- code-management.html → admin/codes.html
- my-profile.html → profile/info.html
- change-password.html → profile/password.html
- admin-settings.html → admin/accounts.html
### 4. 내부 링크 전면 수정
- navbar.html 프로필 메뉴 링크 업데이트
- dashboard.html 빠른 작업 링크 업데이트
- admin/* 페이지 간 링크 업데이트
- load-navbar.js 대시보드 경로 수정
영향받는 파일: 39개
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
116 lines
3.2 KiB
JavaScript
116 lines
3.2 KiB
JavaScript
// /js/load-navbar.js
|
|
import { getUser, clearAuthData } from './auth.js';
|
|
import { loadComponent } from './component-loader.js';
|
|
import { config } from './config.js';
|
|
|
|
// 역할 이름을 한글로 변환하는 맵
|
|
const ROLE_NAMES = {
|
|
admin: '관리자',
|
|
system: '시스템 관리자',
|
|
leader: '그룹장',
|
|
user: '작업자',
|
|
support: '지원팀',
|
|
default: '사용자',
|
|
};
|
|
|
|
/**
|
|
* 네비게이션 바 DOM을 사용자 정보와 역할에 맞게 수정하는 프로세서입니다.
|
|
* @param {Document} doc - 파싱된 HTML 문서 객체
|
|
*/
|
|
function processNavbarDom(doc) {
|
|
const currentUser = getUser();
|
|
if (!currentUser) return;
|
|
|
|
// 1. 역할 기반 메뉴 필터링
|
|
filterMenuByRole(doc, currentUser.role);
|
|
|
|
// 2. 사용자 정보 채우기
|
|
populateUserInfo(doc, currentUser);
|
|
}
|
|
|
|
/**
|
|
* 사용자 역할에 따라 메뉴 항목을 필터링합니다.
|
|
* @param {Document} doc - 파싱된 HTML 문서 객체
|
|
* @param {string} userRole - 현재 사용자의 역할
|
|
*/
|
|
function filterMenuByRole(doc, userRole) {
|
|
const selectors = [
|
|
{ role: 'admin', selector: '.admin-only' },
|
|
{ role: 'system', selector: '.system-only' },
|
|
{ role: 'leader', selector: '.leader-only' },
|
|
];
|
|
|
|
selectors.forEach(({ role, selector }) => {
|
|
if (userRole !== role && userRole !== 'system') {
|
|
doc.querySelectorAll(selector).forEach(el => el.remove());
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 네비게이션 바에 사용자 정보를 채웁니다.
|
|
* @param {Document} doc - 파싱된 HTML 문서 객체
|
|
* @param {object} user - 현재 사용자 객체
|
|
*/
|
|
function populateUserInfo(doc, user) {
|
|
const displayName = user.name || user.username;
|
|
const roleName = ROLE_NAMES[user.role] || ROLE_NAMES.default;
|
|
|
|
const elements = {
|
|
'userName': displayName,
|
|
'userRole': roleName,
|
|
'userInitial': displayName.charAt(0),
|
|
};
|
|
|
|
for (const id in elements) {
|
|
const el = doc.getElementById(id);
|
|
if (el) el.textContent = elements[id];
|
|
}
|
|
|
|
// 메인 대시보드 URL 설정
|
|
const dashboardBtn = doc.getElementById('dashboardBtn');
|
|
if (dashboardBtn) {
|
|
dashboardBtn.href = '/pages/dashboard.html';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 네비게이션 바와 관련된 모든 이벤트를 설정합니다.
|
|
*/
|
|
function setupNavbarEvents() {
|
|
const logoutButton = document.getElementById('logoutBtn');
|
|
if (logoutButton) {
|
|
logoutButton.addEventListener('click', () => {
|
|
if (confirm('로그아웃 하시겠습니까?')) {
|
|
clearAuthData();
|
|
window.location.href = config.paths.loginPage;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 현재 시간을 업데이트하는 함수
|
|
*/
|
|
function updateTime() {
|
|
const timeElement = document.getElementById('timeValue');
|
|
if (timeElement) {
|
|
const now = new Date();
|
|
timeElement.textContent = now.toLocaleTimeString('ko-KR', { hour12: false });
|
|
}
|
|
}
|
|
|
|
// 메인 로직: DOMContentLoaded 시 실행
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
if (getUser()) {
|
|
// 1. 컴포넌트 로드 및 DOM 수정
|
|
await loadComponent('navbar', '#navbar-container', processNavbarDom);
|
|
|
|
// 2. DOM에 삽입된 후에 이벤트 리스너 설정
|
|
setupNavbarEvents();
|
|
|
|
// 3. 실시간 시간 업데이트 시작
|
|
updateTime();
|
|
setInterval(updateTime, 1000);
|
|
}
|
|
}); |