Fix merge conflicts in HWModal.ts and restore optimized structure

This commit is contained in:
2026-04-23 10:21:08 +09:00
parent 809f3fcf3b
commit e147b1a191

View File

@@ -19,23 +19,23 @@ import {
let currentAsset: HardwareAsset | null = null;
let isEditMode = false;
const STATUS_LIST = ['대여중', '보관중', '수리중', '기타'];
const STATUS_LIST = ['사용중', '보관중', '수리중', '폐기예정', '기타'];
// 필드 ID ↔ 데이터 Key 매핑 (유지보수 시 이 부분만 수정)
// 필드 ID ↔ 데이터 Key 매핑
const HW_FIELD_MAP: Record<string, string> = {
'유형': 'type',
'법인': '법인',
'자산코드': '자산코드',
'현사용조직': '사용조직',
'현사용조직': '사용조직',
'이전사용조직': '이전사용조직',
'상세용도': '상세용도',
'상세용도': '서버용도',
'모델명': '모델명',
'명칭': '명칭',
'보관위치': '보관위치',
'현재상태': '현재상태',
'현재상태': '상태',
'IP주소': 'IP주소',
'IP2': 'IP2',
'원격접속': '원격접속',
'원격접속': '원격방법',
'서버ID': '서버ID',
'서버PW': '서버PW',
'모니터링': '모니터링',
@@ -45,16 +45,14 @@ const HW_FIELD_MAP: Record<string, string> = {
'SSD1': 'SSD1',
'SSD2': 'SSD2',
'HW사양': 'HW사양',
'담당자_정': '담당자_정',
'담당자_부': '담당자_부',
'구매일': '구매연월',
'금액': '금액',
'담당자_정': '관리조직',
'구매일': '도입일',
'금액': '구매',
'비고': '비고',
'사용자': '사용자'
};
const HW_FORM_HTML = `
<!-- Group 1: 기본 정보 -->
<div class="form-section-title">기본 정보 (Identity)</div>
<div class="form-group">
<label for="hw-법인">구매법인</label>
@@ -72,7 +70,7 @@ const HW_FORM_HTML = `
<input type="text" id="hw-사용자" />
</div>
<div class="form-group">
<label for="hw-현사용조직">사용조직</label>
<label for="hw-현사용조직">사용조직</label>
<select id="hw-현사용조직">${generateOptionsHTML(ORG_LIST)}</select>
</div>
<div class="form-group" id="hw-이전사용조직-group">
@@ -80,15 +78,17 @@ const HW_FORM_HTML = `
<input type="text" id="hw-이전사용조직" readonly />
</div>
<div class="form-group" id="hw-유형-group">
<label for="hw-유형">유형</label>
<label for="hw-유형">자산구분</label>
<select id="hw-유형">${generateOptionsHTML(HW_TYPE_LIST)}</select>
</div>
<div class="form-group" id="hw-상세용도-group">
<label for="hw-상세용도">상세유형</label>
<div class="form-group" id="hw-상세용도-group" style="display:none;">
<label for="hw-상세용도">서버용도</label>
<select id="hw-상세용도">
<option value="">선택</option>
<option value="서버">서버</option>
<option value="개인PC">개인PC</option>
<option value="">선택하세요</option>
<option value="DB서버">DB 서버</option>
<option value="웹서버">웹 서버</option>
<option value="어플리케이션">어플리케이션</option>
<option value="가상화">가상화 호스트</option>
</select>
</div>
@@ -105,40 +105,31 @@ const HW_FORM_HTML = `
<div class="form-section-title server-only" id="hw-network-title">네트워크 정보 (Connectivity)</div>
<div class="form-group server-only" id="hw-ip-group"><label for="hw-IP주소">IP 주소 1</label><input type="text" id="hw-IP주소" /></div>
<div class="form-group server-only" id="hw-ip2-group"><label for="hw-IP2">IP 주소 2</label><input type="text" id="hw-IP2" /></div>
<div class="form-group server-only" id="hw-remote-group"><label for="hw-원격접속">원격 도구</label><input type="text" id="hw-원격접속" /></div>
<div class="form-group server-only" id="hw-remote-group"><label for="hw-원격접속">원격 방법</label><input type="text" id="hw-원격접속" /></div>
<div class="form-group server-only" id="hw-server-id-group"><label for="hw-서버ID">서버 ID</label><input type="text" id="hw-서버ID" /></div>
<div class="form-group server-only" id="hw-server-pw-group"><label for="hw-서버PW">서버 PW</label><input type="text" id="hw-서버PW" /></div>
<div class="form-group server-only" id="hw-server-pw-group"><label for="hw-서버PW">서버 PW</label><input type="password" id="hw-서버PW" /></div>
<div class="form-group non-server" id="hw-ip-non-server-group"><label for="hw-IP주소-non-server">IP 주소</label><input type="text" id="hw-IP주소-non-server" /></div>
<div class="form-section-title" id="hw-spec-title">시스템 사양 (Specifications)</div>
<div class="form-section-title" id="hw-spec-title">하드웨어 사양 (Specifications)</div>
<div class="form-group" id="hw-model-group"><label for="hw-모델명">모델명</label><input type="text" id="hw-모델명" /></div>
<div class="form-group" id="hw-os-group"><label for="hw-OS">운영체제 (OS)</label><input type="text" id="hw-OS" /></div>
<div class="form-group" id="hw-cpu-group"><label for="hw-CPU">CPU 사양</label><input type="text" id="hw-CPU" /></div>
<div class="form-group" id="hw-ram-group"><label for="hw-RAM">RAM 용량</label><input type="text" id="hw-RAM" /></div>
<div class="form-group" id="hw-ssd1-group"><label for="hw-SSD1">Storage 1 (SSD/HDD)</label><input type="text" id="hw-SSD1" /></div>
<div class="form-group" id="hw-ssd2-group"><label for="hw-SSD2">Storage 2 (SSD/HDD)</label><input type="text" id="hw-SSD2" /></div>
<div class="form-group server-only" id="hw-monitoring-group"><label for="hw-모니터링">모니터링 여부</label><input type="text" id="hw-모니터링" /></div>
<div class="form-group server-only" id="hw-monitoring-group"><label for="hw-모니터링">모니터링 유무</label><input type="text" id="hw-모니터링" /></div>
<div class="form-group full-width non-server" id="hw-hwspec-group"><label for="hw-HW사양">사양 상세</label><textarea id="hw-HW사양" rows="2"></textarea></div>
<div class="form-section-title" id="hw-loc-title">설치 위치 및 관리</div>
<div class="form-group loc-standard"><label for="hw-위치-빌딩">설치위치 (건물)</label><select id="hw-위치-빌딩">${generateOptionsHTML(Object.keys(LOCATION_DATA))}</select></div>
<div class="form-group loc-standard"><label for="hw-위치-상세">세 위치</label><select id="hw-위치-상세"><option value="">선택</option></select></div>
<div class="form-group loc-standard"><label for="hw-위치-빌딩">설치장소 (대분류)</label><select id="hw-위치-빌딩">${generateOptionsHTML(Object.keys(LOCATION_DATA))}</select></div>
<div class="form-group loc-standard"><label for="hw-위치-상세">세부 설치 위치</label><select id="hw-위치-상세"><option value="">선택</option></select></div>
<div class="form-group" id="hw-위치-기타-group" style="display:none;"><label for="hw-위치-기타">직접 입력 (기타)</label><input type="text" id="hw-위치-기타" /></div>
<div class="form-group"><label for="hw-담당자_정">담당자(정)</label><input type="text" id="hw-담당자_정" /></div>
<div class="form-group"><label for="hw-담당자_부">담당자(부)</label><input type="text" id="hw-담당자_부" /></div>
<div class="form-group"><label for="hw-구매일">구매연월</label><input type="text" id="hw-구매일" placeholder="YYYYMM" maxlength="6" /></div>
<div class="form-group"><label for="hw-금액">금액</label><input type="text" id="hw-금액" oninput="this.value=this.value.replace(/[^0-9]/g,'').replace(/\\\\B(?=(\\\\d{3})+(?!\\\\d))/g,',')" /></div>
<div class="form-group"><label for="hw-담당자_정">자산관리조직</label><input type="text" id="hw-담당자_정" readonly /></div>
<div class="form-group"><label for="hw-구매일">도입일</label><input type="text" id="hw-구매일" /></div>
<div class="form-group"><label for="hw-금액">구매</label><input type="text" id="hw-금액" oninput="this.value=this.value.replace(/[^0-9]/g,'').replace(/\\\\B(?=(\\\\d{3})+(?!\\\\d))/g,',')" /></div>
<div class="form-group full-width"><label for="hw-비고">비고</label><textarea id="hw-비고" rows="2"></textarea></div>
<div class="form-group full-width">
<label>품의서 (파일 증빙)</label>
<div style="display:flex; align-items:center; gap:0.5rem;">
<input type="file" id="hw-품의서" />
<span id="hw-품의서명" style="font-size:0.75rem; color:var(--text-light)"></span>
</div>
</div>
`;
<<<<<<< HEAD
function renderHwHistory(assetId: string) {
const container = document.getElementById('hw-history-list');
if (!container) return;
@@ -151,27 +142,6 @@ function renderHwHistory(assetId: string) {
<div class="history-details">${l.details.replace(/\n/g, '<br>')}</div>
</div>
`).join('');
=======
export function openHwModal(asset: HardwareAsset, mode: 'view' | 'add' | 'edit' = 'view') {
currentAsset = asset;
const modal = document.getElementById('hw-asset-modal')!;
// 1. 잠금 상태 통합 제어 (데이터 유무가 아닌 호출 mode에만 의존)
setEditLock('hw-asset-form', mode, {
saveBtnId: 'btn-save-hw-asset',
revertBtnId: 'btn-revert-hw-edit',
generateBtnId: 'btn-generate-hw-code'
});
isEditMode = (mode === 'add' || mode === 'edit');
// 2. 데이터 바인딩
fillHwFormData(asset);
modal.classList.remove('hidden');
applyTypeSpecificUI(asset.type);
createIcons({ icons: { Paperclip } });
>>>>>>> origin/SW_Table
}
function applyTypeSpecificUI(type: string) {
@@ -199,68 +169,39 @@ function applyTypeSpecificUI(type: string) {
const opOnly = document.querySelectorAll('.op-only');
const standardLoc = document.querySelectorAll('.loc-standard');
// 초기화
serverOnly.forEach(el => (el as HTMLElement).style.display = 'none');
nonServer.forEach(el => (el as HTMLElement).style.display = 'none');
opOnly.forEach(el => (el as HTMLElement).style.display = 'none');
standardLoc.forEach(el => (el as HTMLElement).style.display = 'flex');
Object.values(groups).forEach(g => { if (g) g.style.display = 'none'; });
const osLabel = document.querySelector('label[for="hw-OS"]') as HTMLElement;
const ramLabel = document.querySelector('label[for="hw-RAM"]') as HTMLElement;
const modelLabel = document.querySelector('label[for="hw-모델명"]') as HTMLElement;
if (osLabel) osLabel.innerText = '운영체제 (OS)';
if (ramLabel) ramLabel.innerText = 'RAM 용량';
if (modelLabel) modelLabel.innerText = '모델명';
const isServer = upperType.includes('서버') || upperType.includes('SERVER');
const isMobileGroup = ['모바일', '태블릿', '휴대폰'].some(t => upperType.includes(t));
const isEquipGroup = ['CPU', 'RAM', 'HDD', 'GPU'].some(t => upperType.includes(t)) || upperType.includes('비품');
const isOpType = isMobileGroup || isEquipGroup;
const isPcType = upperType === 'PC' || upperType === '개인PC' || upperType === '노트북';
if (groups.opTitle) groups.opTitle.style.display = isOpType ? 'flex' : 'none';
if (isOpType) {
if (isServer) {
serverOnly.forEach(el => (el as HTMLElement).style.display = 'flex');
if (groups.detailPurpose) groups.detailPurpose.style.display = 'flex';
if (groups.networkTitle) groups.networkTitle.style.display = 'flex';
if (groups.specTitle) groups.specTitle.style.display = 'flex';
['model', 'os', 'cpu', 'ram', 'ssd1', 'ssd2', 'monitoring'].forEach(k => { if (groups[k]) groups[k]!.style.display = 'flex'; });
} else if (isPcType) {
if (groups.user) groups.user.style.display = 'flex';
if (groups.specTitle) groups.specTitle.style.display = 'flex';
nonServer.forEach(el => (el as HTMLElement).style.display = 'flex');
['model', 'os', 'cpu', 'ram', 'ssd1', 'ssd2', 'hwSpec'].forEach(k => { if (groups[k]) groups[k]!.style.display = 'flex'; });
} else if (isOpType) {
opOnly.forEach(el => (el as HTMLElement).style.display = 'flex');
standardLoc.forEach(el => (el as HTMLElement).style.display = 'none');
if (groups.specTitle) groups.specTitle.style.display = 'flex';
if (groups.model) groups.model.style.display = 'flex';
if (['CPU', 'GPU'].some(t => upperType.includes(t))) {
if (groups.os && osLabel) { osLabel.innerText = '출시연월'; groups.os.style.display = 'flex'; }
} else if (['RAM', 'HDD'].some(t => upperType.includes(t))) {
if (groups.ram && ramLabel) { ramLabel.innerText = '용량'; groups.ram.style.display = 'flex'; }
if (upperType.includes('HDD') && modelLabel) modelLabel.innerText = 'S/N';
} else {
if (groups.hwSpec) groups.hwSpec.style.display = 'flex';
}
}
else if (isPcType) {
if (groups.user) groups.user.style.display = 'flex';
if (groups.hwSpec) groups.hwSpec.style.display = 'flex';
} else {
nonServer.forEach(el => (el as HTMLElement).style.display = 'flex');
if (groups.specTitle) groups.specTitle.style.display = 'flex';
// 노트북은 상세유형 선택창 숨김
if (upperType === '노트북') {
if (groups.detailPurpose) groups.detailPurpose.style.display = 'none';
nonServer.forEach(el => (el as HTMLElement).style.display = 'flex');
['model', 'os', 'cpu', 'ram', 'ssd1', 'ssd2', 'hwSpec'].forEach(k => { if (groups[k]) groups[k]!.style.display = 'flex'; });
} else {
if (groups.detailPurpose) groups.detailPurpose.style.display = 'flex';
if (detailPurpose === '서버') {
serverOnly.forEach(el => (el as HTMLElement).style.display = 'flex');
if (groups.networkTitle) groups.networkTitle.style.display = 'flex';
['model', 'os', 'cpu', 'ram', 'ssd1', 'ssd2', 'monitoring'].forEach(k => { if (groups[k]) groups[k]!.style.display = 'flex'; });
} else {
nonServer.forEach(el => (el as HTMLElement).style.display = 'flex');
['model', 'os', 'cpu', 'ram', 'ssd1', 'ssd2', 'hwSpec'].forEach(k => { if (groups[k]) groups[k]!.style.display = 'flex'; });
}
}
}
else {
serverOnly.forEach(el => (el as HTMLElement).style.display = 'flex');
if (groups.networkTitle) groups.networkTitle.style.display = 'flex';
if (groups.specTitle) groups.specTitle.style.display = 'flex';
['model', 'os', 'cpu', 'ram', 'ssd1', 'ssd2', 'monitoring'].forEach(k => { if (groups[k]) groups[k]!.style.display = 'flex'; });
['model', 'os', 'cpu', 'ram', 'ssd1', 'ssd2', 'hwSpec'].forEach(k => { if (groups[k]) groups[k]!.style.display = 'flex'; });
}
}
@@ -276,12 +217,7 @@ export function openHwModal(asset: HardwareAsset, mode: 'view' | 'add' = 'view')
});
isEditMode = (mode === 'add');
// 데이터 채우기 (자동 매핑)
autoFillForm('hw', asset, HW_FIELD_MAP);
setFieldValue('hw-명칭', asset. || asset.);
if (!asset. && asset.) setFieldValue('hw-구매일', asset.);
parseAndSetLocation(asset., 'hw-위치-빌딩', 'hw-위치-상세', 'hw-위치-기타-group', 'hw-위치-기타');
applyTypeSpecificUI(asset.type);
renderHwHistory(asset.id);
@@ -293,12 +229,11 @@ export function openHwModal(asset: HardwareAsset, mode: 'view' | 'add' = 'view')
export function initHwModal(onSave: () => void, closeModalsCb: () => void) {
if (!document.getElementById('hw-asset-modal')) {
const html = createModalFrameHTML('hw', '자산 상세 정보', HW_FORM_HTML, {
historyTitle: '분출 및 변경 이력',
historyTitle: '유지보수 및 변경 이력',
addLogBtnId: 'btn-add-hw-log'
});
document.body.insertAdjacentHTML('beforeend', html);
// 이력 추가 모달 HTML도 함께 추가
const logModalHTML = `
<div id="hw-log-modal" class="modal-overlay hidden" style="z-index: 1100;">
<div class="modal-content" style="max-width: 400px;">
@@ -306,7 +241,7 @@ export function initHwModal(onSave: () => void, closeModalsCb: () => void) {
<div class="modal-body">
<div class="grid-form" style="grid-template-columns: 1fr;">
<div class="form-group"><label>날짜</label><input type="date" id="new-hw-log-date" /></div>
<div class="form-group"><label>변경/분출 내용</label><textarea id="new-hw-log-details" rows="3" placeholder="예: [분출] 기술팀 홍길동, [수리] 배터리 교체 등"></textarea></div>
<div class="form-group"><label>내용</label><textarea id="new-hw-log-details" rows="3" placeholder="예: [유지보수] 먼지 제거, [부품교체] 배터리 교체 등"></textarea></div>
</div>
</div>
<div class="modal-footer"><div></div><div class="footer-actions"><button id="btn-cancel-hw-log" class="btn btn-outline">취소</button><button id="btn-confirm-hw-log" class="btn btn-primary">추가</button></div></div>
@@ -316,7 +251,6 @@ export function initHwModal(onSave: () => void, closeModalsCb: () => void) {
document.body.insertAdjacentHTML('beforeend', logModalHTML);
}
const form = document.getElementById('hw-asset-form') as HTMLFormElement;
const saveBtn = document.getElementById('btn-save-hw-asset')!;
const revertBtn = document.getElementById('btn-revert-hw-edit')!;
const deleteBtn = document.getElementById('btn-delete-hw-asset')!;
@@ -351,7 +285,7 @@ export function initHwModal(onSave: () => void, closeModalsCb: () => void) {
const purchaseDate = getFieldValue('hw-구매일');
const typeCode = TYPE_PREFIX_MAP[typeValue] || 'ETC';
const dateStr = purchaseDate.replace(/[^0-9]/g, '');
if (dateStr.length < 6) { alert('올바른 구매연월(YYYYMM)을 입력해주세요.'); return; }
if (dateStr.length < 6) { alert('올바른 도입일(YYYYMM)을 입력해주세요.'); return; }
const prefix = `${typeCode}-${dateStr.substring(0, 6)}-`;
try {
const res = await fetch(`http://localhost:3000/api/generate-asset-code?prefix=${prefix}`);
@@ -360,19 +294,6 @@ export function initHwModal(onSave: () => void, closeModalsCb: () => void) {
} catch (err) { alert('자산번호 생성에 실패했습니다.'); }
});
// YYYYMM 입력 제한 로직 (숫자 6자리)
['hw-구매일', 'hw-OS'].forEach(id => {
const el = document.getElementById(id) as HTMLInputElement;
el?.addEventListener('input', (e) => {
const target = e.target as HTMLInputElement;
const label = document.querySelector(`label[for="${id}"]`) as HTMLElement;
// OS 필드의 경우 라벨이 '출시연월'일 때만 숫자 제한 적용
if (id === 'hw-OS' && label?.innerText !== '출시연월') return;
target.value = target.value.replace(/[^0-9]/g, '').substring(0, 6);
});
});
saveBtn.addEventListener('click', () => {
if (!currentAsset) return;
if (!isEditMode) {
@@ -387,94 +308,52 @@ export function initHwModal(onSave: () => void, closeModalsCb: () => void) {
return;
}
// 데이터 추출 (자동 매핑)
const extracted = autoExtractForm('hw', HW_FIELD_MAP);
if (!extracted.) {
alert('자산번호가 없습니다. [생성] 버튼을 눌러 자산번호를 먼저 부여해주세요.');
alert('자산번호가 없습니다. [생성] 버튼을 눌러 자산번호를 부여해주세요.');
return;
}
const upperType = (extracted.type || '').toUpperCase();
const isOpType = ['CPU', 'RAM', 'HDD', 'GPU'].some(t => upperType.includes(t)) || upperType.includes('비품') || ['모바일', '태블릿', '휴대폰'].some(t => upperType.includes(t));
const diffLogs: string[] = [];
const compareFields = [
{ key: '실사용조직', label: '실사용조직' },
{ key: '위치', label: '위치' },
{ key: '상태', label: '상태' },
{ key: 'IP주소', label: 'IP' }
];
// --- 자동 변경 이력 생성 로직 ---
// 모든 하드웨어 유형에 대해 자동 로깅 적용
if (HW_TYPE_LIST.includes(extracted.type) || extracted.type === '개인PC') {
const diffLogs: string[] = [];
const compareFields = [
{ key: '현사용조직', label: '현사용조직' },
{ key: '위치', label: '설치위치' },
{ key: '관리자', label: '담당자' },
{ key: '현재상태', label: '상태' },
{ key: 'IP주소', label: 'IP' },
{ key: '상세용도', label: '상세유형' },
{ key: '모델명', label: '모델명' }
];
const currentLocation = currentAsset. || '';
const newLocation = getCombinedLocation('hw-위치-빌딩', 'hw-위치-상세', 'hw-위치-기타');
const currentIp = currentAsset.IP주소 || '';
const newIp = getFieldValue('hw-IP주소') || getFieldValue('hw-IP주소-non-server');
const currentLocation = currentAsset. || '';
const newLocation = isOpType ? extracted.보관위치 : getCombinedLocation('hw-위치-빌딩', 'hw-위치-상세', 'hw-위치-기타');
compareFields.forEach(f => {
let oldVal = (currentAsset as any)[f.key] || '';
let newVal = (extracted as any)[f.key] || '';
if (f.key === '위치') { oldVal = currentLocation; newVal = newLocation; }
if (f.key === 'IP주소') { newVal = getFieldValue('hw-IP주소') || getFieldValue('hw-IP주소-non-server'); }
compareFields.forEach(f => {
let oldVal = '';
let newVal = '';
if (f.key === 'IP주소') {
oldVal = currentIp;
newVal = newIp;
} else if (f.key === '위치') {
oldVal = currentLocation;
newVal = newLocation;
} else if (f.key === '관리자') {
oldVal = currentAsset._정 || '';
newVal = extracted._정 || '';
} else if (f.key === '상세용도') {
oldVal = currentAsset. || '';
// 비 PC 자산은 유형을 상세유형으로 간주
newVal = (extracted.type !== 'PC' && extracted.type !== '개인PC') ? extracted.type : (extracted. || '');
} else {
oldVal = (currentAsset as any)[f.key] || '';
newVal = extracted[f.key] || '';
}
if (oldVal !== newVal) {
diffLogs.push(`${f.label}: ${oldVal || '(없음)'}${newVal || '(없음)'}`);
}
});
if (diffLogs.length > 0) {
state.masterData.logs = state.masterData.logs || [];
state.masterData.logs.push({
id: Math.random().toString(36).substring(2, 9),
assetId: currentAsset.id,
date: new Date().toISOString().split('T')[0],
user: '관리자',
details: diffLogs.join('\n')
});
if (oldVal !== newVal) {
diffLogs.push(`${f.label}: ${oldVal || '(없음)'}${newVal || '(없음)'}`);
}
});
if (diffLogs.length > 0) {
state.masterData.logs = state.masterData.logs || [];
state.masterData.logs.push({
id: Math.random().toString(36).substring(2, 9),
assetId: currentAsset.id,
date: new Date().toISOString().split('T')[0],
user: '관리자',
details: diffLogs.join('\n')
});
}
// ----------------------------
const updated: any = {
...currentAsset,
...extracted,
IP주소: getFieldValue('hw-IP주소') || getFieldValue('hw-IP주소-non-server'),
관리자: extracted.담당자_정,
위치: isOpType ? extracted.보관위치 : getCombinedLocation('hw-위치-빌딩', 'hw-위치-상세', 'hw-위치-기타')
위치: newLocation
};
// 현 사용조직 변경 시 이전 사용조직 자동 업데이트
if (currentAsset. && currentAsset. !== extracted.) {
updated. = currentAsset.;
}
// 비 PC 자산에 대해 상세유형(상세용도)을 유형과 동기화
if (updated.type !== 'PC') {
updated. = updated.type;
}
saveHardwareAsset(updated);
onSave();
setEditLock('hw-asset-form', 'view', {