feat(asset): add photos, monitor links and deletion
Apply asset_db_002_photos_monitors.sql before rebuilding web. Restrict soft deletion to the super admin; retain reports and audit.
This commit is contained in:
@@ -1,3 +1,86 @@
|
||||
.am-monitor-summary {
|
||||
margin: 18px 0;
|
||||
padding: 20px;
|
||||
border: 1px solid #e7e7e7;
|
||||
border-radius: 12px;
|
||||
}
|
||||
.am-monitor-summary h3 {
|
||||
margin: 0 0 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #737373;
|
||||
}
|
||||
.am-monitor-grid,
|
||||
.am-photo-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
.am-monitor-card {
|
||||
min-width: 0;
|
||||
padding: 16px;
|
||||
background: #fafafa;
|
||||
border-radius: 10px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.am-monitor-card > strong,
|
||||
.am-monitor-card > small {
|
||||
display: block;
|
||||
}
|
||||
.am-monitor-card > small {
|
||||
color: #737373;
|
||||
margin: 8px 0 14px;
|
||||
}
|
||||
.am-linked-overview {
|
||||
border-top: 1px solid #e7e7e7;
|
||||
padding-top: 12px;
|
||||
}
|
||||
.am-linked-overview h4 {
|
||||
margin: 12px 0 8px;
|
||||
}
|
||||
.am-linked-overview p {
|
||||
font-size: 12px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
.am-monitor-candidate {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.am-monitor-candidate small {
|
||||
display: block;
|
||||
color: #737373;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.am-photo-grid a {
|
||||
display: block;
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
min-width: 0;
|
||||
}
|
||||
.am-photo-grid img {
|
||||
width: 100%;
|
||||
height: 180px;
|
||||
object-fit: contain;
|
||||
border: 1px solid #e7e7e7;
|
||||
border-radius: 10px;
|
||||
background: #fafafa;
|
||||
}
|
||||
.am-photo-grid small {
|
||||
display: block;
|
||||
margin-top: 7px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.am-danger {
|
||||
color: white;
|
||||
background: #b42318;
|
||||
border-color: #b42318;
|
||||
}
|
||||
.am-danger-outline {
|
||||
color: #b42318;
|
||||
}
|
||||
.erp-page:has(.am-workspace) {
|
||||
padding: 0;
|
||||
max-width: none;
|
||||
|
||||
+232
-5
@@ -6,6 +6,7 @@
|
||||
if (!app) return;
|
||||
const { categories, statuses } = JSON.parse($("am-config").textContent);
|
||||
const configured = app.dataset.configured === "true";
|
||||
const canDelete = app.dataset.canDelete === "true";
|
||||
const names = {
|
||||
create: "자산 등록",
|
||||
update: "정보 수정",
|
||||
@@ -16,6 +17,9 @@
|
||||
lost: "분실 처리",
|
||||
retired: "폐기 처리",
|
||||
report: "사양 보고서 등록",
|
||||
photo: "사진 등록",
|
||||
monitor: "모니터 자산 연결",
|
||||
delete: "자산 삭제",
|
||||
};
|
||||
const fieldNames = {
|
||||
tag: "자산번호",
|
||||
@@ -320,6 +324,25 @@
|
||||
function summaryCards(s) {
|
||||
return `<div class="am-spec-cards"><div class="am-spec-card"><span>프로세서 / CPU</span><strong>${esc(s.cpu || "정보 없음")}</strong><small>${esc(s.cores || "—")} 코어 · ${esc(s.threads || "—")} 스레드</small></div><div class="am-spec-card"><span>메모리 / RAM</span><strong>${esc(s.memory || "정보 없음")}</strong><small>설치된 전체 메모리</small></div><div class="am-spec-card"><span>그래픽 / GPU</span><strong>${esc(s.gpu || "정보 없음")}</strong><small>${esc(s.gpu_memory)}</small></div><div class="am-spec-card"><span>저장장치 / STORAGE</span><strong>${s.drive_count ?? 0}개 드라이브</strong><small>내장 · 외장 드라이브 포함</small></div></div>`;
|
||||
}
|
||||
// 같은 모델의 다른 모니터는 자동 연결하지 않고 자산번호로 직접 확인합니다.
|
||||
function monitorCards(report) {
|
||||
const monitors = state.reportView
|
||||
? state.reportView.monitors || []
|
||||
: state.detail.monitors || [];
|
||||
if (!monitors.length)
|
||||
return '<section class="am-monitor-summary"><h3>모니터 / MONITOR</h3><p class="am-muted">보고서에 모니터 정보가 없습니다.</p></section>';
|
||||
const current = report.id === state.detail.asset.latest_report_id;
|
||||
return `<section class="am-monitor-summary"><h3>모니터 / MONITOR <span class="am-badge">${monitors.length}개</span></h3><div class="am-monitor-grid">${monitors
|
||||
.map((m) => {
|
||||
const a = m.asset;
|
||||
return `<article class="am-monitor-card"><strong>${esc(m.name)}</strong><small>${esc(m.model)}${m.serial ? " · 시리얼 " + esc(m.serial) : " · 시리얼 미기록"}</small>${a ? `<div class="am-linked-overview"><span class="am-badge">등록된 자산</span><h4>${esc(a.name)}</h4><p>${esc(a.tag)} · ${esc(a.location || "위치 미지정")}<br>${esc(userName(a.assignee_email))} · ${esc(statuses[a.status])}<br>구매 ${money(a.purchase_cost)} · 보증 ${esc(a.warranty_until || "미입력")}</p><button class="am-text-btn" data-monitor-open="${esc(a.id)}">자산 개요 보기 ↗</button></div>` : `<p class="am-muted">${m.candidates?.length ? "같은 시리얼 또는 모델의 자산이 있습니다. 실제 장비를 확인하세요." : "연결된 자산이 없습니다."}</p>${current ? (m.candidates || []).map((c) => `<div class="am-monitor-candidate"><span>${esc(c.tag)} · ${esc(c.name)}<small>${esc(c.serial || "시리얼 미기록")} · ${esc(c.location || "위치 미지정")}</small></span><button class="am-text-btn" data-monitor-link="${m.index}" data-target="${esc(c.id)}">이 자산 연결</button></div>`).join("") + `<button class="erp-btn erp-btn-outline" data-monitor-create="${m.index}">+ 모니터 자산으로 등록</button>` : '<p class="am-muted">모니터 등록·연결은 최신 보고서에서 진행하세요.</p>'}`}</article>`;
|
||||
})
|
||||
.join("")}</div></section>`;
|
||||
}
|
||||
function photoGallery(a) {
|
||||
const photos = state.detail.photos || [];
|
||||
return `<section class="am-detail-section"><div class="am-panel-head"><h3 class="am-section-title">자산 사진 <span class="am-badge">${photos.length}/10</span></h3><button class="erp-btn erp-btn-outline" data-photo ${photos.length >= 10 ? "disabled" : ""}>+ 사진 등록</button></div>${photos.length ? `<div class="am-photo-grid">${photos.map((p) => `<a href="/asset/api/assets/${encodeURIComponent(a.id)}/photos/${encodeURIComponent(p.id)}" target="_blank" rel="noopener"><img src="/asset/api/assets/${encodeURIComponent(a.id)}/photos/${encodeURIComponent(p.id)}" alt="${esc(p.filename)}" loading="lazy"><small>${esc(p.filename)}</small></a>`).join("")}</div>` : '<p class="am-muted">자산의 외관이나 시리얼 라벨 사진을 등록하세요.</p>'}</section>`;
|
||||
}
|
||||
// 많은 기술 항목 중 용량·속도·시리얼을 먼저 보여주고, 전체 보고서는 아래에 보존합니다.
|
||||
function componentCards(parsed) {
|
||||
const groups = {
|
||||
@@ -477,6 +500,14 @@
|
||||
.join("") +
|
||||
'<p class="am-form-hint">최근 200개 이력을 표시합니다. 전체 이력은 저장소에 보존됩니다.</p>';
|
||||
}
|
||||
if (state.tab === "overview") body = photoGallery(a) + body;
|
||||
if (report && ["overview", "specs"].includes(state.tab)) {
|
||||
// 모니터도 CPU/RAM/GPU/저장장치 바로 다음에 핵심 사양으로 표시합니다.
|
||||
body = body.replace(
|
||||
summaryCards(report.parsed.summary),
|
||||
summaryCards(report.parsed.summary) + monitorCards(report),
|
||||
);
|
||||
}
|
||||
if (state.tab === "specs" && report)
|
||||
body = body.replace(
|
||||
'<div class="am-spec-tools">',
|
||||
@@ -488,7 +519,7 @@
|
||||
'<p class="am-warning">선택한 보고서의 사양입니다. 현재 자산의 최신 보고서는 변경되지 않습니다.</p>' +
|
||||
body;
|
||||
$("am-detail-content").innerHTML =
|
||||
`<div class="am-detail-body"><div class="am-detail-actions">${badge(a.status)}${actionButtons(a)}<button class="erp-btn erp-btn-outline" data-edit>정보 수정</button></div></div><nav class="am-tabs" aria-label="자산 상세 보기">${Object.entries(
|
||||
`<div class="am-detail-body"><div class="am-detail-actions">${state.returnComputer && a.category === "monitor" ? `<button class="am-text-btn" data-return-computer="${esc(state.returnComputer)}">← 컴퓨터 사양으로</button>` : ""}${badge(a.status)}${actionButtons(a)}<button class="erp-btn erp-btn-outline" data-edit>정보 수정</button>${canDelete ? '<button class="erp-btn erp-btn-outline am-danger-outline" data-delete>자산 삭제</button>' : ""}</div></div><nav class="am-tabs" aria-label="자산 상세 보기">${Object.entries(
|
||||
tabs,
|
||||
)
|
||||
.filter(
|
||||
@@ -540,6 +571,9 @@
|
||||
form.reset();
|
||||
clearError(form);
|
||||
state.editing = edit ? structuredClone(state.detail.asset) : null;
|
||||
state.monitorRegistration = null;
|
||||
form.elements.category.disabled = false;
|
||||
form.elements.serial.readOnly = false;
|
||||
$("am-editor-title").textContent = edit ? "자산 정보 수정" : "자산 등록";
|
||||
if (edit)
|
||||
for (const input of form.elements)
|
||||
@@ -576,16 +610,33 @@
|
||||
clearError(form);
|
||||
try {
|
||||
const body = assetPayload(form);
|
||||
if (state.monitorRegistration) body.category = "monitor";
|
||||
if (state.editing) body.version = state.editing.version;
|
||||
const result = await api(
|
||||
state.editing ? "assets/" + state.editing.id : "assets",
|
||||
{ method: state.editing ? "PUT" : "POST", body },
|
||||
state.monitorRegistration
|
||||
? `assets/${state.monitorRegistration.computer.id}/monitors/${state.monitorRegistration.index}`
|
||||
: state.editing
|
||||
? "assets/" + state.editing.id
|
||||
: "assets",
|
||||
{
|
||||
method: state.editing ? "PUT" : "POST",
|
||||
body: state.monitorRegistration
|
||||
? {
|
||||
asset: body,
|
||||
version: state.monitorRegistration.computer.version,
|
||||
report_id: state.monitorRegistration.reportId,
|
||||
}
|
||||
: body,
|
||||
},
|
||||
);
|
||||
const id = state.editing?.id || result.id;
|
||||
form.dataset.busy = "false";
|
||||
close("am-editor");
|
||||
message("자산 정보를 저장했습니다.");
|
||||
await afterSave(id);
|
||||
await afterSave(
|
||||
state.monitorRegistration?.computer.id || id,
|
||||
state.monitorRegistration ? "specs" : "overview",
|
||||
);
|
||||
} catch (error) {
|
||||
formError(form, error);
|
||||
} finally {
|
||||
@@ -764,15 +815,161 @@
|
||||
const assetId = state.detail.asset.id,
|
||||
seq = ++state.detailSeq;
|
||||
try {
|
||||
const report = await api(`assets/${assetId}/reports/${id}`);
|
||||
const [report, monitors] = await Promise.all([
|
||||
api(`assets/${assetId}/reports/${id}`),
|
||||
api(`assets/${assetId}/reports/${id}/monitors`),
|
||||
]);
|
||||
if (seq !== state.detailSeq || !$("am-detail").open) return;
|
||||
state.reportView = report;
|
||||
state.reportView.monitors = monitors.items;
|
||||
state.tab = "specs";
|
||||
renderDetail();
|
||||
} catch (error) {
|
||||
message(error.message, true);
|
||||
}
|
||||
}
|
||||
function openMonitorEditor(index) {
|
||||
const monitor = (state.detail.monitors || []).find(
|
||||
(m) => m.index === index,
|
||||
);
|
||||
if (!monitor) return;
|
||||
openEditor();
|
||||
const form = $("am-editor-form"),
|
||||
computer = structuredClone(state.detail.asset);
|
||||
state.monitorRegistration = {
|
||||
index,
|
||||
computer,
|
||||
reportId: computer.latest_report_id,
|
||||
};
|
||||
$("am-editor-title").textContent = "모니터 자산 등록";
|
||||
for (const [key, value] of Object.entries({
|
||||
name: monitor.name,
|
||||
category: "monitor",
|
||||
model: monitor.model,
|
||||
manufacturer: monitor.manufacturer,
|
||||
serial: monitor.serial,
|
||||
location: computer.location,
|
||||
department: computer.department,
|
||||
}))
|
||||
form.elements[key].value = value || "";
|
||||
form.elements.category.disabled = true;
|
||||
form.elements.serial.readOnly = Boolean(monitor.serial);
|
||||
}
|
||||
async function linkMonitor(button) {
|
||||
const computer = structuredClone(state.detail.asset);
|
||||
button.disabled = true;
|
||||
try {
|
||||
await api(
|
||||
`assets/${computer.id}/monitors/${button.dataset.monitorLink}`,
|
||||
{
|
||||
method: "POST",
|
||||
body: {
|
||||
version: computer.version,
|
||||
report_id: computer.latest_report_id,
|
||||
asset_id: button.dataset.target,
|
||||
},
|
||||
},
|
||||
);
|
||||
await afterSave(computer.id, "specs");
|
||||
message("모니터 자산을 연결했습니다.");
|
||||
} catch (error) {
|
||||
message(error.message, true);
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
function openPhoto() {
|
||||
state.photoAsset = structuredClone(state.detail.asset);
|
||||
const form = $("am-photo-form");
|
||||
form.reset();
|
||||
clearError(form);
|
||||
show("am-photo");
|
||||
}
|
||||
async function savePhoto(event) {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget,
|
||||
button = form.querySelector('[type="submit"]');
|
||||
if (form.dataset.busy === "true" || !form.reportValidity()) return;
|
||||
const file = $("am-photo-file").files[0];
|
||||
if (file.size > 8 * 1024 * 1024) {
|
||||
formError(form, new Error("사진은 8 MB 이하로 선택하세요."));
|
||||
return;
|
||||
}
|
||||
form.dataset.busy = "true";
|
||||
button.disabled = true;
|
||||
clearError(form);
|
||||
try {
|
||||
const body = new FormData();
|
||||
body.append("file", file);
|
||||
body.append("version", state.photoAsset.version);
|
||||
await api(`assets/${state.photoAsset.id}/photos`, {
|
||||
method: "POST",
|
||||
body,
|
||||
});
|
||||
form.dataset.busy = "false";
|
||||
close("am-photo");
|
||||
await afterSave(state.photoAsset.id);
|
||||
message("사진을 등록했습니다.");
|
||||
} catch (error) {
|
||||
formError(form, error);
|
||||
} finally {
|
||||
form.dataset.busy = "false";
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
function openDelete() {
|
||||
if (!canDelete) return;
|
||||
state.deleteAsset = structuredClone(state.detail.asset);
|
||||
const form = $("am-delete-form");
|
||||
form.reset();
|
||||
clearError(form);
|
||||
$("am-delete-hint").textContent =
|
||||
`${state.deleteAsset.tag} · ${state.deleteAsset.name}을(를) 삭제합니다.`;
|
||||
$("am-delete-confirm").placeholder = state.deleteAsset.tag;
|
||||
show("am-delete");
|
||||
}
|
||||
async function saveDelete(event) {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget,
|
||||
button = form.querySelector('[type="submit"]');
|
||||
if (form.dataset.busy === "true" || !form.reportValidity()) return;
|
||||
if ($("am-delete-confirm").value.trim() !== state.deleteAsset.tag) {
|
||||
formError(form, new Error("자산번호를 정확하게 입력하세요."));
|
||||
return;
|
||||
}
|
||||
form.dataset.busy = "true";
|
||||
button.disabled = true;
|
||||
clearError(form);
|
||||
try {
|
||||
await api(`assets/${state.deleteAsset.id}`, {
|
||||
method: "DELETE",
|
||||
body: {
|
||||
version: state.deleteAsset.version,
|
||||
note: $("am-delete-note").value.trim(),
|
||||
},
|
||||
});
|
||||
form.dataset.busy = "false";
|
||||
close("am-delete");
|
||||
close("am-detail");
|
||||
state.page = 1;
|
||||
message("자산을 삭제했습니다.");
|
||||
try {
|
||||
await refresh();
|
||||
} catch (error) {
|
||||
message(
|
||||
"삭제는 완료됐지만 목록을 갱신하지 못했습니다. " + error.message,
|
||||
true,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
formError(form, error);
|
||||
} finally {
|
||||
form.dataset.busy = "false";
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
$("am-photo-form").addEventListener("submit", savePhoto);
|
||||
$("am-delete-form").addEventListener("submit", saveDelete);
|
||||
function resetFilters() {
|
||||
$("am-filters").reset();
|
||||
state.group = "";
|
||||
@@ -787,9 +984,37 @@
|
||||
return;
|
||||
}
|
||||
if (button.dataset.open) {
|
||||
state.returnComputer = null;
|
||||
openDetail(button.dataset.open, button.dataset.tab || "overview");
|
||||
return;
|
||||
}
|
||||
if (button.hasAttribute("data-photo")) {
|
||||
openPhoto();
|
||||
return;
|
||||
}
|
||||
if (button.hasAttribute("data-delete")) {
|
||||
openDelete();
|
||||
return;
|
||||
}
|
||||
if (button.hasAttribute("data-monitor-create")) {
|
||||
openMonitorEditor(Number(button.dataset.monitorCreate));
|
||||
return;
|
||||
}
|
||||
if (button.hasAttribute("data-monitor-link")) {
|
||||
linkMonitor(button);
|
||||
return;
|
||||
}
|
||||
if (button.dataset.monitorOpen) {
|
||||
state.returnComputer = state.detail.asset.id;
|
||||
openDetail(button.dataset.monitorOpen);
|
||||
return;
|
||||
}
|
||||
if (button.dataset.returnComputer) {
|
||||
const id = button.dataset.returnComputer;
|
||||
state.returnComputer = null;
|
||||
openDetail(id, "specs");
|
||||
return;
|
||||
}
|
||||
if (button.hasAttribute("data-create")) {
|
||||
openEditor();
|
||||
return;
|
||||
@@ -870,6 +1095,8 @@
|
||||
"am-action",
|
||||
"am-upload",
|
||||
"am-help",
|
||||
"am-photo",
|
||||
"am-delete",
|
||||
])
|
||||
$(id).addEventListener("cancel", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user