feat(project): 보드에서 하위 업무 한 줄을 다른 업무 카드로 드래그해 옮기기

카드에 펼친 하위 업무 줄을 끌어 다른 카드에 놓으면 그 업무의 하위 업무로
옮긴다. 카드 자체 드래그(세션 이동)와 섞이지 않게 별도 드래그 타입을 쓰고,
놓을 수 있는 카드는 보라 테두리로 표시한다.

- API: POST /project/api/tasks/{id}/move-parent {parent_task_id}
- db.move_subtask: 받는 쪽은 같은 프로젝트의 최상위 업무만(순환 방지),
  활동 로그 subtask_moved, 목록 끝으로 정렬
- 정적 파일 버전 20260925d

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 18:28:56 +09:00
parent db1ffdd636
commit d5e02b04a4
10 changed files with 169 additions and 8 deletions
+4
View File
@@ -297,6 +297,10 @@
}
.pj-card:hover { box-shadow: var(--pj-card-shadow-hover); transform: translateY(-1px); }
.pj-card.is-dragging { opacity: .5; }
/* 하위 업무 한 줄 드래그 — 끄는 줄은 흐리게, 놓을 수 있는 카드는 보라 테두리 */
.pj-card-sub[draggable="true"] .pj-card-sub-title { cursor: grab; }
.pj-card-sub.is-dragging { opacity: .4; }
.pj-card.is-sub-drop { outline: 2px solid var(--pj-accent); outline-offset: -2px; background: var(--pj-accent-tint); }
.pj-card.is-done .pj-card-title { text-decoration: line-through; color: #9aa1a9; }
.pj-card-title { font-size: 13.5px; font-weight: 600; color: var(--pj-ink); line-height: 1.4; }
.pj-card-meta { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
+78
View File
@@ -3171,6 +3171,10 @@
// 닫히면(거기서 하위 업무를 고쳤을 수 있으니) 캐시를 비운다(아래 observer).
const expandedSubs = new Set();
const subsCache = {};
// 지금 끌고 있는 하위 업무 줄 { sub, from(상위 업무) } — dragover 중엔
// dataTransfer 값을 읽을 수 없어서(보안상 type 만 보임) 여기 들고 있는다.
let dragSub = null;
const SUB_DRAG_TYPE = "application/x-pj-subtask";
// 아사나의 하위 업무 아이콘(위 노드 하나에서 두 갈래로 뻗은 노드).
const SUBTASK_ICON_SVG =
'<svg class="pj-card-subtoggle-ic" viewBox="0 0 16 16" width="15" height="15" fill="none" ' +
@@ -3265,6 +3269,24 @@
box.querySelectorAll(".pj-card-sub").forEach(function (row) {
const sub = subs.find(function (x) { return String(x.id) === row.dataset.subId; });
if (!sub) return;
// 드래그 — 이 하위 업무 한 줄만 다른 카드(상위 업무)로 옮긴다. 카드 자체도
// draggable 이라 이벤트가 카드로 올라가면 카드 이동이 시작되므로 막는다.
if (canManage) {
row.draggable = true;
row.addEventListener("dragstart", function (e) {
e.stopPropagation();
dragSub = { sub: sub, from: t };
e.dataTransfer.setData(SUB_DRAG_TYPE, String(sub.id));
e.dataTransfer.effectAllowed = "move";
row.classList.add("is-dragging");
});
row.addEventListener("dragend", function (e) {
e.stopPropagation();
row.classList.remove("is-dragging");
dragSub = null;
document.querySelectorAll(".pj-card.is-sub-drop").forEach(function (c) { c.classList.remove("is-sub-drop"); });
});
}
// 우클릭 — 하위 업무 메뉴(아사나처럼): 열기 / 완료 / 삭제.
if (canManage) row.addEventListener("contextmenu", function (e) {
e.preventDefault();
@@ -3326,6 +3348,40 @@
});
}
// 하위 업무 한 줄을 다른 상위 업무(카드)로 옮긴다 — 보드에서 드래그해 놓았을 때.
// 같은 업무가 여러 프로젝트 맥락 행으로 tasks 에 들어 있을 수 있어(멀티호밍)
// 개수는 같은 id 의 행 모두에서 맞춘다.
function adjustSubCounts(taskId, dTotal, dDone) {
tasks.forEach(function (x) {
if (x.id !== taskId) return;
x.subtask_total = Math.max(0, (x.subtask_total || 0) + dTotal);
x.subtask_done = Math.max(0, (x.subtask_done || 0) + dDone);
});
}
async function moveSubtaskTo(sub, from, to) {
if (sub.project_id && to.project_id && sub.project_id !== to.project_id) {
showToast("다른 프로젝트의 업무로는 옮길 수 없습니다.", "error");
return;
}
try {
const res = await api("POST", "/project/api/tasks/" + sub.id + "/move-parent",
{ parent_task_id: to.id });
const moved = (res && res.task) || Object.assign({}, sub, { parent_task_id: to.id });
const done = sub.completed_at ? 1 : 0;
const fromSubs = subsCache[from.id];
if (fromSubs) {
const i = fromSubs.indexOf(sub);
if (i >= 0) fromSubs.splice(i, 1);
}
if (subsCache[to.id]) subsCache[to.id].push(moved);
adjustSubCounts(from.id, -1, -done);
adjustSubCounts(to.id, 1, done);
if (!from.subtask_total) expandedSubs.delete(from.id);
renderBoard();
showToast("'" + (sub.title || "") + "' → '" + (to.title || "") + "' 로 옮겼습니다.");
} catch (err) { showToast("이동 실패: " + err.message, "error"); }
}
// 카드 하위 업무 펼치기/접기 — 보드를 다시 그리지 않고 그 카드 안에서만
// 높이를 애니메이션한다(아사나처럼 카드가 아래로 스르륵 늘어남).
// 펼칠 땐 목록을 먼저 받아 채운 뒤 펼친다 — "불러오는 중…"에서 목록으로
@@ -3445,6 +3501,28 @@
card.classList.add("is-dragging");
});
card.addEventListener("dragend", function () { card.classList.remove("is-dragging"); });
// 하위 업무 줄을 이 카드에 놓으면 이 업무의 하위 업무로 옮긴다.
// 원래 상위 업무 카드 위에서는 받지 않는다(제자리).
card.addEventListener("dragover", function (e) {
if (!dragSub || !e.dataTransfer.types.includes(SUB_DRAG_TYPE)) return;
if (dragSub.from.id === t.id) return;
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = "move";
card.classList.add("is-sub-drop");
});
card.addEventListener("dragleave", function (e) {
if (!card.contains(e.relatedTarget)) card.classList.remove("is-sub-drop");
});
card.addEventListener("drop", function (e) {
if (!dragSub || !e.dataTransfer.types.includes(SUB_DRAG_TYPE)) return;
e.preventDefault();
e.stopPropagation();
card.classList.remove("is-sub-drop");
const moving = dragSub;
dragSub = null;
if (moving.from.id !== t.id) moveSubtaskTo(moving.sub, moving.from, t);
});
card.addEventListener("contextmenu", function (e) {
e.preventDefault();
showContextMenu(e.clientX, e.clientY, taskContextItems(t));