853 lines
47 KiB
TypeScript
853 lines
47 KiB
TypeScript
import { state } from '../../core/state';
|
|
import { openHwModal } from '../../components/Modal/HWModal';
|
|
import { calculatePcScoreDeductive, getPcGrade, calculateAssetAge, isWindows11Incompatible } from '../../core/utils';
|
|
import { ASSET_SCHEMA } from '../../core/schema';
|
|
import { createIcons, Laptop, Cpu, Shield, Zap, Monitor, AlertTriangle, ChevronRight, HelpCircle } from 'lucide';
|
|
|
|
declare var Chart: any;
|
|
|
|
let donutChartInstance: any = null;
|
|
|
|
export function renderHwDashboard(container: HTMLElement) {
|
|
// 1. 개인용 PC 데이터 추출 (유형이 '개인PC'이거나 상태가 '재고' 또는 '대기' 상태인 PC 집계)
|
|
const pcs = (state.masterData.pc || []).filter((a: any) =>
|
|
a.asset_type === '개인PC' ||
|
|
((a.hw_status === '재고' || a.hw_status === '대기') && a.category === 'PC')
|
|
);
|
|
|
|
// 2. 1페이지 매거진 리포트(제목바 제거, '| 제목' 미니멀리즘 스타일) HTML 빌드
|
|
container.innerHTML = `
|
|
<div class="view-container" style="overflow: hidden; padding: 0.4rem 1.2rem; background-color: #F8FAFC; height: calc(100vh - var(--header-height) - 48px); box-sizing: border-box; display: flex; flex-direction: column; gap: 0.5rem; font-family: 'Pretendard', sans-serif; color: #1E293B;">
|
|
|
|
<!-- 대시보드 타이틀 및 사용조직 필터 -->
|
|
<div style="display: flex; justify-content: space-between; align-items: flex-end; flex-shrink: 0; padding-bottom: 0.4rem;">
|
|
<div style="border-left: 4px solid #1E5149; padding-left: 8px;">
|
|
<h2 style="font-size: 1.65rem; font-weight: 850; color: #1E5149; margin: 0; letter-spacing: -0.5px; display: flex; align-items: center; gap: 0.6rem;">
|
|
개인 PC 자산 대시보드
|
|
</h2>
|
|
</div>
|
|
|
|
<!-- 사용조직 필터 (브랜드 그린 매칭 칩 디자인) -->
|
|
<div style="display: flex; align-items: center; gap: 0.75rem;">
|
|
<span style="font-size: 0.9rem; font-weight: 700; color: #475569; white-space: nowrap;">조직 필터:</span>
|
|
<div id="dashboard-dept-buttons" style="display: flex; gap: 0.3rem; background: #EEF2F6; padding: 4px; border-radius: 8px; border: 1px solid #E2E8F0;">
|
|
<button class="dept-filter-btn active" data-dept="" style="padding: 6px 14px; font-size: 0.88rem; font-weight: 700; border-radius: 6px; border: none; background: #1E5149; color: white; cursor: pointer; transition: all 0.2s;">전체</button>
|
|
<button class="dept-filter-btn" data-dept="한맥" style="padding: 6px 14px; font-size: 0.88rem; font-weight: 700; border-radius: 6px; border: none; background: transparent; color: #475569; cursor: pointer; transition: all 0.2s;">한맥</button>
|
|
<button class="dept-filter-btn" data-dept="삼안" style="padding: 6px 14px; font-size: 0.88rem; font-weight: 700; border-radius: 6px; border: none; background: transparent; color: #475569; cursor: pointer; transition: all 0.2s;">삼안</button>
|
|
<button class="dept-filter-btn" data-dept="장헌" style="padding: 6px 14px; font-size: 0.88rem; font-weight: 700; border-radius: 6px; border: none; background: transparent; color: #475569; cursor: pointer; transition: all 0.2s;">장헌</button>
|
|
<button class="dept-filter-btn" data-dept="한라" style="padding: 6px 14px; font-size: 0.88rem; font-weight: 700; border-radius: 6px; border: none; background: transparent; color: #475569; cursor: pointer; transition: all 0.2s;">한라</button>
|
|
<button class="dept-filter-btn" data-dept="기술개발센터" style="padding: 6px 14px; font-size: 0.88rem; font-weight: 700; border-radius: 6px; border: none; background: transparent; color: #475569; cursor: pointer; transition: all 0.2s;">기술개발센터</button>
|
|
<button class="dept-filter-btn" data-dept="총괄기획실" style="padding: 6px 14px; font-size: 0.88rem; font-weight: 700; border-radius: 6px; border: none; background: transparent; color: #475569; cursor: pointer; transition: all 0.2s;">총괄기획실</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 상단 섹션 (전체 높이의 약 45% 차지, stat-card와 donut/aging 나열) -->
|
|
<div style="display: grid; grid-template-columns: 1fr 1.2fr; gap: 0.5rem; height: 43%; min-height: 0; flex-shrink: 0; margin-bottom: 0.1rem;">
|
|
|
|
<!-- 상단 좌측: 핵심 지표 카드 -->
|
|
<div class="stat-card" style="background: transparent; border-radius: 0; padding: 0.5rem 0.25rem; border: none; border-bottom: 1px solid #E2E8F0; display: grid !important; grid-template-columns: 1fr 1fr; gap: 0.4rem 0.8rem;">
|
|
|
|
<!-- 1. 보유 자산 수량 -->
|
|
<div style="border-right: 1px solid #EEF2F6; border-bottom: 1px solid #EEF2F6; padding-bottom: 0.4rem; padding-right: 0.8rem; display: flex; flex-direction: column; justify-content: center;">
|
|
<div style="border-left: 4px solid #1E5149; padding-left: 8px; margin-bottom: 0.3rem; display: flex; align-items: center; line-height: 1;">
|
|
<span style="font-size: 1.05rem; font-weight: 800; color: #1E293B; white-space: nowrap;">보유 자산 수량</span>
|
|
</div>
|
|
<div style="display: flex; align-items: flex-end; justify-content: space-between;">
|
|
<div id="metric-total-pcs" style="font-size: 2.1rem; font-weight: 900; color: #1E5149; line-height: 1;">0대</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 2. 사양 부족 -->
|
|
<div id="card-under-spec" style="border-bottom: 1px solid #EEF2F6; padding-bottom: 0.4rem; padding-left: 0.8rem; cursor: pointer; transition: opacity 0.2s; display: flex; flex-direction: column; justify-content: center;" onmouseover="this.style.opacity='0.7'" onmouseout="this.style.opacity='1'">
|
|
<div style="border-left: 4px solid #EF4444; padding-left: 8px; margin-bottom: 0.3rem; display: flex; align-items: center; line-height: 1;">
|
|
<span style="font-size: 1.05rem; font-weight: 800; color: #1E293B; white-space: nowrap;">사양 부족</span>
|
|
</div>
|
|
<div style="display: flex; align-items: flex-end; justify-content: space-between;">
|
|
<div id="metric-under-spec" style="font-size: 2.1rem; font-weight: 900; color: #EF4444; line-height: 1;">0대</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 3. 오버 스펙 -->
|
|
<div id="card-over-spec" style="border-right: 1px solid #EEF2F6; padding-top: 0.4rem; padding-right: 0.8rem; cursor: pointer; transition: opacity 0.2s; display: flex; flex-direction: column; justify-content: center;" onmouseover="this.style.opacity='0.7'" onmouseout="this.style.opacity='1'">
|
|
<div style="border-left: 4px solid #F59E0B; padding-left: 8px; margin-bottom: 0.3rem; display: flex; align-items: center; line-height: 1;">
|
|
<span style="font-size: 1.05rem; font-weight: 800; color: #1E293B; white-space: nowrap;">오버 스펙</span>
|
|
</div>
|
|
<div style="display: flex; align-items: flex-end; justify-content: space-between;">
|
|
<div id="metric-over-spec" style="font-size: 2.1rem; font-weight: 900; color: #F59E0B; line-height: 1;">0대</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 4. 윈도우 11 불가 PC -->
|
|
<div id="card-win11-incompatible" style="padding-top: 0.4rem; padding-left: 0.8rem; cursor: pointer; transition: opacity 0.2s; display: flex; flex-direction: column; justify-content: center;" onmouseover="this.style.opacity='0.7'" onmouseout="this.style.opacity='1'">
|
|
<div style="border-left: 4px solid #3B82F6; padding-left: 8px; margin-bottom: 0.3rem; display: flex; align-items: center; line-height: 1;">
|
|
<span style="font-size: 1.05rem; font-weight: 800; color: #1E293B; white-space: nowrap;">윈도우 11 불가 PC</span>
|
|
</div>
|
|
<div style="display: flex; align-items: flex-end; justify-content: space-between;">
|
|
<div id="metric-win11-incompatible" style="font-size: 2.1rem; font-weight: 900; color: #3B82F6; line-height: 1;">0대</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- 상단 우측: 등급별 보유 비율 도넛 & 연도별 PC 노후도 통합 배치 (가로 배치) -->
|
|
<div style="background: transparent; border-radius: 0; padding: 0.5rem 0.25rem; border: none; border-bottom: 1px solid #E2E8F0; display: grid; grid-template-columns: 1fr 1.15fr; gap: 0.8rem; min-height: 0;">
|
|
|
|
<!-- 1열: 등급별 보유 비율 도넛 영역 -->
|
|
<div style="display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 0.4rem; min-height: 0; height: 100%;">
|
|
<!-- 서브 제목 -->
|
|
<div style="width: 100%; border-left: 4px solid #1E5149; padding-left: 8px; margin-bottom: 0.2rem; display: flex; align-items: center; line-height: 1; flex-shrink: 0; height: 1.4rem;">
|
|
<span style="font-size: 1.15rem; font-weight: 850; color: #1E293B;">등급별 보유 비율</span>
|
|
</div>
|
|
|
|
<!-- 도넛 그래프 -->
|
|
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; width: 100%; min-height: 0;">
|
|
<div style="width: 105px; height: 105px; position: relative;">
|
|
<canvas id="chart-overall-donut"></canvas>
|
|
</div>
|
|
<!-- 커스텀 범례 -->
|
|
<div style="display: flex; flex-wrap: wrap; gap: 0.2rem 0.4rem; justify-content: center; align-items: center; margin-top: 6px; font-size: 0.82rem; font-weight: 700; color: #475569; width: 100%;">
|
|
<div style="display: flex; align-items: center; gap: 3px;">
|
|
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #11302B;"></span>
|
|
<span>최상급</span>
|
|
</div>
|
|
<div style="display: flex; align-items: center; gap: 3px;">
|
|
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #1E8E7C;"></span>
|
|
<span>상급</span>
|
|
</div>
|
|
<div style="display: flex; align-items: center; gap: 3px;">
|
|
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #10B981;"></span>
|
|
<span>중급</span>
|
|
</div>
|
|
<div style="display: flex; align-items: center; gap: 3px;">
|
|
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #F59E0B;"></span>
|
|
<span>보급</span>
|
|
</div>
|
|
<div style="display: flex; align-items: center; gap: 3px;">
|
|
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #EF4444;"></span>
|
|
<span>교체 대상</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 2열: 연도별 PC 노후도 및 예측 (표) -->
|
|
<div style="display: flex; flex-direction: column; min-height: 0;">
|
|
<div style="border-left: 4px solid #1E5149; padding-left: 8px; margin-bottom: 0.3rem; display: flex; align-items: center; line-height: 1; flex-shrink: 0; height: 1.4rem;">
|
|
<span style="font-size: 1.15rem; font-weight: 850; color: #1E293B; white-space: nowrap;">연도별 PC 노후도 및 예측</span>
|
|
</div>
|
|
<div style="flex: 1; overflow-y: auto; min-height: 0; padding-right: 0.2rem;">
|
|
<table style="width: 100%; border-collapse: collapse; text-align: left; font-size: 0.95rem;">
|
|
<thead style="position: sticky; top: 0; background: white; z-index: 5;">
|
|
<tr style="border-bottom: 2px solid #1E5149; color: #475569; font-weight: 850;">
|
|
<th style="padding: 6px 8px; width: 45%; font-size: 0.95rem;">구분 (연한)</th>
|
|
<th style="padding: 6px 8px; text-align: center; width: 25%; font-size: 0.95rem;">보유</th>
|
|
<th style="padding: 6px 8px; text-align: center; width: 30%; font-size: 0.95rem;">권장 조치</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="pc-aging-tbody">
|
|
<!-- Dynamic Aging Contents -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- 하단 섹션 (등급별 자산 종합 현황 + 바 그래프, 약 53% 차지) -->
|
|
<div style="background: transparent; border-radius: 0; padding: 0.5rem 0.25rem; border: none; display: flex; flex-direction: column; height: 53%; min-height: 0;">
|
|
<div style="display: flex; flex-direction: column; gap: 0.5rem; justify-content: flex-start; padding-left: 0.5rem; height: 100%;">
|
|
<!-- 메인 제목 -->
|
|
<div style="border-left: 4px solid #1E5149; padding-left: 8px; margin-bottom: 0.2rem; display: flex; align-items: center; line-height: 1; height: 1.6rem; flex-shrink: 0;">
|
|
<span style="font-size: 1.25rem; font-weight: 850; color: #1E293B;">등급별 자산 종합 현황 및 사양 적정성 분석</span>
|
|
</div>
|
|
|
|
<!-- 종합 매트릭스 테이블 -->
|
|
<div style="width: 100%; overflow-y: auto; flex: 1;">
|
|
<table style="width: 100%; border-collapse: collapse; text-align: left; font-size: 1.1rem;">
|
|
<thead style="position: sticky; top: 0; background: #F8FAFC; z-index: 10;">
|
|
<tr style="border-bottom: 2px solid #1E5149; color: #475569; font-weight: 850;">
|
|
<th style="padding: 10px 8px; width: 22%; font-size: 1.1rem; background: #F8FAFC;">구분 (등급)</th>
|
|
<th style="padding: 10px 8px; text-align: center; width: 11%; font-size: 1.1rem; background: #F8FAFC;">보유량</th>
|
|
<th style="padding: 10px 8px; text-align: center; width: 11%; font-size: 1.1rem; background: #F8FAFC;">운영중</th>
|
|
<th style="padding: 10px 8px; text-align: center; width: 11%; font-size: 1.1rem; background: #F8FAFC;">재고</th>
|
|
<th style="padding: 10px 8px; text-align: center; width: 11%; color: #EF4444; font-size: 1.1rem; background: #F8FAFC;">구매 필요</th>
|
|
<th style="padding: 10px 8px; text-align: center; width: 34%; font-size: 1.1rem; background: #F8FAFC;">사양 적정성 분석 (직무 기준)</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="pc-grade-matrix-tbody">
|
|
<!-- Dynamic Matrix Contents -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
`;
|
|
|
|
// 3. Lucide 아이콘 초기화
|
|
createIcons({
|
|
icons: { Laptop, Cpu, Shield, Zap, Monitor, AlertTriangle, ChevronRight, HelpCircle }
|
|
});
|
|
|
|
// 4. 사용조직 버튼 그룹 필터 이벤트 연동
|
|
const btnGroup = container.querySelector('#dashboard-dept-buttons') as HTMLElement;
|
|
btnGroup.addEventListener('click', (e) => {
|
|
const btn = (e.target as HTMLElement).closest('.dept-filter-btn') as HTMLButtonElement;
|
|
if (!btn) return;
|
|
|
|
btnGroup.querySelectorAll('.dept-filter-btn').forEach(b => {
|
|
const button = b as HTMLButtonElement;
|
|
button.classList.remove('active');
|
|
button.style.background = 'transparent';
|
|
button.style.color = '#475569';
|
|
});
|
|
|
|
btn.classList.add('active');
|
|
btn.style.background = '#1E5149';
|
|
btn.style.color = 'white';
|
|
|
|
const selectedDept = btn.getAttribute('data-dept') || '';
|
|
updateDashboardData(pcs, selectedDept);
|
|
});
|
|
|
|
// 5. 첫 로딩 시 전체 부서 대상 통계 로드
|
|
updateDashboardData(pcs, '');
|
|
}
|
|
|
|
/**
|
|
* 대시보드 데이터 수치 및 차트, 테이블 실시간 갱신
|
|
*/
|
|
function updateDashboardData(pcs: any[], selectedDept: string) {
|
|
// 1. 선택 부서 필터 적용
|
|
const filtered = selectedDept
|
|
? pcs.filter((p: any) => String(p[ASSET_SCHEMA.CURRENT_DEPT.key] || '').trim().includes(selectedDept))
|
|
: pcs;
|
|
|
|
// 2. 개별 PC의 성능 감점식 점수 실시간 재연산
|
|
filtered.forEach((p: any) => {
|
|
p._pc_score = calculatePcScoreDeductive(p.cpu, p.ram, p.gpu, p.purchase_date);
|
|
});
|
|
|
|
// 3. DB 기준 사양 데이터 맵핑 (state.masterData.jobSpecs 이용)
|
|
const jobSpecsMap: Record<string, number> = {};
|
|
if (state.masterData.jobSpecs) {
|
|
state.masterData.jobSpecs.forEach((s: any) => {
|
|
jobSpecsMap[s.job_name] = s.min_score;
|
|
});
|
|
}
|
|
|
|
const jobScores: Record<string, { totalScore: number; count: number; avg: number }> = {};
|
|
pcs.forEach((p: any) => {
|
|
const score = calculatePcScoreDeductive(p.cpu, p.ram, p.gpu, p.purchase_date);
|
|
const job = p[ASSET_SCHEMA.USER_POSITION.key] || '미분류';
|
|
if (!jobScores[job]) jobScores[job] = { totalScore: 0, count: 0, avg: 0 };
|
|
jobScores[job].totalScore += score;
|
|
jobScores[job].count += 1;
|
|
});
|
|
Object.keys(jobScores).forEach(job => {
|
|
jobScores[job].avg = jobScores[job].count > 0 ? jobScores[job].totalScore / jobScores[job].count : 0;
|
|
});
|
|
|
|
// 4. 등급 집계 (보유량 vs 실제 할당량 vs 유효 재고량 vs 사양 부족량)
|
|
const isStock = (p: any) => {
|
|
return p.hw_status === '재고' ||
|
|
p.hw_status === '대기' ||
|
|
!(p.user_current || '').trim();
|
|
};
|
|
|
|
const matrix = {
|
|
premium: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] },
|
|
high: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] },
|
|
normal: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] },
|
|
entry: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] },
|
|
replace: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] }
|
|
};
|
|
|
|
let scoreSum = 0;
|
|
let underSpecCount = 0;
|
|
let overSpecCount = 0;
|
|
let win11IncompatibleCount = 0;
|
|
const criticalList: any[] = [];
|
|
|
|
filtered.forEach((p: any) => {
|
|
const score = p._pc_score;
|
|
scoreSum += score;
|
|
const stockYn = isStock(p);
|
|
const win11Incompatible = isWindows11Incompatible(p.cpu, p.ram);
|
|
|
|
// 1. 현재 물리적 자산 등급 판정
|
|
let currentGradeKey: keyof typeof matrix;
|
|
if (score >= 85) {
|
|
currentGradeKey = 'premium';
|
|
} else if (score >= 70) {
|
|
currentGradeKey = 'high';
|
|
} else if (score >= 40) {
|
|
currentGradeKey = 'normal';
|
|
} else if (score >= 20 && !win11Incompatible) {
|
|
currentGradeKey = 'entry';
|
|
} else {
|
|
currentGradeKey = 'replace';
|
|
}
|
|
|
|
const currentTarget = matrix[currentGradeKey];
|
|
currentTarget.pcs.push(p);
|
|
currentTarget.total++;
|
|
|
|
if (stockYn) {
|
|
currentTarget.stock++;
|
|
currentTarget.stockPcs.push(p);
|
|
} else {
|
|
currentTarget.active++;
|
|
currentTarget.activePcs.push(p);
|
|
|
|
// 직무 적정성 계산 (재직 중이고 실 사용자 매핑 자산만 검토 대상)
|
|
const job = p[ASSET_SCHEMA.USER_POSITION.key] || '미분류';
|
|
const standardScore = jobSpecsMap[job] !== undefined ? jobSpecsMap[job] : (jobScores[job]?.avg || 0);
|
|
|
|
let isUnder = false;
|
|
|
|
if (standardScore > 0 && job !== '재고PC') {
|
|
if (score < standardScore * 0.6) {
|
|
isUnder = true;
|
|
p._spec_status = '사양 부족';
|
|
} else if (score > standardScore * 1.5 && !win11Incompatible) {
|
|
p._spec_status = '오버스펙';
|
|
criticalList.push(p);
|
|
overSpecCount++;
|
|
} else if (win11Incompatible) {
|
|
isUnder = true;
|
|
p._spec_status = '사양 부족';
|
|
} else {
|
|
p._spec_status = '적정';
|
|
}
|
|
} else {
|
|
if (win11Incompatible) {
|
|
isUnder = true;
|
|
p._spec_status = '사양 부족';
|
|
} else {
|
|
p._spec_status = '적정';
|
|
}
|
|
}
|
|
|
|
if (isUnder) {
|
|
criticalList.push(p);
|
|
underSpecCount++;
|
|
|
|
// 2. 사양 부족 시 교체받아야 할 직무별 권장 목표 등급 판정
|
|
let targetGradeKey: keyof typeof matrix;
|
|
if (standardScore >= 85) {
|
|
targetGradeKey = 'premium';
|
|
} else if (standardScore >= 70) {
|
|
targetGradeKey = 'high';
|
|
} else if (standardScore >= 40) {
|
|
targetGradeKey = 'normal';
|
|
} else {
|
|
targetGradeKey = 'entry'; // 교체 대상은 최소 보급형 사양으로 교체
|
|
}
|
|
|
|
const targetGrade = matrix[targetGradeKey];
|
|
targetGrade.under++;
|
|
targetGrade.underPcs.push(p);
|
|
}
|
|
}
|
|
|
|
// Windows 11 업그레이드 지원 불가 검사
|
|
if (isWindows11Incompatible(p.cpu, p.ram)) {
|
|
win11IncompatibleCount++;
|
|
}
|
|
});
|
|
|
|
// 5. 핵심 텍스트형 요약 지표 갱신
|
|
document.getElementById('metric-total-pcs')!.textContent = `${filtered.length}대`;
|
|
document.getElementById('metric-under-spec')!.textContent = `${underSpecCount}대`;
|
|
document.getElementById('metric-over-spec')!.textContent = `${overSpecCount}대`;
|
|
document.getElementById('metric-win11-incompatible')!.textContent = `${win11IncompatibleCount}대`;
|
|
|
|
// 6. 종합 매트릭스 테이블 렌더링 및 바인딩
|
|
const matrixTbody = document.getElementById('pc-grade-matrix-tbody')!;
|
|
|
|
const getSpecStatusCounts = (activePcsList: any[]) => {
|
|
let under = 0;
|
|
let normal = 0;
|
|
let over = 0;
|
|
activePcsList.forEach(p => {
|
|
if (p._spec_status === '사양 부족') under++;
|
|
else if (p._spec_status === '오버스펙') over++;
|
|
else normal++;
|
|
});
|
|
return { under, normal, over };
|
|
};
|
|
|
|
const renderMatrixRow = (gradeKey: keyof typeof matrix, label: string, color: string, shortage: number) => {
|
|
const data = matrix[gradeKey];
|
|
const totalRate = filtered.length > 0 ? Math.round((data.total / filtered.length) * 100) : 0;
|
|
|
|
const cellStyle = `padding: 10px 8px; text-align: center; font-weight: 700; cursor: pointer; transition: background 0.2s; font-size: 1.1rem;`;
|
|
const hoverEvents = `onmouseover="this.style.background='#F1F5F9'" onmouseout="this.style.background='none'"`;
|
|
|
|
// 사양 적정성 분석 데이터 계산 (운영중인 자산만)
|
|
const { under, normal, over } = getSpecStatusCounts(data.activePcs);
|
|
const activeCount = data.active;
|
|
|
|
const underPct = activeCount > 0 ? (under / activeCount) * 100 : 0;
|
|
const normalPct = activeCount > 0 ? (normal / activeCount) * 100 : 0;
|
|
const overPct = activeCount > 0 ? (over / activeCount) * 100 : 0;
|
|
|
|
let barGraphHtml = '';
|
|
if (activeCount > 0) {
|
|
barGraphHtml = `
|
|
<div style="display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; width: 100%;">
|
|
<div style="display: flex; height: 18px; border-radius: 4px; overflow: hidden; background: #E2E8F0; width: 100%; max-width: 220px; box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);">
|
|
${under > 0 ? `<div style="width: ${underPct}%; background: #EF4444; cursor: pointer; transition: opacity 0.15s;" title="사양 부족: ${under}대 (${Math.round(underPct)}%)" class="spec-segment-btn" data-grade="${gradeKey}" data-spec-status="사양 부족" onmouseover="this.style.opacity='0.8'" onmouseout="this.style.opacity='1'"></div>` : ''}
|
|
${normal > 0 ? `<div style="width: ${normalPct}%; background: #1E5149; cursor: pointer; transition: opacity 0.15s;" title="적정 사양: ${normal}대 (${Math.round(normalPct)}%)" class="spec-segment-btn" data-grade="${gradeKey}" data-spec-status="적정" onmouseover="this.style.opacity='0.8'" onmouseout="this.style.opacity='1'"></div>` : ''}
|
|
${over > 0 ? `<div style="width: ${overPct}%; background: #F59E0B; cursor: pointer; transition: opacity 0.15s;" title="오버 스펙: ${over}대 (${Math.round(overPct)}%)" class="spec-segment-btn" data-grade="${gradeKey}" data-spec-status="오버스펙" onmouseover="this.style.opacity='0.8'" onmouseout="this.style.opacity='1'"></div>` : ''}
|
|
</div>
|
|
<div style="display: flex; gap: 8px; font-size: 0.8rem; font-weight: 750; color: #64748B;">
|
|
${under > 0 ? `<span style="color: #EF4444; cursor: pointer;" class="spec-text-btn" data-grade="${gradeKey}" data-spec-status="사양 부족">부족 ${under}</span>` : ''}
|
|
${normal > 0 ? `<span style="color: #1E5149; cursor: pointer;" class="spec-text-btn" data-grade="${gradeKey}" data-spec-status="적정">적정 ${normal}</span>` : ''}
|
|
${over > 0 ? `<span style="color: #F59E0B; cursor: pointer;" class="spec-text-btn" data-grade="${gradeKey}" data-spec-status="오버스펙">오버 ${over}</span>` : ''}
|
|
</div>
|
|
</div>
|
|
`;
|
|
} else {
|
|
barGraphHtml = `<span style="font-size: 0.9rem; color: #94A3B8; font-weight: 500;">운영중 자산 없음</span>`;
|
|
}
|
|
|
|
return `
|
|
<tr style="border-bottom: 1px solid #F1F5F9;">
|
|
<td style="padding: 10px 8px; font-weight: 800; color: ${color}; font-size: 1.1rem;">${label}</td>
|
|
<td class="matrix-cell" data-grade="${gradeKey}" data-type="total" style="${cellStyle}" ${hoverEvents}>${data.total}대 <span style="font-size:0.9rem; color:#64748B; font-weight:500;">(${totalRate}%)</span></td>
|
|
<td class="matrix-cell" data-grade="${gradeKey}" data-type="active" style="${cellStyle}" ${hoverEvents}>${data.active}대</td>
|
|
<td class="matrix-cell" data-grade="${gradeKey}" data-type="stock" style="${cellStyle}" ${hoverEvents}>${data.stock}대</td>
|
|
<td class="matrix-cell" data-grade="${gradeKey}" data-type="under" style="${cellStyle} color: #EF4444;" ${hoverEvents}>${shortage}대</td>
|
|
<td style="padding: 10px 8px; text-align: center; font-weight: 700; font-size: 1.1rem; vertical-align: middle;">
|
|
${barGraphHtml}
|
|
</td>
|
|
</tr>
|
|
`;
|
|
};
|
|
|
|
const totalPcs = filtered.length;
|
|
const totalActive = matrix.premium.active + matrix.high.active + matrix.normal.active + matrix.entry.active + matrix.replace.active;
|
|
const totalStock = matrix.premium.stock + matrix.high.stock + matrix.normal.stock + matrix.entry.stock + matrix.replace.stock;
|
|
|
|
const premiumShortage = Math.max(0, matrix.premium.under - matrix.premium.stock);
|
|
const highShortage = Math.max(0, matrix.high.under - matrix.high.stock);
|
|
const normalShortage = Math.max(0, matrix.normal.under - matrix.normal.stock);
|
|
|
|
// 보급 PC 구매 필요 = 보급 under - 보급 stock
|
|
const entryShortage = Math.max(0, matrix.entry.under - matrix.entry.stock);
|
|
|
|
// 교체 대상 PC 자체는 새로 구매하는 기종이 아니므로 구매 필요 0대
|
|
const replaceShortage = 0;
|
|
|
|
const totalShortage = premiumShortage + highShortage + normalShortage + entryShortage + replaceShortage;
|
|
|
|
const totalActivePcs = filtered.filter(p => !isStock(p));
|
|
const { under: totUnder, normal: totNormal, over: totOver } = getSpecStatusCounts(totalActivePcs);
|
|
const totUnderPct = totalActive > 0 ? (totUnder / totalActive) * 100 : 0;
|
|
const totNormalPct = totalActive > 0 ? (totNormal / totalActive) * 100 : 0;
|
|
const totOverPct = totalActive > 0 ? (totOver / totalActive) * 100 : 0;
|
|
|
|
let totBarGraphHtml = '';
|
|
if (totalActive > 0) {
|
|
totBarGraphHtml = `
|
|
<div style="display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; width: 100%;">
|
|
<div style="display: flex; height: 18px; border-radius: 4px; overflow: hidden; background: #E2E8F0; width: 100%; max-width: 220px; box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);">
|
|
${totUnder > 0 ? `<div style="width: ${totUnderPct}%; background: #EF4444; cursor: pointer; transition: opacity 0.15s;" title="사양 부족: ${totUnder}대 (${Math.round(totUnderPct)}%)" class="spec-segment-btn" data-grade="all" data-spec-status="사양 부족" onmouseover="this.style.opacity='0.8'" onmouseout="this.style.opacity='1'"></div>` : ''}
|
|
${totNormal > 0 ? `<div style="width: ${totNormalPct}%; background: #1E5149; cursor: pointer; transition: opacity 0.15s;" title="적정 사양: ${totNormal}대 (${Math.round(totNormalPct)}%)" class="spec-segment-btn" data-grade="all" data-spec-status="적정" onmouseover="this.style.opacity='0.8'" onmouseout="this.style.opacity='1'"></div>` : ''}
|
|
${totOver > 0 ? `<div style="width: ${totOverPct}%; background: #F59E0B; cursor: pointer; transition: opacity 0.15s;" title="오버 스펙: ${totOver}대 (${Math.round(totOverPct)}%)" class="spec-segment-btn" data-grade="all" data-spec-status="오버스펙" onmouseover="this.style.opacity='0.8'" onmouseout="this.style.opacity='1'"></div>` : ''}
|
|
</div>
|
|
<div style="display: flex; gap: 8px; font-size: 0.8rem; font-weight: 750; color: #64748B;">
|
|
${totUnder > 0 ? `<span style="color: #EF4444; cursor: pointer;" class="spec-text-btn" data-grade="all" data-spec-status="사양 부족">부족 ${totUnder}</span>` : ''}
|
|
${totNormal > 0 ? `<span style="color: #1E5149; cursor: pointer;" class="spec-text-btn" data-grade="all" data-spec-status="적정">적정 ${totNormal}</span>` : ''}
|
|
${totOver > 0 ? `<span style="color: #F59E0B; cursor: pointer;" class="spec-text-btn" data-grade="all" data-spec-status="오버스펙">오버 ${totOver}</span>` : ''}
|
|
</div>
|
|
</div>
|
|
`;
|
|
} else {
|
|
totBarGraphHtml = `<span style="font-size: 0.9rem; color: #94A3B8; font-weight: 500;">운영중 자산 없음</span>`;
|
|
}
|
|
|
|
const cellStyleHeader = `padding: 10px 8px; text-align: center; font-weight: 800; cursor: pointer; transition: background 0.2s; background: #F8FAFC; font-size: 1.1rem;`;
|
|
const hoverEventsHeader = `onmouseover="this.style.background='#EEF2F6'" onmouseout="this.style.background='#F8FAFC'"`;
|
|
|
|
matrixTbody.innerHTML = `
|
|
${renderMatrixRow('premium', '최상급 PC (85점 이상)', '#11302B', premiumShortage)}
|
|
${renderMatrixRow('high', '상급 PC (70점 ~ 85점)', '#1E8E7C', highShortage)}
|
|
${renderMatrixRow('normal', '중급 PC (40점 ~ 70점)', '#10B981', normalShortage)}
|
|
${renderMatrixRow('entry', '보급 PC (20점 ~ 40점)', '#F59E0B', entryShortage)}
|
|
${renderMatrixRow('replace', '교체 대상 PC (20점 미만 또는 Win11 불가)', '#EF4444', replaceShortage)}
|
|
<tr style="background: #F8FAFC; border-top: 2px solid #E2E8F0; font-weight: 800;">
|
|
<td style="padding: 10px 8px; color: #1E293B; font-weight: 800; font-size: 1.1rem;">합계 (Total)</td>
|
|
<td class="matrix-cell" data-grade="all" data-type="total" style="${cellStyleHeader}" ${hoverEventsHeader}>${totalPcs}대 <span style="font-size:0.95rem; color:#64748B; font-weight:600;">(100%)</span></td>
|
|
<td class="matrix-cell" data-grade="all" data-type="active" style="${cellStyleHeader}" ${hoverEventsHeader}>${totalActive}대</td>
|
|
<td class="matrix-cell" data-grade="all" data-type="stock" style="${cellStyleHeader}" ${hoverEventsHeader}>${totalStock}대</td>
|
|
<td class="matrix-cell" data-grade="all" data-type="under" style="${cellStyleHeader} color: #EF4444;" ${hoverEventsHeader}>${totalShortage}대</td>
|
|
<td style="padding: 10px 8px; text-align: center; font-weight: 800; font-size: 1.1rem; background: #F8FAFC; vertical-align: middle;">
|
|
${totBarGraphHtml}
|
|
</td>
|
|
</tr>
|
|
`;
|
|
|
|
// 셀별 동적 클릭 리스너 바인딩
|
|
matrixTbody.querySelectorAll('.matrix-cell').forEach(cell => {
|
|
cell.addEventListener('click', () => {
|
|
const grade = cell.getAttribute('data-grade')!;
|
|
const type = cell.getAttribute('data-type')!;
|
|
|
|
let targetList: any[] = [];
|
|
let title = '';
|
|
|
|
const getGradeLabel = (g: string) => {
|
|
if (g === 'premium') return '최상급 PC';
|
|
if (g === 'high') return '상급 PC';
|
|
if (g === 'normal') return '중급 PC';
|
|
if (g === 'entry') return '보급 PC';
|
|
if (g === 'replace') return '교체 대상 PC';
|
|
return '전체 PC';
|
|
};
|
|
|
|
const getTypeLabel = (t: string) => {
|
|
if (t === 'total') return '보유';
|
|
if (t === 'active') return '운영중';
|
|
if (t === 'stock') return '재고';
|
|
if (t === 'under') return '구매 필요';
|
|
return '';
|
|
};
|
|
|
|
if (grade === 'all') {
|
|
if (type === 'total') {
|
|
targetList = filtered;
|
|
} else if (type === 'active') {
|
|
targetList = filtered.filter(p => !isStock(p));
|
|
} else if (type === 'stock') {
|
|
targetList = filtered.filter(p => isStock(p));
|
|
} else if (type === 'under') {
|
|
targetList = criticalList.filter(p => p._spec_status === '사양 부족');
|
|
}
|
|
} else {
|
|
const data = matrix[grade as keyof typeof matrix];
|
|
if (type === 'total') {
|
|
targetList = data.pcs;
|
|
} else if (type === 'active') {
|
|
targetList = data.activePcs;
|
|
} else if (type === 'stock') {
|
|
targetList = data.stockPcs;
|
|
} else if (type === 'under') {
|
|
targetList = data.underPcs;
|
|
}
|
|
}
|
|
|
|
title = `${getGradeLabel(grade)} - ${getTypeLabel(type)} 자산 목록`;
|
|
showMiniListModal(title, targetList);
|
|
});
|
|
});
|
|
|
|
// 바그래프 세그먼트 또는 텍스트 클릭 리스너 설정
|
|
const handleSpecClick = (e: Event) => {
|
|
e.stopPropagation();
|
|
const target = e.currentTarget as HTMLElement;
|
|
const grade = target.getAttribute('data-grade')!;
|
|
const status = target.getAttribute('data-spec-status')!;
|
|
|
|
let targetPcs: any[] = [];
|
|
if (grade === 'all') {
|
|
targetPcs = filtered.filter(p => !isStock(p) && p._spec_status === status);
|
|
} else {
|
|
const data = matrix[grade as keyof typeof matrix];
|
|
targetPcs = data.activePcs.filter(p => p._spec_status === status);
|
|
}
|
|
|
|
const getGradeLabel = (g: string) => {
|
|
if (g === 'premium') return '최상급 PC';
|
|
if (g === 'high') return '상급 PC';
|
|
if (g === 'normal') return '중급 PC';
|
|
if (g === 'entry') return '보급 PC';
|
|
if (g === 'replace') return '교체 대상 PC';
|
|
return '전체 PC';
|
|
};
|
|
|
|
const title = `${getGradeLabel(grade)} - ${status} 자산 목록`;
|
|
showMiniListModal(title, targetPcs);
|
|
};
|
|
|
|
matrixTbody.querySelectorAll('.spec-segment-btn, .spec-text-btn').forEach(btn => {
|
|
btn.addEventListener('click', handleSpecClick);
|
|
});
|
|
|
|
// 7. 연도별 PC 노후도 집계 및 렌더링
|
|
const agingCounts = {
|
|
immediate: [] as any[], // 7년 이상
|
|
review: [] as any[], // 3년 이상 7년 미만
|
|
normal: [] as any[], // 1년 이상 3년 미만
|
|
fresh: [] as any[] // 1년 미만
|
|
};
|
|
|
|
filtered.forEach((p: any) => {
|
|
const age = calculateAssetAge(p.purchase_date);
|
|
if (age >= 7.0) {
|
|
agingCounts.immediate.push(p);
|
|
} else if (age >= 3.0) {
|
|
agingCounts.review.push(p);
|
|
} else if (age >= 1.0) {
|
|
agingCounts.normal.push(p);
|
|
} else {
|
|
agingCounts.fresh.push(p);
|
|
}
|
|
});
|
|
|
|
const agingTbody = document.getElementById('pc-aging-tbody')!;
|
|
|
|
const renderAgingRow = (label: string, list: any[], badgeText: string, badgeStyle: string, ageGroupKey: string) => {
|
|
return `
|
|
<tr style="border-bottom:1px solid #F1F5F9; cursor:pointer; transition: background 0.2s;" class="aging-row" data-group="${ageGroupKey}" onmouseover="this.style.background='#F8FAFC'" onmouseout="this.style.background='none'">
|
|
<td style="padding:6px 8px; font-weight:700; color:#334155; font-size: 0.95rem;">${label}</td>
|
|
<td style="padding:6px 8px; text-align:center; font-weight:700; color:#334155; font-size: 0.95rem;">${list.length}대</td>
|
|
<td style="padding:6px 8px; text-align:center;">
|
|
<span style="padding:2px 6px; border-radius:4px; font-size:12px; font-weight:800; ${badgeStyle}">${badgeText}</span>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
};
|
|
|
|
agingTbody.innerHTML = `
|
|
${renderAgingRow('즉시 교체 (7년 이상)', agingCounts.immediate, '즉시 교체', 'background:#FFF1F2; color:#EF4444; border:1px solid #FCA5A5;', 'immediate')}
|
|
${renderAgingRow('교체 검토 (3년 ~ 7년)', agingCounts.review, '교체 검토', 'background:#FFF7ED; color:#D97706; border:1px solid #FCD34D;', 'review')}
|
|
${renderAgingRow('정상 운용 (1년 ~ 3년)', agingCounts.normal, '정상 운용', 'background:#ECFDF5; color:#059669; border:1px solid #A7F3D0;', 'normal')}
|
|
${renderAgingRow('최신 도입 (1년 미만)', agingCounts.fresh, '최신 도입', 'background:#F0FDF4; color:#16A34A; border:1px solid #BBF7D0;', 'fresh')}
|
|
`;
|
|
|
|
agingTbody.querySelectorAll('.aging-row').forEach(row => {
|
|
row.addEventListener('click', () => {
|
|
const groupKey = row.getAttribute('data-group') as any;
|
|
const groupList = agingCounts[groupKey as keyof typeof agingCounts];
|
|
const groupLabels = {
|
|
immediate: '즉시 교체 대상 (7년 이상)',
|
|
review: '교체 검토 대상 (3년 ~ 7년)',
|
|
normal: '정상 운용 장비 (1년 ~ 3년)',
|
|
fresh: '최신 도입 장비 (1년 미만)'
|
|
};
|
|
showMiniListModal(groupLabels[groupKey as keyof typeof groupLabels], groupList);
|
|
});
|
|
});
|
|
|
|
// 8. 요약 지표 카드 클릭 리스너 설정
|
|
const bindCardClick = (id: string, gradeTitle: string, filterFn: (p: any) => boolean) => {
|
|
const card = document.getElementById(id)!;
|
|
if (!card) return;
|
|
card.style.cursor = 'pointer';
|
|
card.style.transition = 'opacity 0.2s';
|
|
|
|
card.onmouseover = () => { card.style.opacity = '0.7'; };
|
|
card.onmouseout = () => { card.style.opacity = '1'; };
|
|
|
|
card.onclick = () => {
|
|
const pcsInGrade = filtered.filter(filterFn);
|
|
showMiniListModal(gradeTitle, pcsInGrade);
|
|
};
|
|
};
|
|
|
|
// 사양 부족 / 오버 스펙 / 윈도우 11 불가 클릭 리스너 설정
|
|
bindCardClick('card-under-spec', '사양 부족 대상', p => p._spec_status === '사양 부족');
|
|
bindCardClick('card-over-spec', '오버 스펙 대상', p => p._spec_status === '오버스펙');
|
|
bindCardClick('card-win11-incompatible', '윈도우 11 업그레이드 불가 PC', p => isWindows11Incompatible(p.cpu, p.ram));
|
|
|
|
// 10. 도넛 차트 렌더링 호출
|
|
renderDonutChart(matrix.premium.total, matrix.high.total, matrix.normal.total, matrix.entry.total, matrix.replace.total);
|
|
|
|
// 전역 상태 등록
|
|
state.activeCharts = [donutChartInstance];
|
|
}
|
|
|
|
/**
|
|
* 등급 클릭 시 열리는 심플 미니 리스트 모달 (라이트 글래스 헤더 적용)
|
|
*/
|
|
function showMiniListModal(title: string, list: any[]) {
|
|
const oldModal = document.getElementById('dashboard-mini-modal');
|
|
if (oldModal) oldModal.remove();
|
|
|
|
const modal = document.createElement('div');
|
|
modal.id = 'dashboard-mini-modal';
|
|
modal.style.cssText = `
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100vw;
|
|
height: 100vh;
|
|
background: rgba(15, 23, 42, 0.4);
|
|
backdrop-filter: blur(4px);
|
|
z-index: 1000;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-family: 'Pretendard', sans-serif;
|
|
color: #1E293B;
|
|
`;
|
|
|
|
modal.innerHTML = `
|
|
<div style="background: white; border-radius: 12px; width: 800px; max-width: 95%; max-height: 80%; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15); overflow: hidden; border: 1px solid #E2E8F0; animation: modalFadeIn 0.2s ease-out; color: #1E293B;">
|
|
<div style="padding: 1.25rem 1.75rem; border-bottom: 1px solid #F1F5F9; display: flex; justify-content: space-between; align-items: center; background: #F8FAFC;">
|
|
<h3 style="margin: 0; font-size: 1.26rem; font-weight: 850; color: #1E5149; display: flex; align-items: center; gap: 0.5rem;">
|
|
<span style="display:inline-block; width:8px; height:8px; border-radius:50%; background:#1E5149;"></span>
|
|
${title} 자산 목록
|
|
<span style="font-size: 0.96rem; font-weight: 700; color: white; background: #1E5149; padding: 2px 8px; border-radius: 9999px; margin-left: 0.25rem;">${list.length}대</span>
|
|
</h3>
|
|
<button id="btn-close-mini-modal" style="background: none; border: none; font-size: 1.25rem; color: #94A3B8; cursor: pointer; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 6px; transition: background 0.2s;" onmouseover="this.style.background='#EEF2F6'; this.style.color='#1E5149';" onmouseout="this.style.background='none'; this.style.color='#94A3B8';">
|
|
×
|
|
</button>
|
|
</div>
|
|
<div style="padding: 0 1.75rem 1rem 1.75rem; overflow-y: auto; flex: 1;">
|
|
<table style="width: 100%; border-collapse: collapse; text-align: left; font-size: 1.01rem; table-layout: fixed;">
|
|
<thead style="position: sticky; top: 0; background: white; z-index: 10;">
|
|
<tr style="border-bottom: 2px solid #E2E8F0; color: #64748B; font-weight: 800; background: white;">
|
|
<th style="padding: 10px 4px; width: 14%; background: white;">사용자</th>
|
|
<th style="padding: 10px 4px; width: 25%; background: white;">조직 (직무)</th>
|
|
<th style="padding: 10px 4px; width: 28%; background: white;">주요 사양</th>
|
|
<th style="padding: 10px 4px; width: 18%; text-align: center; background: white;">등급 (점수)</th>
|
|
<th style="padding: 10px 4px; text-align: center; background: white;">자산코드</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
${list.length === 0
|
|
? `<tr><td colspan="5" style="text-align:center; padding:3rem; color:#94A3B8; font-weight:500;">해당 등급의 자산이 없습니다.</td></tr>`
|
|
: list.map(pc => {
|
|
const spec = `${pc.cpu || ''} / ${pc.ram || ''} / ${pc.gpu || '-'}`;
|
|
const user = pc.user_current || '(재고)';
|
|
const score = pc._pc_score !== undefined ? pc._pc_score : calculatePcScoreDeductive(pc.cpu, pc.ram, pc.gpu, pc.purchase_date);
|
|
const win11Incompatible = isWindows11Incompatible(pc.cpu, pc.ram);
|
|
const grade = getPcGrade(score, win11Incompatible);
|
|
const badgeHTML = `<span class="badge ${grade.class}" style="font-size: 11px; padding: 2px 6px;">${grade.name}</span>`;
|
|
const scoreHTML = `<strong style="color: ${grade.color}; font-size: 13px; margin-left: 4px;">${score}점</strong>`;
|
|
|
|
return `
|
|
<tr style="border-bottom: 1px solid #F1F5F9; cursor: pointer; transition: background 0.2s;" class="mini-modal-row" data-id="${pc.id}" onmouseover="this.style.background='#F8FAFC'" onmouseout="this.style.background='none'">
|
|
<td style="padding: 12px 4px; font-weight: 700; color: #334155; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${user}">${user}</td>
|
|
<td style="padding: 12px 4px; color: #475569; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${pc.current_dept || '-'} (${pc.user_position || '-'})">${pc.current_dept || '-'} (${pc.user_position || '-'})</td>
|
|
<td style="padding: 12px 4px; color: #64748B; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${spec}">${spec}</td>
|
|
<td style="padding: 12px 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">${badgeHTML}${scoreHTML}</td>
|
|
<td style="padding: 12px 4px; font-family: monospace; color: #475569; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${pc.asset_code || '-'}">${pc.asset_code || '-'}</td>
|
|
</tr>
|
|
`;
|
|
}).join('')
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div style="padding: 1rem 1.75rem; border-top: 1px solid #F1F5F9; display: flex; justify-content: flex-end; background: #F8FAFC;">
|
|
<button id="btn-confirm-mini-modal" style="padding: 6px 20px; font-size: 1.01rem; font-weight: 700; background: #1E5149; color: white; border: none; border-radius: 6px; cursor: pointer; transition: opacity 0.2s;" onmouseover="this.style.opacity='0.9'" onmouseout="this.style.opacity='1'">
|
|
확인
|
|
</button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
const style = document.createElement('style');
|
|
style.innerHTML = `
|
|
@keyframes modalFadeIn {
|
|
from { transform: scale(0.96); opacity: 0; }
|
|
to { transform: scale(1); opacity: 1; }
|
|
}
|
|
`;
|
|
modal.appendChild(style);
|
|
|
|
document.body.appendChild(modal);
|
|
|
|
const closeModal = () => { modal.remove(); };
|
|
|
|
modal.addEventListener('click', (e) => {
|
|
if (e.target === modal) closeModal();
|
|
});
|
|
|
|
document.getElementById('btn-close-mini-modal')?.addEventListener('click', closeModal);
|
|
document.getElementById('btn-confirm-mini-modal')?.addEventListener('click', closeModal);
|
|
|
|
modal.querySelectorAll('.mini-modal-row').forEach(row => {
|
|
row.addEventListener('click', () => {
|
|
const id = row.getAttribute('data-id');
|
|
const asset = list.find(p => String(p.id) === String(id));
|
|
if (asset) {
|
|
closeModal();
|
|
openHwModal(asset, 'view');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 실시간 사양 적정률 원형 도넛 그래프 (Active Spec Rate)
|
|
*/
|
|
function renderDonutChart(premium: number, high: number, normal: number, entry: number, replace: number) {
|
|
const ctx = document.getElementById('chart-overall-donut') as HTMLCanvasElement;
|
|
if (!ctx || typeof Chart === 'undefined') return;
|
|
|
|
if (donutChartInstance) {
|
|
donutChartInstance.destroy();
|
|
donutChartInstance = null;
|
|
}
|
|
|
|
const total = premium + high + normal + entry + replace;
|
|
|
|
donutChartInstance = new Chart(ctx, {
|
|
type: 'doughnut',
|
|
data: {
|
|
labels: ['최상급', '상급', '중급', '보급', '교체 대상'],
|
|
datasets: [{
|
|
data: [premium, high, normal, entry, replace],
|
|
backgroundColor: [
|
|
'#11302B', // premium (Hanmac Dark Green)
|
|
'#1E8E7C', // high (Hanmac Teal)
|
|
'#10B981', // normal (Hanmac Mint)
|
|
'#F59E0B', // entry (Yellow-Orange)
|
|
'#EF4444' // replace (Red)
|
|
],
|
|
borderColor: '#ffffff',
|
|
borderWidth: 2
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
cutout: '70%',
|
|
plugins: {
|
|
legend: { display: false },
|
|
tooltip: {
|
|
titleFont: { family: 'Pretendard', size: 12 },
|
|
bodyFont: { family: 'Pretendard', size: 12 },
|
|
callbacks: {
|
|
label: (context: any) => `${context.label}: ${context.raw}대`
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// 도넛 차트 중앙에 총 자산 대수 텍스트 오버레이 배치
|
|
const parent = ctx.parentElement!;
|
|
let textOverlay = parent.querySelector('.donut-text-overlay') as HTMLElement;
|
|
if (!textOverlay) {
|
|
textOverlay = document.createElement('div');
|
|
textOverlay.className = 'donut-text-overlay';
|
|
textOverlay.style.cssText = `
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -46%);
|
|
font-size: 1.65rem;
|
|
font-weight: 900;
|
|
color: #1E5149;
|
|
font-family: 'Pretendard', sans-serif;
|
|
pointer-events: none;
|
|
white-space: nowrap;
|
|
`;
|
|
parent.appendChild(textOverlay);
|
|
}
|
|
textOverlay.textContent = `총 ${total}대`;
|
|
}
|