import { state } from '../../core/state'; import { openHwModal } from '../../components/Modal/HWModal'; import { formatInline, createBadge, sortAssets } from '../../core/utils'; import { ASSET_SCHEMA, UI_TEXT } from '../../core/schema'; import { createIcons, RefreshCcw } from 'lucide'; /** * 서버 자산 목록 뷰 * 라인 정렬 보정 및 헤더 통일 */ export function renderServerList(container: HTMLElement) { const fullList = sortAssets(state.masterData.server); const filterBar = document.createElement('div'); filterBar.className = 'search-bar'; const corps = Array.from(new Set(fullList.map(a => a[ASSET_SCHEMA.CORP.key]))).filter(Boolean).sort(); const orgUnits = Array.from(new Set(fullList.map(a => a[ASSET_SCHEMA.ORG.key]))).filter(Boolean).sort(); filterBar.innerHTML = `
`; container.appendChild(filterBar); const tableWrapper = document.createElement('div'); tableWrapper.className = 'table-container'; const table = document.createElement('table'); table.innerHTML = ` No ${ASSET_SCHEMA.CORP.ui} ${ASSET_SCHEMA.ORG.ui} ${ASSET_SCHEMA.ASSET_CODE.ui} 용도 상세 ${ASSET_SCHEMA.LOCATION.ui} 담당자(정/부) `; tableWrapper.appendChild(table); container.appendChild(tableWrapper); const tbody = table.querySelector('tbody')!; const updateTable = () => { const keywordInput = document.getElementById('filter-keyword') as HTMLInputElement; const corpSelect = document.getElementById('filter-corp') as HTMLSelectElement; const orgSelect = document.getElementById('filter-org-unit') as HTMLSelectElement; const keyword = keywordInput ? keywordInput.value.toLowerCase().trim() : ''; const corp = corpSelect ? corpSelect.value : ''; const orgUnit = orgSelect ? orgSelect.value : ''; const filtered = fullList.filter(asset => { const matchKeyword = !keyword || String(asset[ASSET_SCHEMA.ASSET_CODE.key]||'').toLowerCase().includes(keyword) || String(asset[ASSET_SCHEMA.ORG.key]||'').toLowerCase().includes(keyword) || String(asset[ASSET_SCHEMA.MODEL.key]||'').toLowerCase().includes(keyword); const matchCorp = !corp || asset[ASSET_SCHEMA.CORP.key] === corp; const matchOrg = !orgUnit || asset[ASSET_SCHEMA.ORG.key] === orgUnit; return matchKeyword && matchCorp && matchOrg; }); tbody.innerHTML = ''; if (filtered.length === 0) { tbody.innerHTML = `${UI_TEXT.MESSAGES.NO_DATA}`; return; } filtered.forEach((asset, idx) => { const tr = document.createElement('tr'); tr.style.cursor = 'pointer'; const mainManager = asset[ASSET_SCHEMA.MANAGER_MAIN.key] || ''; const subManager = asset[ASSET_SCHEMA.MANAGER_SUB.key] || ''; const managerHtml = [ mainManager ? `${createBadge('정', 'primary')} ${mainManager}` : '', subManager ? `${createBadge('부', 'muted')} ${subManager}` : '' ].filter(v => v !== '').join(' / '); tr.innerHTML = ` ${idx+1} ${asset[ASSET_SCHEMA.CORP.key]} ${asset[ASSET_SCHEMA.ORG.key]||'-'} ${asset[ASSET_SCHEMA.ASSET_CODE.key]} ${formatInline(asset.용도)} ${formatInline(asset.상세)} ${formatInline(asset[ASSET_SCHEMA.LOCATION.key])} ${managerHtml || '-'} `; tr.addEventListener('click', () => openHwModal(asset, 'view')); tbody.appendChild(tr); }); }; document.getElementById('filter-keyword')?.addEventListener('input', updateTable); document.getElementById('filter-corp')?.addEventListener('change', updateTable); document.getElementById('filter-org-unit')?.addEventListener('change', updateTable); document.getElementById('btn-reset-filters')?.addEventListener('click', () => { (document.getElementById('filter-keyword') as HTMLInputElement).value = ''; (document.getElementById('filter-corp') as HTMLSelectElement).value = ''; (document.getElementById('filter-org-unit') as HTMLSelectElement).value = ''; updateTable(); }); updateTable(); createIcons({ icons: { RefreshCcw } }); }