feat(asset): animate asset detail drawer
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
{% set force_sidebar_collapsed = true %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/asset.css?v=20261006b">{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/asset.css?v=20261006c">{% endblock %}
|
||||
{% block content %}
|
||||
<div id="asset-app" class="am-workspace" data-csrf="{{ csrf_token }}" data-configured="{{ 'true' if configured else 'false' }}" data-can-delete="{{ 'true' if can_delete else 'false' }}">
|
||||
<aside class="am-nav" aria-label="자산관리 탐색">
|
||||
@@ -67,4 +67,4 @@
|
||||
<dialog id="am-photo" class="am-dialog" aria-labelledby="am-photo-title"><div class="am-dialog-head"><h2 id="am-photo-title">자산 사진 등록</h2><button type="button" class="am-close" data-close="am-photo" aria-label="사진 등록 닫기">×</button></div><form id="am-photo-form" class="am-form"><p class="am-form-hint">JPG · PNG · WebP, 파일당 8 MB 이하 · 자산당 최대 10장. 촬영 위치 정보는 제거해 보관합니다.</p><label>사진 선택<input id="am-photo-file" type="file" accept="image/jpeg,image/png,image/webp" required></label><div class="am-form-error" role="alert" hidden></div><div class="am-dialog-footer"><button type="button" class="erp-btn erp-btn-outline" data-close="am-photo">취소</button><button type="submit" class="erp-btn erp-btn-primary">사진 저장</button></div></form></dialog>
|
||||
<dialog id="am-delete" class="am-dialog" aria-labelledby="am-delete-title"><div class="am-dialog-head"><h2 id="am-delete-title">자산 삭제</h2><button type="button" class="am-close" data-close="am-delete" aria-label="삭제 창 닫기">×</button></div><form id="am-delete-form" class="am-form"><p class="am-warning" id="am-delete-hint"></p><p class="am-form-hint">자산대장과 현황에서 제외됩니다. 사진·보고서·처리 이력은 보존됩니다.</p><label>삭제할 자산번호 확인<input id="am-delete-confirm" required autocomplete="off"></label><label>삭제 사유<textarea id="am-delete-note" required maxlength="2000" rows="3"></textarea></label><div class="am-form-error" role="alert" hidden></div><div class="am-dialog-footer"><button type="button" class="erp-btn erp-btn-outline" data-close="am-delete">취소</button><button type="submit" class="erp-btn am-danger">자산 삭제</button></div></form></dialog>
|
||||
{% endblock %}
|
||||
{% block scripts %}<script id="am-config" type="application/json">{{ {"categories":categories,"statuses":statuses}|tojson }}</script><script src="/static/asset.js?v=20261006b" defer></script>{% endblock %}
|
||||
{% block scripts %}<script id="am-config" type="application/json">{{ {"categories":categories,"statuses":statuses}|tojson }}</script><script src="/static/asset.js?v=20261006c" defer></script>{% endblock %}
|
||||
|
||||
@@ -683,11 +683,21 @@
|
||||
max-height: 100dvh;
|
||||
border-radius: 14px 0 0 14px;
|
||||
overflow: auto;
|
||||
will-change: transform;
|
||||
}
|
||||
.am-drawer.am-closing {
|
||||
pointer-events: none;
|
||||
}
|
||||
.am-dialog::backdrop,
|
||||
.am-drawer::backdrop {
|
||||
background: #0004;
|
||||
}
|
||||
.am-drawer::backdrop {
|
||||
transition: background-color 220ms ease;
|
||||
}
|
||||
.am-drawer.am-closing::backdrop {
|
||||
background: #0000;
|
||||
}
|
||||
body:has(dialog[open]) {
|
||||
overflow: hidden;
|
||||
}
|
||||
@@ -1352,4 +1362,7 @@ body:has(dialog[open]) {
|
||||
.am-kpi {
|
||||
transition: none;
|
||||
}
|
||||
.am-drawer::backdrop {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
+81
-3
@@ -304,19 +304,71 @@
|
||||
await loadDashboard();
|
||||
await loadList();
|
||||
}
|
||||
let drawerAnimation = null;
|
||||
let drawerMotionId = 0;
|
||||
function moveDrawer(opening) {
|
||||
const drawer = $("am-detail"),
|
||||
motionId = ++drawerMotionId;
|
||||
// 진행 중인 위치에서 방향을 바꾸므로 빠른 열기·닫기에도 패널이 튀지 않습니다.
|
||||
const from =
|
||||
drawerAnimation || !opening
|
||||
? getComputedStyle(drawer).transform
|
||||
: "translateX(100%)";
|
||||
drawerAnimation?.cancel();
|
||||
drawerAnimation = null;
|
||||
drawer.classList.toggle("am-closing", !opening);
|
||||
const finish = () => {
|
||||
if (motionId !== drawerMotionId) return;
|
||||
if (!opening) drawer.close();
|
||||
drawer.classList.remove("am-closing");
|
||||
drawerAnimation?.cancel();
|
||||
drawerAnimation = null;
|
||||
};
|
||||
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
const animation = drawer.animate(
|
||||
[
|
||||
{ transform: from },
|
||||
{ transform: opening ? "translateX(0)" : "translateX(100%)" },
|
||||
],
|
||||
{
|
||||
duration: opening ? 280 : 220,
|
||||
easing: opening
|
||||
? "cubic-bezier(.22,1,.36,1)"
|
||||
: "cubic-bezier(.4,0,1,1)",
|
||||
fill: "both",
|
||||
},
|
||||
);
|
||||
animation.id = "asset-drawer";
|
||||
drawerAnimation = animation;
|
||||
animation.finished.then(finish, () => {});
|
||||
}
|
||||
function show(id) {
|
||||
$(id).showModal();
|
||||
const dialog = $(id);
|
||||
if (id === "am-detail") {
|
||||
if (!dialog.open) {
|
||||
dialog.showModal();
|
||||
moveDrawer(true);
|
||||
} else if (dialog.classList.contains("am-closing")) moveDrawer(true);
|
||||
return;
|
||||
}
|
||||
if (!dialog.open) dialog.showModal();
|
||||
}
|
||||
function close(id) {
|
||||
// 저장 중에는 창을 닫거나 다시 제출해서 요청을 겹치지 않게 합니다.
|
||||
if ($(id).querySelector('form[data-busy="true"]')) return;
|
||||
if (id === "am-detail") {
|
||||
if (!$(id).open || $(id).classList.contains("am-closing")) return;
|
||||
++state.detailSeq;
|
||||
state.detail = null;
|
||||
syncURL();
|
||||
moveDrawer(false);
|
||||
return;
|
||||
}
|
||||
if (id === "am-upload") ++state.previewSeq;
|
||||
$(id).close();
|
||||
if (id === "am-detail") syncURL();
|
||||
}
|
||||
function info(label, value, wide = false) {
|
||||
return `<div class="am-info-field${wide ? " am-wide" : ""}"><span>${esc(label)}</span><strong>${esc(value || "—")}</strong></div>`;
|
||||
@@ -410,7 +462,7 @@
|
||||
const seq = ++state.detailSeq;
|
||||
state.tab = tab;
|
||||
state.reportView = null;
|
||||
if (!$("am-detail").open) show("am-detail");
|
||||
show("am-detail");
|
||||
$("am-detail-title").textContent = "자산 정보";
|
||||
$("am-detail-tag").textContent = "불러오는 중";
|
||||
$("am-detail-content").innerHTML =
|
||||
@@ -979,6 +1031,8 @@
|
||||
document.addEventListener("click", (event) => {
|
||||
const button = event.target.closest("button,a");
|
||||
if (!button) return;
|
||||
// 닫히는 동안 키보드로 이전 패널의 처리 버튼을 실행하지 않게 합니다.
|
||||
if (button.closest("#am-detail.am-closing")) return;
|
||||
if (button.dataset.close) {
|
||||
close(button.dataset.close);
|
||||
return;
|
||||
@@ -1102,6 +1156,30 @@
|
||||
event.preventDefault();
|
||||
close(id);
|
||||
});
|
||||
// 바깥에서 누르고 놓은 경우만 닫습니다. 패널 안에서 바깥으로 드래그하면 유지합니다.
|
||||
let drawerBackdropPressed = false;
|
||||
const outsideDrawer = (event) => {
|
||||
const drawer = $("am-detail"),
|
||||
rect = drawer.getBoundingClientRect();
|
||||
return (
|
||||
event.target === drawer &&
|
||||
(event.clientX < rect.left ||
|
||||
event.clientX >= rect.right ||
|
||||
event.clientY < rect.top ||
|
||||
event.clientY >= rect.bottom)
|
||||
);
|
||||
};
|
||||
$("am-detail").addEventListener("pointerdown", (event) => {
|
||||
drawerBackdropPressed = event.button === 0 && outsideDrawer(event);
|
||||
});
|
||||
$("am-detail").addEventListener("pointerup", (event) => {
|
||||
const dismiss = drawerBackdropPressed && outsideDrawer(event);
|
||||
drawerBackdropPressed = false;
|
||||
if (dismiss) close("am-detail");
|
||||
});
|
||||
$("am-detail").addEventListener("pointercancel", () => {
|
||||
drawerBackdropPressed = false;
|
||||
});
|
||||
$("am-filters").addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
state.page = 1;
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
- 현황 카드: 전체·사용 중·사용 가능·수리 중·30일 이내 보증 만료. 분류 구성·최근 활동·보유 구매금액(폐기 제외).
|
||||
- 자산대장: 검색/분류/상태/위치/사용자 필터, 정렬, 25개씩 페이지 이동. 엑셀은 현재 필터 전체(최대 10,000개).
|
||||
- 상세: 기본 정보/컴퓨터 사양/보고서/활동 이력. 구매일·금액·구매처·보증·부서·위치·메모.
|
||||
- 자산 선택 시 상세 패널은 오른쪽에서 들어온다. 바깥 영역 클릭·X·Esc로 오른쪽으로 나가며 닫힌다.
|
||||
패널 안에서 시작한 드래그는 닫지 않으며 사진/편집 창이 열린 동안 부모 패널을 유지한다.
|
||||
시스템의 모션 줄이기 설정에서는 즉시 열고 닫는다.
|
||||
- 등록: 번호를 비우면 `AST-000001` 형식으로 자동 발급. 대소문자 무관 고유. 같은 모델도 물건마다 하나씩 등록.
|
||||
- 배정: 사용 가능 → 사용 중. 등록된 회사 사용자만 배정. 반납 시 사용자 배정을 해제한다.
|
||||
- 수리: 사용 가능 → 수리 중 → 사용 가능. 배정된 자산은 먼저 반납한다.
|
||||
|
||||
@@ -395,6 +395,167 @@ const server = http.createServer(async (req, res) => {
|
||||
await page.goto(origin + "/asset/");
|
||||
await page.locator("#am-total").filter({ hasText: "30" }).waitFor();
|
||||
assert.equal(await page.locator("#am-rows tr").count(), 25);
|
||||
// 실제 브라우저의 애니메이션 시각을 고정해 중간 위치와 닫기 완료 시점을 확인합니다.
|
||||
await page.evaluate(() => {
|
||||
const drawer = document.querySelector("#am-detail"),
|
||||
animate = drawer.animate.bind(drawer);
|
||||
drawer.animate = (frames, options) => {
|
||||
const motion = animate(frames, options);
|
||||
motion.pause();
|
||||
return motion;
|
||||
};
|
||||
});
|
||||
const finishDrawer = () =>
|
||||
page.evaluate(async () => {
|
||||
const motion = document
|
||||
.querySelector("#am-detail")
|
||||
.getAnimations()
|
||||
.find((a) => a.id === "asset-drawer");
|
||||
if (motion) {
|
||||
motion.finish();
|
||||
await motion.finished;
|
||||
}
|
||||
});
|
||||
const drawerPosition = (time) =>
|
||||
page.evaluate((time) => {
|
||||
const drawer = document.querySelector("#am-detail"),
|
||||
motion = drawer
|
||||
.getAnimations()
|
||||
.find((a) => a.id === "asset-drawer");
|
||||
if (time !== null) motion.currentTime = time;
|
||||
const rect = drawer.getBoundingClientRect();
|
||||
return {
|
||||
left: rect.left,
|
||||
width: rect.width,
|
||||
viewport: innerWidth,
|
||||
open: drawer.open,
|
||||
closing: drawer.classList.contains("am-closing"),
|
||||
};
|
||||
}, time);
|
||||
await page.locator('[data-open="asset0"]').first().click();
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelector("#am-detail-title").textContent ===
|
||||
"KING-DESKTOP",
|
||||
);
|
||||
const entryStart = await drawerPosition(0),
|
||||
entryMiddle = await drawerPosition(140);
|
||||
assert.ok(
|
||||
Math.abs(entryStart.left - entryStart.viewport) < 2,
|
||||
"entry starts beyond the right screen edge",
|
||||
);
|
||||
assert.ok(
|
||||
entryMiddle.left < entryStart.left &&
|
||||
entryMiddle.left > entryStart.viewport - entryStart.width,
|
||||
"entry moves from right to left",
|
||||
);
|
||||
await finishDrawer();
|
||||
const atRest = await drawerPosition(null);
|
||||
assert.ok(Math.abs(atRest.left - (atRest.viewport - atRest.width)) < 2);
|
||||
await page.locator('[data-close="am-detail"]').click();
|
||||
const exitStart = await drawerPosition(0),
|
||||
exitMiddle = await drawerPosition(110);
|
||||
assert.ok(
|
||||
exitStart.open && exitStart.closing,
|
||||
"X retains the drawer until animation completion",
|
||||
);
|
||||
assert.ok(exitMiddle.left > exitStart.left, "exit moves back to the right");
|
||||
await finishDrawer();
|
||||
assert.equal(
|
||||
await page.locator("#am-detail").evaluate((el) => el.open),
|
||||
false,
|
||||
);
|
||||
assert.equal(new URL(page.url()).searchParams.has("asset"), false);
|
||||
assert.equal(
|
||||
await page.evaluate(() => document.activeElement.dataset.open),
|
||||
"asset0",
|
||||
"focus returns to the selected asset",
|
||||
);
|
||||
|
||||
await page.locator('[data-open="asset0"]').first().click();
|
||||
await finishDrawer();
|
||||
const rect = await page.locator("#am-detail").boundingBox();
|
||||
await page.mouse.move(rect.x + 100, 300);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(10, 300);
|
||||
await page.mouse.up();
|
||||
assert.equal(
|
||||
(await drawerPosition(null)).closing,
|
||||
false,
|
||||
"inside-to-outside drag must not dismiss",
|
||||
);
|
||||
await page.mouse.click(10, 400);
|
||||
assert.equal(
|
||||
(await drawerPosition(80)).closing,
|
||||
true,
|
||||
"backdrop click starts animated dismissal",
|
||||
);
|
||||
// 닫기 도중 다시 열면 취소한 닫기의 완료 콜백이 새 패널을 닫지 않습니다.
|
||||
const interrupted = await drawerPosition(null);
|
||||
await page.evaluate(() =>
|
||||
document.querySelector('#am-rows [data-open="asset0"]').click(),
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs((await drawerPosition(0)).left - interrupted.left) < 2,
|
||||
"reopen continues from the current position",
|
||||
);
|
||||
await finishDrawer();
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelector("#am-detail-title").textContent ===
|
||||
"KING-DESKTOP",
|
||||
);
|
||||
assert.equal((await drawerPosition(null)).closing, false);
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(
|
||||
(await drawerPosition(110)).closing,
|
||||
true,
|
||||
"Escape uses the same exit animation",
|
||||
);
|
||||
await finishDrawer();
|
||||
|
||||
// 닫힌 뒤 도착하는 응답이 패널을 다시 열거나 선택 URL을 복구하지 않습니다.
|
||||
await page.route("**/asset/api/assets/asset0", async (route) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
await route.continue();
|
||||
});
|
||||
const delayedResponse = page.waitForResponse((response) =>
|
||||
response.url().endsWith("/asset/api/assets/asset0"),
|
||||
);
|
||||
await page.locator('[data-open="asset0"]').first().click();
|
||||
await drawerPosition(100);
|
||||
await page.evaluate(() =>
|
||||
document.querySelector('[data-close="am-detail"]').click(),
|
||||
);
|
||||
await finishDrawer();
|
||||
await delayedResponse;
|
||||
await page.evaluate(
|
||||
() => new Promise((resolve) => requestAnimationFrame(resolve)),
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator("#am-detail").evaluate((el) => el.open),
|
||||
false,
|
||||
);
|
||||
assert.equal(new URL(page.url()).searchParams.has("asset"), false);
|
||||
await page.unroute("**/asset/api/assets/asset0");
|
||||
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await page.locator('[data-open="asset0"]').first().click();
|
||||
assert.equal(
|
||||
await page
|
||||
.locator("#am-detail")
|
||||
.evaluate((el) => el.getAnimations().length),
|
||||
0,
|
||||
);
|
||||
await page.locator('[data-close="am-detail"]').click();
|
||||
assert.equal(
|
||||
await page.locator("#am-detail").evaluate((el) => el.open),
|
||||
false,
|
||||
);
|
||||
await page.emulateMedia({ reducedMotion: "no-preference" });
|
||||
await page.evaluate(() => {
|
||||
delete document.querySelector("#am-detail").animate;
|
||||
});
|
||||
await page.screenshot({
|
||||
path: path.join(OUT, "asset-desktop.png"),
|
||||
fullPage: true,
|
||||
@@ -591,13 +752,11 @@ const server = http.createServer(async (req, res) => {
|
||||
await page.screenshot({ path: path.join(OUT, "asset-monitor-links.png") });
|
||||
await page.locator('[data-detail-tab="overview"]').click();
|
||||
await page.locator("[data-photo]").click();
|
||||
await page
|
||||
.locator("#am-photo-file")
|
||||
.setInputFiles({
|
||||
name: "test.png",
|
||||
mimeType: "image/png",
|
||||
buffer: photoPNG,
|
||||
});
|
||||
await page.locator("#am-photo-file").setInputFiles({
|
||||
name: "test.png",
|
||||
mimeType: "image/png",
|
||||
buffer: photoPNG,
|
||||
});
|
||||
await page.locator('#am-photo-form [type="submit"]').click();
|
||||
await page.waitForFunction(() => !document.querySelector("#am-photo").open);
|
||||
await page.locator('.am-photo-grid img[alt="test.png"]').waitFor();
|
||||
@@ -677,7 +836,7 @@ const server = http.createServer(async (req, res) => {
|
||||
);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(
|
||||
"ALL PASS: Chrome desktop/mobile, search races, paging, specs, XSS escaping, conflict draft, create, checkout/checkin, reports, setup mode, photos, monitor registration/link/overview, super-admin deletion",
|
||||
"ALL PASS: Chrome desktop/mobile, drawer entry/exit/backdrop/X/Escape, interrupt/reopen, late responses, reduced motion, search races, paging, specs, XSS escaping, conflict draft, create, checkout/checkin, reports, setup mode, photos, monitor registration/link/overview, super-admin deletion",
|
||||
);
|
||||
} finally {
|
||||
await browser?.close();
|
||||
|
||||
Reference in New Issue
Block a user