- 공통 유틸리티 추출 (common/utils.js, common/base-state.js) - TBM 모바일 인라인 JS/CSS 외부 파일로 분리 (tbm-mobile.js, tbm-mobile.css) - 미사용 코드 삭제 (index.js, work-report-*.js 등 5개 파일) - TBM/작업보고 state.js, utils.js를 공통 모듈 기반으로 전환 - 작업보고서 SSO 인증 호환 수정 (token/user 함수) - tbmModel.js: incomplete-reports 쿼리에서 users→sso_users 조인 수정, leader_name 조인 추가 - docker-compose.yml: system1-web 볼륨 마운트 추가 - 모바일 인계(handover) 기능 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
128 lines
3.5 KiB
JavaScript
128 lines
3.5 KiB
JavaScript
/**
|
|
* TBM - Utilities
|
|
* TBM 관련 유틸리티 함수들 (공통 함수는 CommonUtils에 위임)
|
|
*/
|
|
|
|
class TbmUtils {
|
|
constructor() {
|
|
this._common = window.CommonUtils;
|
|
console.log('[TbmUtils] 초기화 완료');
|
|
}
|
|
|
|
// --- CommonUtils 위임 ---
|
|
getTodayKST() { return this._common.getTodayKST(); }
|
|
formatDate(dateString) { return this._common.formatDate(dateString); }
|
|
getDayOfWeek(dateString) { return this._common.getDayOfWeek(dateString); }
|
|
isToday(dateString) { return this._common.isToday(dateString); }
|
|
generateUUID() { return this._common.generateUUID(); }
|
|
escapeHtml(text) { return this._common.escapeHtml(text); }
|
|
|
|
// --- TBM 전용 ---
|
|
|
|
/**
|
|
* 날짜 표시용 포맷 (MM월 DD일)
|
|
*/
|
|
formatDateDisplay(dateString) {
|
|
if (!dateString) return '';
|
|
const [year, month, day] = dateString.split('-');
|
|
return `${parseInt(month)}월 ${parseInt(day)}일`;
|
|
}
|
|
|
|
/**
|
|
* 날짜를 연/월/일/요일 형식으로 포맷
|
|
*/
|
|
formatDateFull(dateString) {
|
|
if (!dateString) return '';
|
|
const [year, month, day] = dateString.split('-');
|
|
const dayName = this._common.getDayOfWeek(dateString);
|
|
return `${year}년 ${parseInt(month)}월 ${parseInt(day)}일 (${dayName})`;
|
|
}
|
|
|
|
/**
|
|
* 현재 시간을 HH:MM 형식으로 반환
|
|
*/
|
|
getCurrentTime() {
|
|
return new Date().toTimeString().slice(0, 5);
|
|
}
|
|
|
|
/**
|
|
* 날씨 조건명 반환
|
|
*/
|
|
getWeatherConditionName(code) {
|
|
const names = {
|
|
clear: '맑음', rain: '비', snow: '눈', heat: '폭염',
|
|
cold: '한파', wind: '강풍', fog: '안개', dust: '미세먼지'
|
|
};
|
|
return names[code] || code;
|
|
}
|
|
|
|
/**
|
|
* 날씨 아이콘 반환
|
|
*/
|
|
getWeatherIcon(code) {
|
|
const icons = {
|
|
clear: '☀️', rain: '🌧️', snow: '❄️', heat: '🔥',
|
|
cold: '🥶', wind: '💨', fog: '🌫️', dust: '😷'
|
|
};
|
|
return icons[code] || '🌤️';
|
|
}
|
|
|
|
/**
|
|
* 카테고리명 반환
|
|
*/
|
|
getCategoryName(category) {
|
|
const names = {
|
|
'PPE': '개인 보호 장비', 'EQUIPMENT': '장비 점검',
|
|
'ENVIRONMENT': '작업 환경', 'EMERGENCY': '비상 대응',
|
|
'WEATHER': '날씨', 'TASK': '작업'
|
|
};
|
|
return names[category] || category;
|
|
}
|
|
|
|
/**
|
|
* 상태 배지 HTML 반환
|
|
*/
|
|
getStatusBadge(status) {
|
|
const badges = {
|
|
'draft': '<span class="tbm-card-status draft">진행중</span>',
|
|
'completed': '<span class="tbm-card-status completed">완료</span>',
|
|
'cancelled': '<span class="tbm-card-status cancelled">취소</span>'
|
|
};
|
|
return badges[status] || '';
|
|
}
|
|
}
|
|
|
|
// 전역 인스턴스 생성
|
|
window.TbmUtils = new TbmUtils();
|
|
|
|
// 하위 호환성: TBM 전용 유틸 (showToast, formatDate, waitForApi, generateUUID는 api-base.js 전역)
|
|
window.getTodayKST = () => window.TbmUtils.getTodayKST();
|
|
|
|
// 카테고리별 그룹화
|
|
window.groupChecksByCategory = function(checks) {
|
|
return checks.reduce((acc, check) => {
|
|
const category = check.check_category || 'OTHER';
|
|
if (!acc[category]) acc[category] = [];
|
|
acc[category].push(check);
|
|
return acc;
|
|
}, {});
|
|
};
|
|
|
|
// 작업별 그룹화
|
|
window.groupChecksByTask = function(checks) {
|
|
return checks.reduce((acc, check) => {
|
|
const taskId = check.task_id || 0;
|
|
const taskName = check.task_name || '기타 작업';
|
|
if (!acc[taskId]) acc[taskId] = { name: taskName, items: [] };
|
|
acc[taskId].items.push(check);
|
|
return acc;
|
|
}, {});
|
|
};
|
|
|
|
// Admin 사용자 확인
|
|
window.isAdminUser = function() {
|
|
return window.TbmState?.isAdminUser() || false;
|
|
};
|
|
|
|
console.log('[Module] tbm/utils.js 로드 완료');
|