feat(project): 파일 끌어 놓기 → 구글 드라이브 링크, 필터 켠 보드 카드 순서 버그 수정

- 설명란·세부 업무 목록·보드 카드에 파일을 놓으면 드라이브 프로젝트/섹션/업무/세부 업무
  폴더에 올리고 설명에 "파일 이름.확장자" 링크(PROJECT_DRIVE_FOLDER_ID)
- 설명에서 링크를 지우면 우리가 올린 파일만 드라이브 휴지통, 되살리면 복구
- 브라우저별 필터(localStorage)가 켜져 있으면 섹션 안 카드가 제자리로 돌아가던 버그 —
  필터 중에도 순서 변경 허용, 숨은 업무는 제자리. 카드 속 이미지 끌기 오인 방지

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-19 23:19:16 +09:00
parent ee96c924fc
commit 52ca60df9a
19 changed files with 887 additions and 50 deletions
+204 -25
View File
@@ -3630,8 +3630,11 @@
}
// 보드 카드 순서 바꾸기는 "기본 정렬 + 필터 없음"일 때만 — 가려진 카드가 있거나
// 다른 기준으로 정렬돼 있으면 놓은 자리가 실제 순서와 어긋난다(아사나도 같다).
// 보드 카드 순서를 손으로 바꿀 수 있는가 — 정렬이 "기본"일 때. 필터(상태·담당자·마감·우선순위·찾기)는 막지 않는다
// (2026-10-19): 필터 설정은 브라우저(localStorage pj_filter_…)마다 남아, 필터를 켜 둔 컴퓨터에서만 섹션 안 카드가
// 늘 제자리로 돌아가던 버그. 숨은 업무는 제자리에 두고 보이는 카드끼리의 새 순서만 반영한다(orderWithHidden).
function manualOrderAllowed() {
return taskFilter.sort === "manual" && !taskFilterActive(taskFilter);
return taskFilter.sort === "manual";
}
const FB = {
@@ -5202,6 +5205,18 @@
// 세션"만 연결(POST .../links)로 바꾼다.
// 드롭 지점(마우스 Y)이 이 컬럼의 카드들 중 어디에 해당하는지 인덱스로.
// 드래그 중인 카드 자신은 계산에서 제외(자기 위치가 기준을 흔들지 않게).
// 섹션 전체 순서(full, 옮기는 업무 뺌)에 옮기는 업무를 넣는다 — 화면에 보이는 카드 순서(visible, 옮기는 업무 포함)에서
// 바로 앞 카드 뒤(없으면 바로 뒤 카드 앞, 둘 다 없으면 맨 끝). 필터로 숨은 업무는 원래 자리 그대로(예전엔 맨 뒤로 밀렸다).
function orderWithHidden(full, visible, movingId) {
const out = full.filter(function (id) { return id !== movingId; });
const i = visible.indexOf(movingId);
const before = i > 0 ? out.indexOf(visible[i - 1]) : -1;
const after = i >= 0 && i + 1 < visible.length ? out.indexOf(visible[i + 1]) : -1;
if (before >= 0) out.splice(before + 1, 0, movingId);
else if (after >= 0) out.splice(after, 0, movingId);
else out.push(movingId);
return out;
}
function cardDropIndex(body, clientY, excludeTaskId) {
const cards = Array.prototype.slice.call(body.querySelectorAll(".pj-card[data-task-id]"))
.filter(function (c) { return String(c.dataset.taskId) !== String(excludeTaskId); });
@@ -5346,19 +5361,19 @@
// 놓을 자리 = 자리 표시 위치(없으면 마우스 위치)
let idx = phIndex(body);
if (idx < 0) idx = cardDropIndex(body, e.clientY, taskId);
// 자리 표시 기준 이 섹션 카드 순서(끈 카드 포함) + 화면에 없는 이 섹션 업무는 뒤에
// 자리 표시 기준 이 섹션 카드 순서(끈 카드 포함)
const domIds = phCards(body).map(function (c) { return parseInt(c.dataset.taskId, 10); })
.filter(function (id) { return id !== taskId; });
domIds.splice(idx, 0, taskId);
function orderedFor() {
const rest = tasks.filter(function (x) {
return x.stage_id === stageId && x.context_project_id === projectId && domIds.indexOf(x.id) < 0;
const full = tasks.filter(function (x) {
return x.stage_id === stageId && x.context_project_id === projectId && x.id !== taskId;
}).map(function (x) { return x.id; });
return domIds.concat(rest);
return orderWithHidden(full, domIds, taskId);
}
if (t.stage_id === stageId) {
if (!manualOrderAllowed()) {
showToast("필터·정렬을 쓰는 중에는 카드 순서를 바꿀 수 없습니다. (정렬: 기본, 필터 초기화 후 가능)", "error");
showToast("정렬을 쓰는 중에는 카드 순서를 바꿀 수 없습니다. (필터 바의 정렬을 '기본'으로 바꾼 뒤 가능)", "error");
endCardDrag(true);
return;
}
@@ -6251,35 +6266,56 @@
e.preventDefault();
showContextMenu(e.clientX, e.clientY, taskContextItems(t));
});
// 파일을 카드에 끌어 놓으면 이 업무에 첨부(2026-10-19) — 카드 끌기(text/plain)·세부 업무 끌기와는 종류("Files")로 구분
// 파일을 카드에 끌어 놓으면 구글 드라이브에 올리고 그 업무 설명에 "파일 이름.확장자" 링크(2026-10-19 — 예전엔 첨부).
// 펼친 세부 업무 줄에 놓으면 그 세부 업무 설명에. 카드 끌기(text/plain)·세부 업무 끌기와는 종류("Files")로 구분
let fileDepth = 0;
function fileSubRow(e) {
const r = e.target && e.target.closest ? e.target.closest(".pj-card-sub[data-sub-id]") : null;
return r && card.contains(r) ? r : null;
}
function markFileSub(row) {
card.querySelectorAll(".pj-card-sub.is-drive-over").forEach(function (x) { if (x !== row) x.classList.remove("is-drive-over"); });
if (row) row.classList.add("is-drive-over");
card.classList.toggle("is-file-drop-sub", !!row);
}
card.addEventListener("dragenter", function (e) {
if (!dragHasFiles(e)) return;
e.preventDefault();
fileDepth++;
card.classList.add("is-file-drop");
markFileSub(fileSubRow(e));
});
card.addEventListener("dragover", function (e) {
if (!dragHasFiles(e)) return;
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = "copy";
markFileSub(fileSubRow(e));
});
card.addEventListener("dragleave", function (e) {
if (!dragHasFiles(e)) return;
if (--fileDepth <= 0) { fileDepth = 0; card.classList.remove("is-file-drop"); }
if (--fileDepth <= 0) { fileDepth = 0; card.classList.remove("is-file-drop"); markFileSub(null); }
});
card.addEventListener("drop", async function (e) {
if (!dragHasFiles(e)) return;
e.preventDefault();
e.stopPropagation();
const row = fileSubRow(e);
const files = Array.prototype.slice.call(e.dataTransfer.files || []);
fileDepth = 0;
card.classList.remove("is-file-drop");
card.classList.add("is-file-uploading");
const out = await uploadTaskFiles(t.id, e.dataTransfer.files);
card.classList.remove("is-file-uploading");
reportUpload(out, t.title || "");
if (currentTaskId === t.id && !taskModal.hidden) loadAttachments(t.id); // 열려 있는 업무 창도 바로
markFileSub(null);
if (!files.length) return;
const target = row || card;
target.classList.add("is-file-uploading");
try {
if (row) {
const st = row.querySelector(".pj-card-sub-title");
await dropDriveFilesOnTask(parseInt(row.dataset.subId, 10), files, st ? st.textContent.trim() : "");
} else {
await dropDriveFilesOnTask(t.id, files, t.title || "");
}
} finally { target.classList.remove("is-file-uploading"); }
});
}
return card;
@@ -7817,8 +7853,51 @@
if (out.ok) showToast((where ? "‘" + where + "’에 " : "") + "파일 " + out.ok + "개를 첨부했습니다.");
if (out.errors.length) showToast("업로드 실패 — " + out.errors.join(" / "), "error");
}
// 끌고 있는 것이 "파일"인가(카드 끌기·글자 끌기와 구분)
// ── 업무 파일 → 구글 드라이브(2026-10-19) — 드라이브 `프로젝트/섹션/업무/세부 업무` 폴더에 올리고 설명란에
// "파일 이름.확장자" 링크. 설명에서 링크를 지우면 서버가 그 파일을 드라이브 휴지통으로 보낸다.
// append=true → 서버가 그 업무 설명 끝에 링크를 붙인다(보드 카드·세부 업무 줄 — 설명란을 열어 두지 않은 업무).
async function uploadDriveFile(taskId, file, append) {
const fd = new FormData();
fd.append("file", file);
if (append) fd.append("append", "true");
const res = await fetch("/project/api/tasks/" + taskId + "/drive-files", { method: "POST", body: fd });
if (!res.ok) { let m = res.statusText; try { m = (await res.json()).detail; } catch (_) {} throw new Error(m || ("HTTP " + res.status)); }
const data = await res.json();
if (data.append_failed) throw new Error("드라이브에는 올렸지만 설명에 링크를 못 붙였습니다 — " + data.file.url);
return { url: data.file.url, name: data.file.name, task: data.task || null };
}
// 여러 파일을 차례로 올려 그 업무 설명 끝에 붙인다 → { ok, errors, task(마지막으로 바뀐 업무) }
async function appendDriveFiles(taskId, files) {
const out = { ok: 0, errors: [], task: null };
for (const f of Array.prototype.slice.call(files || [])) {
try { const r = await uploadDriveFile(taskId, f, true); out.ok++; if (r.task) out.task = r.task; }
catch (e) { out.errors.push(f.name + ": " + e.message); }
}
return out;
}
function reportDrive(out, where) {
if (out.ok) showToast((where ? "‘" + where + "’ " : "") + "설명에 구글 드라이브 파일 링크 " + out.ok + "개를 넣었습니다.");
if (out.stale) showToast("파일은 구글 드라이브에 올라갔지만 업무 창이 바뀌어 설명에 링크를 넣지 못했습니다.", "error");
if (out.errors.length) showToast("드라이브 업로드 실패 — " + out.errors.join(" / "), "error");
}
// 보드 카드·업무 창 세부 업무 줄 → 그 업무 설명에 링크. 지금 업무 창(설명란)에 열려 있는 업무면 서버가 아니라
// 편집기 맨 끝에 넣는다(서버가 붙인 뒤 창의 옛 설명이 저장돼 링크가 지워지고 파일이 휴지통으로 가지 않게).
async function dropDriveFilesOnTask(taskId, files, where) {
if (descEditor && !taskModal.hidden && !taskReadOnly && String(currentTaskId) === String(taskId)) {
const out = await descEditor.insertDriveFiles(files, null, null, function (f) { return uploadDriveFile(taskId, f, false); });
reportDrive(out, where);
return out;
}
const out = await appendDriveFiles(taskId, files);
if (out.task) { try { mergeTask(out.task); } catch (_) {} }
reportDrive(out, where);
return out;
}
// 끌고 있는 것이 "파일"인가(카드 끌기·글자 끌기와 구분). 화면 안 카드·세부 업무 끌기 중이면 아니다 —
// 카드 속 이미지(아바타 등)를 잡고 끌면 브라우저가 "Files" 를 같이 실어, 파일 받기 칸이 카드 끌기를 가로채
// 놓을 때 카드가 제자리로 돌아가던 경우를 막는다(2026-10-19).
function dragHasFiles(e) {
if (cardDrag || dragSub) return false;
return !!(e.dataTransfer && Array.prototype.indexOf.call(e.dataTransfer.types || [], "Files") >= 0);
}
const attachInput = el("pj-attach-input");
@@ -7829,25 +7908,49 @@
if (out.errors.length) alert("업로드 실패: " + out.errors.join("\n"));
loadAttachments(currentTaskId);
});
// ── 업무 창 아무 곳에나 파일을 끌어 놓으면 첨부(2026-10-19) — 창 전체에 점선 안내가 뜨고, 놓으면 [첨부 파일]에 올라간다.
// 설명칸에 놓아도 글에 끼워 넣지 않고 첨부로. 아직 저장 전인 새 업무·읽기 전용이면 안내만.
// ── 업무 창에 파일 끌어 놓기 — 놓는 자리에 따라(2026-10-19):
// · 설명란 → 구글 드라이브에 올리고 놓은 자리에 "파일 이름.확장자" 링크(설명란 위 점선 안내)
// · 세부 업무 목록의 줄 → 그 세부 업무 설명 끝에 드라이브 링크(줄 점선 안내), 목록 빈 곳 → 이 업무 설명 끝에
// · 그 밖의 곳 → 예전처럼 [첨부 파일](창 전체 점선 안내)
// 아직 저장 전인 새 업무·읽기 전용이면 안내만.
(function wireTaskFileDrop() {
const card = taskModal && taskModal.querySelector(".pj-task-modal-card");
if (!card) return;
let depth = 0;
const clear = function () { depth = 0; card.classList.remove("is-file-over"); };
const descBox = el("pj-t-desc");
const descWrap = descBox ? descBox.parentElement : null;
const subList = el("pj-subtask-list");
let depth = 0, hot = null;
function blocked() { return !currentTaskId || !canManage || taskReadOnly; }
// 놓는 자리 → { kind: "desc" | "sub" | "subs" | "attach", el, id }
function zoneOf(target) {
const t = target && target.nodeType === 1 ? target : target && target.parentElement;
if (!t) return { kind: "attach", el: null };
if (descWrap && descWrap.contains(t)) return { kind: "desc", el: descWrap };
const row = subList && t.closest ? t.closest(".pj-subtask-row") : null;
if (row && subList.contains(row) && row.dataset.id) return { kind: "sub", el: row, id: row.dataset.id };
if (subList && subList.contains(t)) return { kind: "subs", el: subList };
return { kind: "attach", el: null };
}
function mark(z) {
if (hot && (!z || hot !== z.el)) { hot.classList.remove("is-drive-over"); hot = null; }
const drive = z && z.kind !== "attach";
card.classList.toggle("is-file-over", !!z && (!drive || blocked()));
card.classList.toggle("is-file-blocked", !!z && blocked());
if (drive && !blocked() && z.el) { z.el.classList.add("is-drive-over"); hot = z.el; }
}
const clear = function () { depth = 0; mark(null); card.classList.remove("is-file-over", "is-file-blocked"); };
card.addEventListener("dragenter", function (e) {
if (!dragHasFiles(e)) return;
e.preventDefault();
depth++;
card.classList.add("is-file-over");
card.classList.toggle("is-file-blocked", !currentTaskId || !canManage || taskReadOnly);
mark(zoneOf(e.target));
});
card.addEventListener("dragover", function (e) {
if (!dragHasFiles(e)) return;
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = (!currentTaskId || !canManage || taskReadOnly) ? "none" : "copy";
e.dataTransfer.dropEffect = blocked() ? "none" : "copy";
mark(zoneOf(e.target));
});
card.addEventListener("dragleave", function (e) {
if (!dragHasFiles(e)) return;
@@ -7857,11 +7960,30 @@
if (!dragHasFiles(e)) return;
e.preventDefault();
e.stopPropagation();
const z = zoneOf(e.target);
clear();
if (!canManage || taskReadOnly) { showToast("이 업무에는 파일을 첨부할 수 없습니다(읽기 전용).", "error"); return; }
if (!canManage || taskReadOnly) { showToast("이 업무에는 파일을 넣을 수 없습니다(읽기 전용).", "error"); return; }
if (!currentTaskId) { showToast("업무 이름을 먼저 넣어 업무를 만든 뒤 파일을 끌어 놓으세요.", "error"); return; }
const taskId = currentTaskId;
const out = await uploadTaskFiles(taskId, e.dataTransfer.files);
const files = Array.prototype.slice.call(e.dataTransfer.files || []);
if (!files.length) return;
if (z.kind === "desc" && descEditor) {
const x = e.clientX, y = e.clientY;
const out = await descEditor.insertDriveFiles(files, x, y, function (f) { return uploadDriveFile(taskId, f, false); });
reportDrive(out, "");
return;
}
if (z.kind === "sub") {
const name = z.el.querySelector(".pj-subtask-title") || {};
const title = (name.value || name.textContent || "").trim();
z.el.classList.add("is-file-uploading");
const out = await appendDriveFiles(parseInt(z.id, 10), files);
z.el.classList.remove("is-file-uploading");
reportDrive(out, title);
return;
}
if (z.kind === "subs") { await dropDriveFilesOnTask(taskId, files, ""); return; }
const out = await uploadTaskFiles(taskId, files);
reportUpload(out, "");
if (currentTaskId === taskId) loadAttachments(taskId);
});
@@ -8849,9 +8971,9 @@
let pendingUploads = 0;
let idleWaiters = [];
let editorGen = 0;
function beginUpload() {
function beginUpload(label) {
pendingUploads++;
if (hint) hint.textContent = "이미지 업로드 중…";
if (hint) hint.textContent = label || "이미지 업로드 중…";
}
function endUpload() {
pendingUploads = Math.max(0, pendingUploads - 1);
@@ -8928,8 +9050,65 @@
imgInput.value = "";
});
// ── 파일 끌어 놓기 → 구글 드라이브(2026-10-19) — 놓은 자리에 "올리는 중" 표시를 두고, 올라가면 그 자리를
// "파일 이름.확장자" 링크(새 탭)로 바꾼다. 올리는 동안은 저장을 미룬다(isUploading). upload(file) → Promise<{url, name}>.
// x·y 가 없으면 설명 맨 끝에. 반환 { ok, errors: ["파일: 이유"], stale: 올렸지만 창이 바뀌어 못 넣음 }
function caretRangeAt(x, y) {
let r = null;
try {
if (document.caretRangeFromPoint) r = document.caretRangeFromPoint(x, y);
else if (document.caretPositionFromPoint) {
const p = document.caretPositionFromPoint(x, y);
if (p) { r = document.createRange(); r.setStart(p.offsetNode, p.offset); r.collapse(true); }
}
} catch (_) { r = null; }
return r && box.contains(r.startContainer) ? r : null;
}
async function insertDriveFiles(files, x, y, upload) {
const list = Array.prototype.slice.call(files || []);
const out = { ok: 0, errors: [], stale: false };
if (!list.length || box.getAttribute("contenteditable") === "false") return out;
const myGen = editorGen;
let at = x != null && y != null ? caretRangeAt(x, y) : null;
if (!at) { at = document.createRange(); at.selectNodeContents(box); at.collapse(false); }
const mark = document.createElement("span");
mark.className = "pj-drive-uploading";
mark.setAttribute("contenteditable", "false");
mark.textContent = "구글 드라이브에 올리는 중… (" + list.length + "개)";
at.insertNode(mark);
beginUpload("파일을 구글 드라이브에 올리는 중…");
const links = [];
try {
for (const f of list) {
try { links.push(await upload(f)); out.ok++; }
catch (e) { out.errors.push(f.name + ": " + e.message); }
}
} finally {
if (myGen !== editorGen || !mark.isConnected) {
out.stale = links.length > 0;
mark.remove();
} else {
const frag = document.createDocumentFragment();
links.forEach(function (l, i) {
if (i) frag.appendChild(document.createElement("br"));
const a = document.createElement("a");
a.href = l.url; a.target = "_blank"; a.rel = "noopener noreferrer";
a.textContent = l.name;
frag.appendChild(a);
});
if (links.length) frag.appendChild(document.createTextNode(" "));
mark.replaceWith(frag);
lastRange = null;
box.dispatchEvent(new Event("input", { bubbles: true }));
}
endUpload();
}
return out;
}
return {
setTaskId: setTaskId,
insertDriveFiles: insertDriveFiles,
setHtml: function (html) {
selectImg(null); lastRange = null;
box.innerHTML = html || "";