refactor: standardize modal system, unify hardware DB schemas, and implement automatic asset reclassification
This commit is contained in:
45
src/main.ts
45
src/main.ts
@@ -2,11 +2,10 @@ import { state, loadMasterDataFromDB } from './core/state';
|
||||
import { renderNavigation } from './components/Navigation';
|
||||
import { renderDashboard } from './views/DashboardView';
|
||||
import { renderTable } from './views/AssetTableView';
|
||||
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 { initStorageModal } from './components/Modal/StorageModal';
|
||||
import { initSwModal } from './components/Modal/SWModal';
|
||||
import { initSwUserModal } from './components/Modal/SWUserModal';
|
||||
import { initDashboardDetailModal } from './components/Modal/DashboardDetailModal';
|
||||
@@ -31,10 +30,22 @@ const savePcToDB = () => apiBatchSave('http://localhost:3000/api/pc/batch', stat
|
||||
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 saveSwUsersToDB = () => apiBatchSave('http://localhost:3000/api/sw-users/batch', state.masterData.swUsers, 'SW사용자');
|
||||
|
||||
// 모든 하드웨어 DB 동기화
|
||||
async function saveAllHardwareToDB() {
|
||||
await Promise.all([
|
||||
savePcToDB(),
|
||||
saveServerToDB(),
|
||||
saveStorageToDB(),
|
||||
saveEquipToDB(),
|
||||
saveMobileToDB()
|
||||
]);
|
||||
}
|
||||
|
||||
// --- App Initialization ---
|
||||
function initApp() {
|
||||
console.log('🚀 ITAM Dedicated System Initializing...');
|
||||
@@ -49,15 +60,10 @@ function initApp() {
|
||||
else renderTable(mainContent);
|
||||
});
|
||||
|
||||
// 각 모달 초기화 시 해당 카테고리의 저장 API만 호출하도록 콜백 연결
|
||||
initPcModal(() => { savePcToDB(); renderTable(mainContent); }, closeAllModals);
|
||||
initHwModal(() => {
|
||||
if (state.activeSubTab === '서버') saveServerToDB();
|
||||
else if (state.activeSubTab === '스토리지') saveStorageToDB();
|
||||
else if (state.activeSubTab === '전산비품') saveEquipToDB();
|
||||
renderTable(mainContent);
|
||||
}, closeAllModals);
|
||||
initStorageModal(() => { saveStorageToDB(); renderTable(mainContent); }, closeAllModals);
|
||||
// 하드웨어 모달은 통합 저장 로직 사용 (유형 변경 시 카테고리 이동 대응)
|
||||
initPcModal(() => { saveAllHardwareToDB(); renderTable(mainContent); }, closeAllModals);
|
||||
initHwModal(() => { saveAllHardwareToDB(); renderTable(mainContent); }, closeAllModals);
|
||||
|
||||
initSwModal(() => {
|
||||
if (state.activeSubTab === '구독SW') saveSubSwToDB();
|
||||
else savePermSwToDB();
|
||||
@@ -86,9 +92,8 @@ function initApp() {
|
||||
if (file) {
|
||||
const data = await parseExcel(file);
|
||||
state.masterData = data;
|
||||
// 엑셀 업로드 시 모든 카테고리 병렬 덮어쓰기
|
||||
await Promise.all([
|
||||
savePcToDB(), saveServerToDB(), saveStorageToDB(), saveEquipToDB(),
|
||||
saveAllHardwareToDB(),
|
||||
saveSubSwToDB(), savePermSwToDB(), saveSwUsersToDB()
|
||||
]);
|
||||
renderTable(mainContent);
|
||||
@@ -96,13 +101,13 @@ function initApp() {
|
||||
});
|
||||
|
||||
document.getElementById('btn-add-asset')?.addEventListener('click', () => {
|
||||
if (state.activeSubTab === '서버' || state.activeSubTab === '전산비품' || state.activeSubTab === '스토리지') {
|
||||
openHwModal({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: state.activeSubTab,
|
||||
법인: '한맥', 자산코드: '', 명칭: '', 위치: '', 관리자: '', IP주소: '', MACaddress: '', HW사양: '', OS: '', 납품업체: '', 품의서명: ''
|
||||
} as any);
|
||||
}
|
||||
const defaultType = state.activeSubTab === '대시보드' ? '' : state.activeSubTab;
|
||||
openHwModal({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: defaultType,
|
||||
법인: '', 자산코드: '', 명칭: '', 위치: '', 관리자: '', IP주소: '', MACaddress: '', HW사양: '', OS: '', 납품업체: '', 품의서명: '', 현사용조직: '', 이전사용조직: '',
|
||||
용도: '', 상세: '', 비고: '', storage유형: defaultType, 모델명: '', CPU: '', RAM: '', SSD1: '', SSD2: '', HDD1: '', 모니터링: ''
|
||||
} as any, 'add');
|
||||
});
|
||||
|
||||
createIcons({
|
||||
|
||||
Reference in New Issue
Block a user