Merge origin/setting into SW_Table and resolve conflicts
This commit is contained in:
103
src/main.ts
103
src/main.ts
@@ -2,15 +2,14 @@ import { state, loadMasterDataFromDB } from './core/state';
|
||||
import { renderNavigation } from './components/Navigation';
|
||||
import { renderDashboard } from './views/DashboardView';
|
||||
import { renderSWTable } from './views/SW_Table';
|
||||
import { downloadTemplate, exportToExcel, parseExcel, HardwareAsset, SoftwareAsset, SWUser } from './core/excelHandler';
|
||||
import { downloadTemplate, exportToExcel, parseExcel } from './core/excelHandler';
|
||||
import { initBaseModal } from './components/Modal/BaseModal';
|
||||
import { initPcModal } from './components/Modal/PCModal';
|
||||
import { initHwModal, openHwModal } from './components/Modal/HWModal';
|
||||
import { initSwModal, openSwModal } from './components/Modal/SWModal';
|
||||
import { initSwUserModal } from './components/Modal/SWUserModal';
|
||||
import { initDashboardDetailModal } from './components/Modal/DashboardDetailModal';
|
||||
import { initGuide } from './components/Guide';
|
||||
import { createIcons, Download, Upload, FileSpreadsheet, Plus, X, LayoutDashboard, Monitor, Server, Database, Laptop, CalendarClock, Key, Cpu, Layers, Users, Paperclip, Edit2, History, RefreshCcw, BookOpen } from 'lucide';
|
||||
import { createIcons, Download, Upload, FileSpreadsheet, Plus, X, LayoutDashboard, Monitor, Server, Database, Laptop, CalendarClock, Key, Cpu, Layers, Users, Paperclip, Edit2, History, RefreshCcw, BookOpen, Settings } from 'lucide';
|
||||
|
||||
// --- DB 저장을 위한 세분화된 헬퍼 함수들 ---
|
||||
async function apiBatchSave(url: string, data: any[], label: string) {
|
||||
@@ -31,15 +30,15 @@ async function apiBatchSave(url: string, data: any[], label: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const savePcToDB = () => apiBatchSave('http://localhost:3000/api/pc/batch', state.masterData.pc, '개인PC');
|
||||
const saveServerToDB = () => apiBatchSave('http://localhost:3000/api/server/batch', state.masterData.server, '서버');
|
||||
const saveStorageToDB = () => apiBatchSave('http://localhost:3000/api/storage/batch', state.masterData.storage, '스토리지');
|
||||
const saveEquipToDB = () => apiBatchSave('http://localhost:3000/api/equip/batch', state.masterData.equip, '전산비품');
|
||||
const saveMobileToDB = () => apiBatchSave('http://localhost:3000/api/mobile/batch', state.masterData.mobile, '모바일기기');
|
||||
const saveSubSwToDB = () => apiBatchSave('http://localhost:3000/api/sw/sub/batch', state.masterData.subSw, '구독SW');
|
||||
const savePermSwToDB = () => apiBatchSave('http://localhost:3000/api/sw/perm/batch', state.masterData.permSw, '영구SW');
|
||||
const saveCloudToDB = () => apiBatchSave('http://localhost:3000/api/cloud/batch', state.masterData.cloud, '클라우드');
|
||||
const saveSwUsersToDB = () => apiBatchSave('http://localhost:3000/api/sw-users/batch', state.masterData.swUsers, 'SW사용자');
|
||||
const savePcToDB = () => apiBatchSave('http://172.16.40.100:3000/api/pc/batch', state.masterData.pc, '개인PC');
|
||||
const saveServerToDB = () => apiBatchSave('http://172.16.40.100:3000/api/server/batch', state.masterData.server, '서버');
|
||||
const saveStorageToDB = () => apiBatchSave('http://172.16.40.100:3000/api/storage/batch', state.masterData.storage, '스토리지');
|
||||
const saveEquipToDB = () => apiBatchSave('http://172.16.40.100:3000/api/equip/batch', state.masterData.equip, '전산비품');
|
||||
const saveMobileToDB = () => apiBatchSave('http://172.16.40.100:3000/api/mobile/batch', state.masterData.mobile, '모바일기기');
|
||||
const saveSubSwToDB = () => apiBatchSave('http://172.16.40.100:3000/api/sw/sub/batch', state.masterData.subSw, '구독SW');
|
||||
const savePermSwToDB = () => apiBatchSave('http://172.16.40.100:3000/api/sw/perm/batch', state.masterData.permSw, '영구SW');
|
||||
const saveCloudToDB = () => apiBatchSave('http://172.16.40.100:3000/api/cloud/batch', state.masterData.cloud, '클라우드');
|
||||
const saveSwUsersToDB = () => apiBatchSave('http://172.16.40.100:3000/api/sw-users/batch', state.masterData.swUsers, 'SW사용자');
|
||||
|
||||
// 화면 갱신 통합 핸들러 (대시보드 vs 리스트)
|
||||
function refreshView() {
|
||||
@@ -53,19 +52,6 @@ function refreshView() {
|
||||
}
|
||||
}
|
||||
|
||||
// 모든 소프트웨어 DB 동기화
|
||||
async function saveAllSoftwareToDB() {
|
||||
await Promise.all([
|
||||
saveSubSwToDB(),
|
||||
savePermSwToDB(),
|
||||
saveCloudToDB(),
|
||||
saveSwUsersToDB()
|
||||
]);
|
||||
// 저장 후 최신 데이터 다시 로드 (정합성)
|
||||
await loadMasterDataFromDB();
|
||||
refreshView();
|
||||
}
|
||||
|
||||
// 모든 하드웨어 DB 동기화
|
||||
async function saveAllHardwareToDB() {
|
||||
await Promise.all([
|
||||
@@ -79,15 +65,28 @@ async function saveAllHardwareToDB() {
|
||||
refreshView();
|
||||
}
|
||||
|
||||
// 모든 소프트웨어 DB 동기화
|
||||
async function saveAllSoftwareToDB() {
|
||||
await Promise.all([
|
||||
saveSubSwToDB(),
|
||||
savePermSwToDB(),
|
||||
saveCloudToDB(),
|
||||
saveSwUsersToDB()
|
||||
]);
|
||||
// 저장 후 최신 데이터 다시 로드 (정합성)
|
||||
await loadMasterDataFromDB();
|
||||
refreshView();
|
||||
}
|
||||
|
||||
// --- App Initialization ---
|
||||
function initApp() {
|
||||
console.log('🚀 ITAM Dedicated System Initializing...');
|
||||
const mainContent = document.getElementById('main-content')!;
|
||||
if (!mainContent) return;
|
||||
|
||||
const { closeAllModals } = initBaseModal();
|
||||
|
||||
|
||||
try {
|
||||
// 네비게이션 렌더링 및 콜백 연결
|
||||
renderNavigation((tab) => {
|
||||
if (tab === '대시보드') {
|
||||
renderDashboard(mainContent);
|
||||
@@ -96,10 +95,8 @@ function initApp() {
|
||||
}
|
||||
});
|
||||
|
||||
// 모달 초기화
|
||||
initPcModal(() => saveAllHardwareToDB(), closeAllModals);
|
||||
// 각종 모달 및 가이드 초기화
|
||||
initHwModal(() => saveAllHardwareToDB(), closeAllModals);
|
||||
|
||||
initSwModal(() => saveAllSoftwareToDB(), closeAllModals);
|
||||
|
||||
initSwUserModal(() => {
|
||||
@@ -110,19 +107,15 @@ function initApp() {
|
||||
|
||||
initDashboardDetailModal();
|
||||
initGuide();
|
||||
|
||||
// DB 데이터 로드 및 초기 화면 렌더링
|
||||
loadMasterDataFromDB().then((success) => {
|
||||
if (success) {
|
||||
refreshView();
|
||||
}
|
||||
});
|
||||
} catch (e) { console.error('❌ Initialization failed:', e); }
|
||||
|
||||
// 초기 로드 시 대시보드 렌더링
|
||||
renderDashboard(mainContent);
|
||||
|
||||
// DB에서 데이터 로드 후 화면 갱신
|
||||
loadMasterDataFromDB().then((success) => {
|
||||
if (success) {
|
||||
if (state.activeSubTab === '대시보드') renderDashboard(mainContent);
|
||||
else renderSWTable(mainContent);
|
||||
}
|
||||
});
|
||||
|
||||
// 버튼 이벤트 바인딩
|
||||
document.getElementById('btn-download-template')?.addEventListener('click', () => downloadTemplate());
|
||||
document.getElementById('btn-export-excel')?.addEventListener('click', () => exportToExcel(state.masterData));
|
||||
@@ -133,40 +126,24 @@ function initApp() {
|
||||
if (file) {
|
||||
const data = await parseExcel(file);
|
||||
state.masterData = data;
|
||||
await Promise.all([
|
||||
saveAllHardwareToDB(),
|
||||
saveAllSoftwareToDB()
|
||||
]);
|
||||
renderSWTable(mainContent);
|
||||
await Promise.all([saveAllHardwareToDB(), saveAllSoftwareToDB()]);
|
||||
handleTabChange(state.activeSubTab);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('btn-add-asset')?.addEventListener('click', () => {
|
||||
const tab = state.activeSubTab;
|
||||
const cat = state.activeCategory;
|
||||
|
||||
if (cat === 'hw') {
|
||||
// 하드웨어 대시보드 또는 개별 탭에서 추가
|
||||
const defaultType = (tab === '대시보드') ? '' : tab;
|
||||
openHwModal({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: defaultType,
|
||||
법인: '한맥', 자산코드: '', 명칭: '', 설치위치: '', MACaddress: '', HW사양: '', OS: '', 연락처: '', 담당부서: ''
|
||||
} as any, 'add');
|
||||
let defaultType = (tab === '개인PC') ? 'PC' : (tab === '서버' ? '서버' : (tab === '스토리지' ? '스토리지' : (tab === '전산비품' ? 'CPU' : '모바일')));
|
||||
openHwModal({ id: Math.random().toString(36).substring(2, 9), type: defaultType, 법인: '한맥', 자산코드: '', 명칭: '', 설치위치: '', MACaddress: '', HW사양: '', OS: '', 연락처: '', 담당부서: '' } as any, 'add');
|
||||
} else if (cat === 'sw') {
|
||||
// 소프트웨어 대시보드 또는 개별 탭에서 추가
|
||||
let defaultType = tab;
|
||||
if (tab === '대시보드') defaultType = '구독SW'; // SW는 기본 레이아웃을 위해 하나 지정하되 필드는 빈값
|
||||
|
||||
openSwModal({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: defaultType, 제품명: '', 금액: '', 수량: 1, 계정명: '', 납품업체: '', 비고: '', 법인: '한맥'
|
||||
} as any, 'add');
|
||||
openSwModal({ id: Math.random().toString(36).substring(2, 9), type: tab === '대시보드' ? '구독SW' : tab, 제품명: '', 금액: '', 수량: 1, 계정명: '', 납품업체: '', 비고: '', 법인: '한맥' } as any, 'add');
|
||||
}
|
||||
});
|
||||
|
||||
createIcons({
|
||||
icons: { Download, Upload, FileSpreadsheet, Plus, X, LayoutDashboard, Monitor, Server, Database, Laptop, CalendarClock, Key, Cpu, Layers, Users, Paperclip, Edit2, History, RefreshCcw, BookOpen }
|
||||
icons: { Download, Upload, FileSpreadsheet, Plus, X, LayoutDashboard, Monitor, Server, Database, Laptop, CalendarClock, Key, Cpu, Layers, Users, Paperclip, Edit2, History, RefreshCcw, BookOpen, Settings }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user