106 lines
3.1 KiB
JavaScript
106 lines
3.1 KiB
JavaScript
// /js/project-analysis.js
|
|
import { getMasterData, getAnalysisReport } from './project-analysis-api.js';
|
|
import {
|
|
setDefaultDates,
|
|
setUIState,
|
|
updateFilterOptions,
|
|
renderSummary,
|
|
renderAnalysisTables,
|
|
renderDetailTable,
|
|
switchTab,
|
|
} from './project-analysis-ui.js';
|
|
|
|
// DOM 요소 참조 (이벤트 리스너 설정용)
|
|
const DOM = {
|
|
startDate: document.getElementById('startDate'),
|
|
endDate: document.getElementById('endDate'),
|
|
analyzeBtn: document.getElementById('analyzeBtn'),
|
|
quickMonthBtn: document.getElementById('quickMonth'),
|
|
quickLastMonthBtn: document.getElementById('quickLastMonth'),
|
|
// 필터 버튼은 현재 아무 기능도 하지 않으므로 주석 처리 또는 제거 가능
|
|
// applyFilterBtn: document.getElementById('applyFilter'),
|
|
tabButtons: document.querySelectorAll('.tab-button'),
|
|
};
|
|
|
|
/**
|
|
* 분석 실행 버튼 클릭 이벤트 핸들러
|
|
*/
|
|
async function handleAnalysis() {
|
|
const startDate = DOM.startDate.value;
|
|
const endDate = DOM.endDate.value;
|
|
|
|
if (!startDate || !endDate || startDate > endDate) {
|
|
alert('올바른 분석 기간을 설정해주세요.');
|
|
return;
|
|
}
|
|
|
|
setUIState('loading');
|
|
try {
|
|
const analysisResult = await getAnalysisReport(startDate, endDate);
|
|
|
|
if (!analysisResult.summary.totalHours) {
|
|
setUIState('no-data');
|
|
return;
|
|
}
|
|
|
|
renderSummary(analysisResult.summary);
|
|
renderAnalysisTables(analysisResult);
|
|
renderDetailTable(analysisResult.details);
|
|
setUIState('data');
|
|
|
|
} catch (error) {
|
|
console.error('분석 처리 중 오류:', error);
|
|
setUIState('error');
|
|
alert(error.message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 빠른 날짜 설정 버튼 핸들러
|
|
*/
|
|
function handleQuickDate(monthType) {
|
|
const now = new Date();
|
|
const year = now.getFullYear();
|
|
const month = now.getMonth();
|
|
const firstDay = monthType === 'this' ? new Date(year, month, 1) : new Date(year, month - 1, 1);
|
|
const lastDay = monthType === 'this' ? new Date(year, month + 1, 0) : new Date(year, month, 0);
|
|
|
|
DOM.startDate.value = firstDay.toISOString().split('T')[0];
|
|
DOM.endDate.value = lastDay.toISOString().split('T')[0];
|
|
}
|
|
|
|
/**
|
|
* 이벤트 리스너 설정
|
|
*/
|
|
function setupEventListeners() {
|
|
DOM.analyzeBtn.addEventListener('click', handleAnalysis);
|
|
DOM.quickMonthBtn.addEventListener('click', () => handleQuickDate('this'));
|
|
DOM.quickLastMonthBtn.addEventListener('click', () => handleQuickDate('last'));
|
|
|
|
DOM.tabButtons.forEach(btn => {
|
|
btn.addEventListener('click', () => switchTab(btn.dataset.tab));
|
|
});
|
|
|
|
// 프론트엔드 필터링은 제거되었으므로 관련 이벤트 리스너는 주석 처리합니다.
|
|
// DOM.applyFilterBtn.addEventListener('click', ...);
|
|
}
|
|
|
|
/**
|
|
* 페이지 초기화 함수
|
|
*/
|
|
async function initialize() {
|
|
setDefaultDates();
|
|
setupEventListeners();
|
|
|
|
try {
|
|
const masterData = await getMasterData();
|
|
updateFilterOptions(masterData);
|
|
await handleAnalysis();
|
|
} catch (error) {
|
|
alert(error.message);
|
|
setUIState('error');
|
|
}
|
|
}
|
|
|
|
// 초기화 실행
|
|
document.addEventListener('DOMContentLoaded', initialize); |