feat: implement unified schema mapper, enhance UI/UX with responsive design, and optimize asset log logic
This commit is contained in:
@@ -2,8 +2,9 @@ import { state } from '../../core/state';
|
||||
import { SoftwareAsset } from '../../core/excelHandler';
|
||||
import { closeModals } from './BaseModal';
|
||||
import { openSwUserModal } from './SWUserModal';
|
||||
import { ASSET_SCHEMA, UI_TEXT } from '../../core/schema';
|
||||
import { createIcons, History, Plus, X, Save, Edit2, RotateCcw } from 'lucide';
|
||||
import { CORP_LIST, TYPE_PREFIX_MAP } from './SharedData';
|
||||
import { CORP_LIST } from './SharedData';
|
||||
import {
|
||||
generateOptionsHTML,
|
||||
setFieldValue,
|
||||
@@ -17,67 +18,63 @@ import {
|
||||
let currentSwAsset: SoftwareAsset | null = null;
|
||||
let isEditMode = false;
|
||||
|
||||
/**
|
||||
* 소프트웨어 필드 매핑 (통합 스키마 기반)
|
||||
* 소프트웨어는 자산번호를 사용하지 않으므로 제거함
|
||||
*/
|
||||
const SW_FIELD_MAP: Record<string, string> = {
|
||||
'법인': '법인',
|
||||
'자산번호': '자산번호',
|
||||
'제품명': '제품명',
|
||||
'수량': '수량',
|
||||
'금액': '금액',
|
||||
'구매일': '구매일',
|
||||
'납품업체': '납품업체',
|
||||
'비고': '비고',
|
||||
'플랫폼명': '플랫폼명',
|
||||
'부서': '부서',
|
||||
'계정명': '계정명',
|
||||
'결제수단': '결제수단',
|
||||
'연결카드번호': '연결카드번호',
|
||||
'결제일': '결제일',
|
||||
'당월청구액': '당월청구액',
|
||||
'라이선스유형': '라이선스유형',
|
||||
'만료일': '만료일',
|
||||
'라이선스키': '라이선스키'
|
||||
'법인': ASSET_SCHEMA.CORP.key,
|
||||
'제품명': ASSET_SCHEMA.PRODUCT.key,
|
||||
'수량': ASSET_SCHEMA.QTY.key,
|
||||
'금액': ASSET_SCHEMA.PRICE.key,
|
||||
'구매일': ASSET_SCHEMA.PURCHASE_YM.key,
|
||||
'납품업체': ASSET_SCHEMA.VENDOR.key,
|
||||
'비고': ASSET_SCHEMA.REMARKS.key,
|
||||
'플랫폼명': ASSET_SCHEMA.PLATFORM.key,
|
||||
'부서': '부서',
|
||||
'계정명': ASSET_SCHEMA.ACCOUNT.key,
|
||||
'결제수단': ASSET_SCHEMA.PAY_METHOD.key,
|
||||
'연결카드번호': ASSET_SCHEMA.CARD_NUM.key,
|
||||
'결제일': ASSET_SCHEMA.PAY_DAY.key,
|
||||
'당월청구액': ASSET_SCHEMA.BILLING.key,
|
||||
'라이선스유형': ASSET_SCHEMA.LICENSE_TYPE.key,
|
||||
'만료일': ASSET_SCHEMA.EXPIRY.key,
|
||||
'라이선스키': ASSET_SCHEMA.LICENSE_KEY.key
|
||||
};
|
||||
|
||||
const SW_FORM_HTML = `
|
||||
<!-- Group 1: 기본 정보 -->
|
||||
<div class="form-section-title">기본 정보 (Identity)</div>
|
||||
<div class="form-group">
|
||||
<label for="sw-법인">구매법인</label>
|
||||
<label for="sw-법인">${ASSET_SCHEMA.CORP.ui}</label>
|
||||
<select id="sw-법인" required>${generateOptionsHTML(CORP_LIST)}</select>
|
||||
</div>
|
||||
<div class="form-group sw-standard-field">
|
||||
<label for="sw-자산번호">자산번호</label>
|
||||
<div class="input-with-btn">
|
||||
<input type="text" id="sw-자산번호" readonly class="is-readonly-field" placeholder="번호 생성을 클릭하세요" />
|
||||
<button type="button" id="btn-generate-sw-code" class="btn btn-outline btn-sm">생성</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group full-width">
|
||||
<label for="sw-제품명">제품명 / 서비스명</label>
|
||||
<label for="sw-제품명">${ASSET_SCHEMA.PRODUCT.ui}</label>
|
||||
<input type="text" id="sw-제품명" required />
|
||||
</div>
|
||||
<div class="form-group cloud-only"><label for="sw-플랫폼명">플랫폼명</label><input type="text" id="sw-플랫폼명" placeholder="예: AWS, Cafe24" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-플랫폼명">${ASSET_SCHEMA.PLATFORM.ui}</label><input type="text" id="sw-플랫폼명" placeholder="예: AWS, Cafe24" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-부서">담당부서</label><input type="text" id="sw-부서" /></div>
|
||||
|
||||
<!-- Group 2: 라이선스 및 계약 -->
|
||||
<div class="form-section-title">라이선스 및 계약 정보</div>
|
||||
<div class="form-group sw-standard-field" id="sw-license-type-group"><label for="sw-라이선스유형">라이선스 유형</label><input type="text" id="sw-라이선스유형" /></div>
|
||||
<div class="form-group sw-standard-field" id="sw-license-key-group"><label for="sw-라이선스키">라이선스 키</label><input type="text" id="sw-라이선스키" /></div>
|
||||
<div class="form-group sw-standard-field"><label for="sw-수량">보유 수량</label><input type="number" id="sw-수량" min="0" /></div>
|
||||
<div class="form-group sw-standard-field"><label for="sw-금액">도입 금액</label><input type="text" id="sw-금액" oninput="this.value=this.value.replace(/[^0-9]/g,'').replace(/\\\\B(?=(\\\\d{3})+(?!\\\\d))/g,',')" /></div>
|
||||
<div class="form-group sw-standard-field" id="sw-license-type-group"><label for="sw-라이선스유형">${ASSET_SCHEMA.LICENSE_TYPE.ui}</label><input type="text" id="sw-라이선스유형" /></div>
|
||||
<div class="form-group sw-standard-field" id="sw-license-key-group"><label for="sw-라이선스키">${ASSET_SCHEMA.LICENSE_KEY.ui}</label><input type="text" id="sw-라이선스키" /></div>
|
||||
<div class="form-group sw-standard-field"><label for="sw-수량">${ASSET_SCHEMA.QTY.ui}</label><input type="number" id="sw-수량" min="0" /></div>
|
||||
<div class="form-group sw-standard-field"><label for="sw-금액">${ASSET_SCHEMA.PRICE.ui}</label><input type="text" id="sw-금액" oninput="this.value=this.value.replace(/[^0-9]/g,'').replace(/\\\\B(?=(\\\\d{3})+(?!\\\\d))/g,',')" /></div>
|
||||
|
||||
<div class="form-group cloud-only"><label for="sw-계정명">계정명 (이메일)</label><input type="text" id="sw-계정명" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-결제수단">결제수단</label><select id="sw-결제수단"><option value="">선택안함</option><option value="법인카드">법인카드</option><option value="인보이스">인보이스</option></select></div>
|
||||
<div class="form-group cloud-only"><label for="sw-연결카드번호">연결카드번호(뒷4자리)</label><input type="text" id="sw-연결카드번호" maxlength="4" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-결제일">결제일 (기준일)</label><input type="number" id="sw-결제일" min="1" max="31" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-당월청구액">당월 청구액(원)</label><input type="text" id="sw-당월청구액" oninput="this.value=this.value.replace(/[^0-9]/g,'').replace(/\\\\B(?=(\\\\d{3})+(?!\\\\d))/g,',')" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-계정명">${ASSET_SCHEMA.ACCOUNT.ui}</label><input type="text" id="sw-계정명" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-결제수단">${ASSET_SCHEMA.PAY_METHOD.ui}</label><select id="sw-결제수단"><option value="">선택안함</option><option value="법인카드">법인카드</option><option value="인보이스">인보이스</option></select></div>
|
||||
<div class="form-group cloud-only"><label for="sw-연결카드번호">${ASSET_SCHEMA.CARD_NUM.ui}</label><input type="text" id="sw-연결카드번호" maxlength="4" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-결제일">${ASSET_SCHEMA.PAY_DAY.ui}</label><input type="number" id="sw-결제일" min="1" max="31" /></div>
|
||||
<div class="form-group cloud-only"><label for="sw-당월청구액">${ASSET_SCHEMA.BILLING.ui}</label><input type="text" id="sw-당월청구액" oninput="this.value=this.value.replace(/[^0-9]/g,'').replace(/\\\\B(?=(\\\\d{3})+(?!\\\\d))/g,',')" /></div>
|
||||
|
||||
<!-- Group 4: 관리 정보 -->
|
||||
<div class="form-section-title">관리 및 비고</div>
|
||||
<div class="form-group sw-standard-field"><label for="sw-구매일">구매연월</label><input type="text" id="sw-구매일" placeholder="YYYYMM" maxlength="6" /></div>
|
||||
<div class="form-group sw-standard-field" id="sw-expiry-group"><label for="sw-만료일">만료일 (구독)</label><input type="text" id="sw-만료일" /></div>
|
||||
<div class="form-group sw-standard-field"><label for="sw-납품업체">납품업체</label><input type="text" id="sw-납품업체" /></div>
|
||||
<div class="form-group full-width"><label for="sw-비고">비고</label><textarea id="sw-비고" rows="2"></textarea></div>
|
||||
<div class="form-group sw-standard-field"><label for="sw-구매일">${ASSET_SCHEMA.PURCHASE_YM.ui}</label><input type="text" id="sw-구매일" placeholder="YYYYMM" maxlength="6" /></div>
|
||||
<div class="form-group sw-standard-field" id="sw-expiry-group"><label for="sw-만료일">${ASSET_SCHEMA.EXPIRY.ui}</label><input type="text" id="sw-만료일" /></div>
|
||||
<div class="form-group sw-standard-field"><label for="sw-납품업체">${ASSET_SCHEMA.VENDOR.ui}</label><input type="text" id="sw-납품업체" /></div>
|
||||
<div class="form-group full-width"><label for="sw-비고">${ASSET_SCHEMA.REMARKS.ui}</label><textarea id="hw-비고" rows="2"></textarea></div>
|
||||
|
||||
<div id="sw-user-section" class="user-management-section" style="margin-top: 2rem;">
|
||||
<div class="section-header" style="display:flex; justify-content:space-between; align-items:center; margin-bottom:1rem;">
|
||||
@@ -149,7 +146,6 @@ export function openSwModal(asset: SoftwareAsset, mode: 'view' | 'add' = 'view')
|
||||
setEditLock('sw-asset-form', mode, {
|
||||
saveBtnId: 'btn-save-sw-asset',
|
||||
revertBtnId: 'btn-revert-sw-edit',
|
||||
generateBtnId: 'btn-generate-sw-code',
|
||||
addLogBtnId: 'btn-add-sw-log'
|
||||
});
|
||||
isEditMode = (mode === 'add');
|
||||
@@ -171,9 +167,9 @@ export function initSwModal(onSave: () => void, closeModalsCb: () => void) {
|
||||
const logModalHTML = `
|
||||
<div id="sw-log-modal" class="modal-overlay hidden" style="z-index: 1100;">
|
||||
<div class="modal-content" style="max-width: 400px;">
|
||||
<div class="modal-header"><h2>업데이트 내역 추가</h2><button id="btn-close-sw-log" class="btn-icon"><i data-lucide="x"></i></button></div>
|
||||
<div class="modal-header"><h2>${UI_TEXT.ACTION.HISTORY_ADD}</h2><button id="btn-close-sw-log" class="btn-icon"><i data-lucide="x"></i></button></div>
|
||||
<div class="modal-body"><div class="grid-form" style="grid-template-columns: 1fr;"><div class="form-group"><label>날짜</label><input type="date" id="new-log-date" /></div><div class="form-group"><label>상세 내용</label><textarea id="new-log-details" rows="3"></textarea></div></div></div>
|
||||
<div class="modal-footer"><div></div><div class="footer-actions"><button id="btn-cancel-sw-log" class="btn btn-outline">취소</button><button id="btn-confirm-sw-log" class="btn btn-primary">추가</button></div></div>
|
||||
<div class="modal-footer"><div></div><div class="footer-actions"><button id="btn-cancel-sw-log" class="btn btn-outline">${UI_TEXT.ACTION.CANCEL}</button><button id="btn-confirm-sw-log" class="btn btn-primary">추가</button></div></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@@ -196,27 +192,12 @@ export function initSwModal(onSave: () => void, closeModalsCb: () => void) {
|
||||
setEditLock('sw-asset-form', 'view', {
|
||||
saveBtnId: 'btn-save-sw-asset',
|
||||
revertBtnId: 'btn-revert-sw-edit',
|
||||
generateBtnId: 'btn-generate-sw-code',
|
||||
addLogBtnId: 'btn-add-sw-log'
|
||||
});
|
||||
isEditMode = false;
|
||||
if (currentSwAsset) openSwModal(currentSwAsset, 'view');
|
||||
});
|
||||
|
||||
document.getElementById('btn-generate-sw-code')?.addEventListener('click', async () => {
|
||||
const typeValue = getFieldValue('sw-asset-type');
|
||||
const purchaseDate = getFieldValue('sw-구매일');
|
||||
const typeCode = TYPE_PREFIX_MAP[typeValue] || 'SW';
|
||||
const dateStr = purchaseDate.replace(/[^0-9]/g, '');
|
||||
if (dateStr.length < 6) { alert('올바른 구매연월(YYYYMM)을 입력해주세요.'); return; }
|
||||
const prefix = `${typeCode}-${dateStr.substring(0, 6)}-`;
|
||||
try {
|
||||
const res = await fetch(`http://172.16.40.100:3000/api/generate-asset-code?prefix=${prefix}`);
|
||||
const data = await res.json();
|
||||
if (data.nextCode) setFieldValue('sw-자산번호', data.nextCode);
|
||||
} catch (err) { alert('자산번호 생성에 실패했습니다.'); }
|
||||
});
|
||||
|
||||
// YYYYMM 입력 제한 로직 (숫자 6자리)
|
||||
document.getElementById('sw-구매일')?.addEventListener('input', (e) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
@@ -229,14 +210,13 @@ export function initSwModal(onSave: () => void, closeModalsCb: () => void) {
|
||||
setEditLock('sw-asset-form', 'edit', {
|
||||
saveBtnId: 'btn-save-sw-asset',
|
||||
revertBtnId: 'btn-revert-sw-edit',
|
||||
generateBtnId: 'btn-generate-sw-code',
|
||||
addLogBtnId: 'btn-add-sw-log'
|
||||
addLogBtnId: 'btn-add-hw-log'
|
||||
});
|
||||
isEditMode = true;
|
||||
return;
|
||||
}
|
||||
const extracted = autoExtractForm('sw', SW_FIELD_MAP);
|
||||
const updated = { ...currentSwAsset, ...extracted, 수량: parseInt(extracted.수량 || '0') };
|
||||
const updated = { ...currentSwAsset, ...extracted, 수량: parseInt(extracted[ASSET_SCHEMA.QTY.key] || '0') };
|
||||
|
||||
let targetList: SoftwareAsset[] = [];
|
||||
if (updated.type === '구독SW') targetList = state.masterData.subSw;
|
||||
@@ -250,14 +230,13 @@ export function initSwModal(onSave: () => void, closeModalsCb: () => void) {
|
||||
setEditLock('sw-asset-form', 'view', {
|
||||
saveBtnId: 'btn-save-sw-asset',
|
||||
revertBtnId: 'btn-revert-sw-edit',
|
||||
generateBtnId: 'btn-generate-sw-code',
|
||||
addLogBtnId: 'btn-add-sw-log'
|
||||
});
|
||||
isEditMode = false;
|
||||
});
|
||||
|
||||
deleteBtn.addEventListener('click', () => {
|
||||
if (currentSwAsset && confirm('삭제하시겠습니까?')) {
|
||||
if (currentSwAsset && confirm(UI_TEXT.MESSAGES.CONFIRM_DELETE)) {
|
||||
const type = currentSwAsset.type;
|
||||
if (type === '구독SW') state.masterData.subSw = state.masterData.subSw.filter(a => a.id !== currentSwAsset!.id);
|
||||
else if (type === '영구SW') state.masterData.permSw = state.masterData.permSw.filter(a => a.id !== currentSwAsset!.id);
|
||||
@@ -279,7 +258,7 @@ export function initSwModal(onSave: () => void, closeModalsCb: () => void) {
|
||||
const details = (document.getElementById('new-log-details') as HTMLTextAreaElement).value;
|
||||
if (!date || !details) return;
|
||||
state.masterData.logs = state.masterData.logs || [];
|
||||
state.masterData.logs.push({ id: Math.random().toString(36).substring(2, 9), assetId: currentSwAsset.id, date, user: '관리자', details });
|
||||
state.masterData.logs.push({ id: Math.random().toString(36).substring(2, 9), assetId: currentSwAsset.id, date, user: '담당자', details });
|
||||
logModal.classList.add('hidden'); renderSwHistory(currentSwAsset.id);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user