Merge all feature branches into main and optimize core architecture
This commit is contained in:
@@ -1,92 +1,78 @@
|
||||
import { state } from '../../core/state';
|
||||
import { openHwModal } from '../../components/Modal/HWModal';
|
||||
import { formatInline, sortAssets } from '../../core/utils';
|
||||
import { createIcons, Paperclip, RefreshCcw } from 'lucide';
|
||||
|
||||
export function renderPcList(container: HTMLElement) {
|
||||
const fullList = sortAssets(state.masterData.pc);
|
||||
|
||||
const filterBar = document.createElement('div');
|
||||
filterBar.className = 'search-bar';
|
||||
const corps = Array.from(new Set(fullList.map(a => a.법인))).filter(Boolean).sort();
|
||||
export function renderPcList(filterKeyword: string = '') {
|
||||
const container = document.getElementById('view-container');
|
||||
if (!container) return;
|
||||
|
||||
filterBar.innerHTML = `
|
||||
<div class="search-item flex-1">
|
||||
<label>통합 검색 (자산코드/사용자)</label>
|
||||
<input type="text" id="filter-keyword" placeholder="검색어를 입력하세요..." autocomplete="off">
|
||||
const pcs = state.masterData.pc.filter(pc =>
|
||||
pc.자산코드?.includes(filterKeyword) ||
|
||||
pc.사용자?.includes(filterKeyword) ||
|
||||
pc.모델명?.includes(filterKeyword) ||
|
||||
pc.실사용조직?.includes(filterKeyword)
|
||||
);
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="view-header">
|
||||
<div class="header-left">
|
||||
<h2>개인PC 자산 현황</h2>
|
||||
<span class="count-badge">총 ${pcs.length}대</span>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button id="btn-add-pc" class="btn btn-primary"><i data-lucide="plus"></i> 신규 등록</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="search-item">
|
||||
<label>구매법인</label>
|
||||
<select id="filter-corp"><option value="">전체 법인</option>${corps.map(c => `<option value="${c}">${c}</option>`).join('')}</select>
|
||||
<div class="table-container">
|
||||
<table class="itam-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>구매법인</th>
|
||||
<th>자산번호</th>
|
||||
<th>실사용조직</th>
|
||||
<th>사용자</th>
|
||||
<th>모델명</th>
|
||||
<th>사양 (CPU/RAM)</th>
|
||||
<th>도입일</th>
|
||||
<th>관리</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${pcs.length === 0 ? '<tr><td colspan="8" class="empty-row">데이터가 없습니다.</td></tr>' :
|
||||
pcs.map(pc => `
|
||||
<tr class="asset-row" data-id="${pc.id}">
|
||||
<td>${pc.법인 || '-'}</td>
|
||||
<td><span class="code-link">${pc.자산코드 || pc.관리번호 || '미부여'}</span></td>
|
||||
<td>${pc.실사용조직 || pc.현사용조직 || '-'}</td>
|
||||
<td>${pc.사용자 || '-'}</td>
|
||||
<td>${pc.모델명 || '-'}</td>
|
||||
<td><small>${pc.CPU || '-'} / ${pc.RAM || '-'}</small></td>
|
||||
<td>${pc.도입일 || pc.구매일 || '-'}</td>
|
||||
<td><button class="btn btn-sm btn-outline btn-detail" data-id="${pc.id}">상세</button></td>
|
||||
</tr>
|
||||
`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<button id="btn-reset-filters" class="btn btn-outline btn-reset">
|
||||
<i data-lucide="refresh-ccw"></i> 필터 초기화
|
||||
</button>
|
||||
`;
|
||||
container.appendChild(filterBar);
|
||||
|
||||
const tableWrapper = document.createElement('div');
|
||||
tableWrapper.className = 'table-container';
|
||||
const table = document.createElement('table');
|
||||
table.innerHTML = `<thead><tr><th>No</th><th>구매법인</th><th>현 사용조직</th><th>자산코드</th><th>사용자</th><th>위치</th><th>CPU</th><th>RAM</th><th>Storage</th><th>구매연월</th><th>금액</th><th>품의서</th><th>관리</th></tr></thead><tbody id="dynamic-tbody"></tbody>`;
|
||||
|
||||
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 keyword = keywordInput ? keywordInput.value.toLowerCase().trim() : '';
|
||||
const corp = corpSelect ? corpSelect.value : '';
|
||||
|
||||
const filtered = fullList.filter(asset => {
|
||||
const matchKeyword = !keyword || String(asset.자산코드||'').toLowerCase().includes(keyword) || String(asset.사용자||'').toLowerCase().includes(keyword) || String(asset.현사용조직||'').toLowerCase().includes(keyword);
|
||||
const matchCorp = !corp || asset.법인 === corp;
|
||||
return matchKeyword && matchCorp;
|
||||
// 이벤트 바인딩
|
||||
container.querySelectorAll('.asset-row, .btn-detail').forEach(el => {
|
||||
el.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
const id = (el as HTMLElement).getAttribute('data-id');
|
||||
const asset = state.masterData.pc.find(a => a.id === id);
|
||||
if (asset) openHwModal(asset, 'view');
|
||||
});
|
||||
|
||||
tbody.innerHTML = '';
|
||||
if (filtered.length === 0) {
|
||||
tbody.innerHTML = `<tr><td colspan="13" style="text-align:center; padding: 3rem; color: var(--text-muted);">검색 결과가 없습니다.</td></tr>`;
|
||||
return;
|
||||
}
|
||||
|
||||
filtered.forEach((asset, idx) => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.style.cursor = 'pointer';
|
||||
const storage = [asset.SSD1, asset.SSD2, asset.HDD1].filter(v => v).join(' / ');
|
||||
|
||||
tr.innerHTML = `
|
||||
<td>${idx+1}</td>
|
||||
<td>${asset.법인}</td>
|
||||
<td>${asset.현사용조직||''}</td>
|
||||
<td>${asset.자산코드}</td>
|
||||
<td>${asset.사용자||''}</td>
|
||||
<td>${asset.위치||''}</td>
|
||||
<td>${asset.CPU||''}</td>
|
||||
<td>${asset.RAM||''}</td>
|
||||
<td>${formatInline(storage)}</td>
|
||||
<td>${asset.구매연월 || asset.구매일 || ''}</td>
|
||||
<td>${asset.금액||''}</td>
|
||||
<td style="text-align:center;">${asset.품의서명 ? '<i data-lucide="paperclip" class="text-primary"></i>' : '-'}</td>
|
||||
<td><button class="btn btn-outline btn-sm">수정</button></td>
|
||||
`;
|
||||
tr.addEventListener('click', (e) => { if (!(e.target as HTMLElement).closest('button')) openHwModal(asset, 'view'); });
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
createIcons({ icons: { Paperclip } });
|
||||
};
|
||||
|
||||
document.getElementById('filter-keyword')?.addEventListener('input', updateTable);
|
||||
document.getElementById('filter-corp')?.addEventListener('change', updateTable);
|
||||
document.getElementById('btn-reset-filters')?.addEventListener('click', () => {
|
||||
(document.getElementById('filter-keyword') as HTMLInputElement).value = '';
|
||||
(document.getElementById('filter-corp') as HTMLSelectElement).value = '';
|
||||
updateTable();
|
||||
});
|
||||
|
||||
updateTable();
|
||||
document.getElementById('btn-add-pc')?.addEventListener('click', () => {
|
||||
const newPc: any = {
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: '개인PC',
|
||||
법인: 'HM',
|
||||
관리조직: '전산팀',
|
||||
상태: '사용중'
|
||||
};
|
||||
openHwModal(newPc, 'add');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user