fix(project): keep sidebar on week navigation
This commit is contained in:
@@ -26,3 +26,17 @@
|
||||
.pj-side-meeting-week:hover { background: #f1f2f4; }
|
||||
.pj-side-meeting-week.is-active { background: var(--pj-accent-tint); color: var(--pj-accent-dark); }
|
||||
.pj-side-meeting-retry { font: inherit; font-size: 12px; color: var(--pj-ink-soft); border: 0; background: transparent; cursor: pointer; padding: 5px 8px; }
|
||||
|
||||
/* 왼쪽 메뉴와 별개로 오른쪽 회의록 문서만 바뀌는 영역. */
|
||||
.pj-meeting-panel-host { position: relative; max-width: none !important; overflow: hidden; }
|
||||
.pj-meeting-panel-frame { display: block; width: 100%; height: 100%; min-height: 0; flex: 1; border: 0; background: #fff; }
|
||||
.pj-meeting-panel-frame.is-loading { position: absolute; inset: 0; visibility: hidden; }
|
||||
.pj-meeting-panel-status { position: absolute; top: 4px; right: 8px; z-index: 2; padding: 6px 10px; border-radius: 6px; background: #f4f5f7; color: var(--pj-ink-soft); font-size: 12px; }
|
||||
.pj-meeting-panel-status.is-error { color: #b42318; background: #fff1f0; }
|
||||
html.pj-meeting-content, html.pj-meeting-content body { height: 100%; overflow: hidden; }
|
||||
html.pj-meeting-content .erp-page { height: 100%; margin: 0; padding: 0; display: flex; box-sizing: border-box; }
|
||||
html.pj-meeting-content .pj-wrap { width: 100%; min-height: 0; display: flex; flex-direction: column; padding: 0; }
|
||||
html.pj-meeting-content .pj-layout { display: flex; flex-direction: column; height: 100%; min-height: 0; }
|
||||
@media (max-width: 800px) {
|
||||
.pj-meeting-panel-host { height: 80vh; min-height: 400px; }
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
const branches = Array.from(document.querySelectorAll(".pj-side-goal-branch"));
|
||||
if (!branches.length) return;
|
||||
let loading = false, retry = null;
|
||||
const navigation = initMeetingNavigation();
|
||||
|
||||
// 문자열을 HTML로 해석하지 않고 넣어 회의록 메뉴의 글자를 그대로 표시한다.
|
||||
function icon(name, cls) {
|
||||
@@ -40,6 +41,13 @@
|
||||
link.href = week.href;
|
||||
link.textContent = week.label;
|
||||
link.title = week.label;
|
||||
link.addEventListener("click", function (event) {
|
||||
// Ctrl/⌘ 클릭과 새 탭 열기는 일반 링크의 동작을 유지한다.
|
||||
if (event.defaultPrevented || event.button || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
||||
if (!navigation) return;
|
||||
event.preventDefault();
|
||||
navigation.open(link.href);
|
||||
});
|
||||
if (week.start === current) {
|
||||
link.classList.add("is-active");
|
||||
link.setAttribute("aria-current", "page");
|
||||
@@ -66,6 +74,7 @@
|
||||
const year = (data.years || []).find(function (y) { return String(y.year) === branch.dataset.goalYear; });
|
||||
render(branch, year ? year.months : []);
|
||||
});
|
||||
if (navigation) navigation.markCurrent();
|
||||
if (retry) { retry.remove(); retry = null; }
|
||||
} catch (_) {
|
||||
// 목록 조회가 실패해도 기존 목표·프로젝트 메뉴는 계속 사용할 수 있다.
|
||||
@@ -82,6 +91,139 @@
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
// 왼쪽 메뉴는 그대로 두고 오른쪽 문서만 교체한다. 회의록 편집 이벤트·타이머는 문서와 함께 정리된다.
|
||||
function initMeetingNavigation() {
|
||||
const layout = document.querySelector(".pj-layout");
|
||||
const original = layout && layout.querySelector(".pj-main");
|
||||
if (!original) return null;
|
||||
const root = layout.closest(".pj-wrap"), originalClasses = root.className;
|
||||
const originalUrl = location.pathname + location.search;
|
||||
const originalTitle = document.title;
|
||||
const originalYears = new Set(Array.from(document.querySelectorAll(".pj-side-goal-year.is-active")));
|
||||
let host = null, frame = null, pending = null, sequence = 0, current = originalUrl;
|
||||
|
||||
function meetingUrl(value) {
|
||||
const url = new URL(value, location.href);
|
||||
if (url.origin !== location.origin || !/^\/project\/goals\/\d{4}\/meetings\/\d{1,2}$/.test(url.pathname)) return null;
|
||||
url.searchParams.delete("content");
|
||||
return url;
|
||||
}
|
||||
function markCurrent() {
|
||||
const url = meetingUrl(current), week = url && url.searchParams.get("week");
|
||||
document.querySelectorAll(".pj-side-meeting-week").forEach(function (link) {
|
||||
const selected = url && link.pathname === url.pathname && new URL(link.href).searchParams.get("week") === week;
|
||||
link.classList.toggle("is-active", !!selected);
|
||||
if (selected) link.setAttribute("aria-current", "page"); else link.removeAttribute("aria-current");
|
||||
});
|
||||
document.querySelectorAll(".pj-side-goal-year").forEach(function (link) {
|
||||
link.classList.toggle("is-active", url ? url.pathname.startsWith(link.pathname + "/") : originalYears.has(link));
|
||||
});
|
||||
}
|
||||
function ensureHost() {
|
||||
if (host) return;
|
||||
host = document.createElement("section");
|
||||
host.className = "pj-main pj-meeting-panel-host";
|
||||
original.replaceWith(host);
|
||||
root.classList.add("pj-goal-view", "pj-inbox-view", "pj-meet-view");
|
||||
}
|
||||
function status(message, failed) {
|
||||
if (!host) return;
|
||||
let box = host.querySelector(".pj-meeting-panel-status");
|
||||
if (!box) { box = document.createElement("div"); box.className = "pj-meeting-panel-status"; box.setAttribute("role", "status"); host.append(box); }
|
||||
box.textContent = message;
|
||||
box.classList.toggle("is-error", !!failed);
|
||||
}
|
||||
function clearStatus() { const box = host && host.querySelector(".pj-meeting-panel-status"); if (box) box.remove(); }
|
||||
function syncFont() {
|
||||
if (!frame) return;
|
||||
const font = document.documentElement.dataset.pjFont || "system";
|
||||
if (frame.contentDocument.documentElement.dataset.pjFont !== font) {
|
||||
frame.contentDocument.documentElement.dataset.pjFont = font;
|
||||
frame.contentWindow.dispatchEvent(new frame.contentWindow.Event("resize"));
|
||||
}
|
||||
}
|
||||
async function saveCurrent() {
|
||||
const view = frame ? frame.contentWindow : window;
|
||||
if (view.PJFlushForNavigation) await view.PJFlushForNavigation();
|
||||
}
|
||||
async function open(value, options) {
|
||||
options = options || {};
|
||||
const url = meetingUrl(value);
|
||||
if (!url) return;
|
||||
const target = url.pathname + url.search;
|
||||
if (frame && target === current && !pending) return;
|
||||
const turn = ++sequence;
|
||||
try {
|
||||
if (!options.initial) await saveCurrent();
|
||||
if (turn !== sequence) return;
|
||||
ensureHost();
|
||||
if (pending) { pending.remove(); pending = null; }
|
||||
status("회의록을 불러오는 중…", false);
|
||||
const next = document.createElement("iframe");
|
||||
next.className = "pj-meeting-panel-frame is-loading";
|
||||
next.title = "주간 회의록";
|
||||
pending = next;
|
||||
next.addEventListener("load", function () {
|
||||
if (next !== frame && turn !== sequence) { next.remove(); return; }
|
||||
try {
|
||||
if (!next.contentDocument.documentElement.classList.contains("pj-meeting-content")) throw new Error("회의록을 불러오지 못했습니다. 주차를 다시 눌러 주세요.");
|
||||
const actual = meetingUrl(next.contentWindow.location.href);
|
||||
const pane = next.contentDocument.getElementById("pj-meet-pane");
|
||||
if (pane && pane.dataset.week) actual.searchParams.set("week", pane.dataset.week);
|
||||
// 줄 추가·삭제 등으로 현재 회의록 자체가 새로고침되어도 패널을 제거하지 않는다.
|
||||
if (next === frame) {
|
||||
if (!pending) {
|
||||
current = actual.pathname + actual.search;
|
||||
clearStatus(); markCurrent(); history.replaceState({ pjMeeting: true }, "", current);
|
||||
}
|
||||
syncFont(); return;
|
||||
}
|
||||
current = actual.pathname + actual.search;
|
||||
if (frame) frame.remove();
|
||||
frame = next; pending = null;
|
||||
next.classList.remove("is-loading");
|
||||
syncFont(); clearStatus(); markCurrent();
|
||||
document.title = next.contentDocument.title;
|
||||
if (options.history !== false) history[options.initial ? "replaceState" : "pushState"]({ pjMeeting: true }, "", current);
|
||||
} catch (error) {
|
||||
if (next !== frame) { next.remove(); if (pending === next) pending = null; }
|
||||
status(error.message, true);
|
||||
if (options.history === false) history.replaceState(null, "", current);
|
||||
}
|
||||
});
|
||||
url.searchParams.set("content", "1");
|
||||
next.src = url.href;
|
||||
host.append(next);
|
||||
} catch (error) {
|
||||
if (turn !== sequence) return;
|
||||
if (host) status("이동하지 못했습니다. " + error.message, true);
|
||||
else if (window.erpAlert) window.erpAlert(error.message);
|
||||
if (options.history === false) history.replaceState(null, "", current);
|
||||
}
|
||||
}
|
||||
window.addEventListener("message", function (event) {
|
||||
if (!frame || event.origin !== location.origin || event.source !== frame.contentWindow) return;
|
||||
if (event.data && event.data.type === "pj-meeting-navigate") open(event.data.href);
|
||||
});
|
||||
window.addEventListener("resize", syncFont);
|
||||
window.addEventListener("popstate", async function () {
|
||||
const url = location.pathname + location.search;
|
||||
if (meetingUrl(url)) { open(url, { history: false }); return; }
|
||||
if (url === originalUrl && host) {
|
||||
try {
|
||||
await saveCurrent(); sequence++;
|
||||
if (pending) pending.remove();
|
||||
if (frame) frame.remove();
|
||||
host.replaceWith(original); host = frame = pending = null;
|
||||
root.className = originalClasses; current = originalUrl; document.title = originalTitle; markCurrent();
|
||||
} catch (error) { status(error.message, true); history.replaceState(null, "", current); }
|
||||
}
|
||||
});
|
||||
// 첫 회의록도 편집 코드가 붙기 전에 오른쪽 전용 문서로 분리해 중복 초기화를 막는다.
|
||||
if (meetingUrl(originalUrl)) open(originalUrl, { initial: true });
|
||||
return { open: open, markCurrent: markCurrent };
|
||||
}
|
||||
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init);
|
||||
else init();
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/* 오른쪽 회의록 안의 주차·달 이동도 왼쪽 메뉴를 유지하도록 부모 화면에 전달한다. */
|
||||
(function () {
|
||||
"use strict";
|
||||
if (window.parent === window) return;
|
||||
document.addEventListener("click", function (event) {
|
||||
const link = event.target.closest("a[href]");
|
||||
if (!link || event.defaultPrevented || event.button || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
||||
const url = new URL(link.href, location.href);
|
||||
if (url.origin !== location.origin) return;
|
||||
if (/^\/project\/goals\/\d{4}\/meetings\/\d{1,2}$/.test(url.pathname)) {
|
||||
event.preventDefault();
|
||||
url.searchParams.delete("content");
|
||||
window.parent.postMessage({ type: "pj-meeting-navigate", href: url.href }, location.origin);
|
||||
} else if (/^\/project\/goals\/\d{4}$/.test(url.pathname)) {
|
||||
// 연간 목표로 돌아갈 때는 중첩 메뉴가 생기지 않도록 바깥 화면에서 연다.
|
||||
link.target = "_top";
|
||||
}
|
||||
});
|
||||
})();
|
||||
+31
-16
@@ -8,24 +8,36 @@
|
||||
"use strict";
|
||||
|
||||
// ── 공용 fetch ─────────────────────────────────────────────
|
||||
const navigationSavers = [];
|
||||
let navigationWrites = 0;
|
||||
// 오른쪽 회의록을 바꾸기 전에 입력 칸 저장을 끝낸다. 실패하면 기존 화면을 유지한다.
|
||||
window.PJFlushForNavigation = async function () {
|
||||
if (document.activeElement && document.activeElement.blur) document.activeElement.blur();
|
||||
await Promise.all(navigationSavers.map(function (flush) { return flush(); }));
|
||||
if (navigationWrites) throw new Error("저장 중입니다. 저장이 끝난 뒤 다시 이동해 주세요.");
|
||||
};
|
||||
// extra.keepalive — 페이지를 떠나는 중에도 요청을 보내 달라고 브라우저에 부탁(보장은 아님, createFieldSaver 참고)
|
||||
async function api(method, url, body, extra) {
|
||||
const opts = { method, headers: { "Content-Type": "application/json" } };
|
||||
if (body !== undefined) opts.body = JSON.stringify(body);
|
||||
if (extra && extra.keepalive) opts.keepalive = true;
|
||||
const res = await fetch(url, opts);
|
||||
if (!res.ok) {
|
||||
let msg = res.statusText, detail = null;
|
||||
try { detail = (await res.json()).detail; } catch (_) {}
|
||||
if (typeof detail === "string") msg = detail;
|
||||
else if (detail && detail.message) msg = detail.message;
|
||||
const err = new Error(msg);
|
||||
err.status = res.status; // 403(권한 없음)·404 를 일시 오류와 구분하려고
|
||||
err.detail = detail;
|
||||
throw err;
|
||||
}
|
||||
if (res.status === 204) return null;
|
||||
return res.json();
|
||||
const writing = method !== "GET";
|
||||
if (writing) navigationWrites++;
|
||||
try {
|
||||
const opts = { method, headers: { "Content-Type": "application/json" } };
|
||||
if (body !== undefined) opts.body = JSON.stringify(body);
|
||||
if (extra && extra.keepalive) opts.keepalive = true;
|
||||
const res = await fetch(url, opts);
|
||||
if (!res.ok) {
|
||||
let msg = res.statusText, detail = null;
|
||||
try { detail = (await res.json()).detail; } catch (_) {}
|
||||
if (typeof detail === "string") msg = detail;
|
||||
else if (detail && detail.message) msg = detail.message;
|
||||
const err = new Error(msg);
|
||||
err.status = res.status; // 403(권한 없음)·404 를 일시 오류와 구분하려고
|
||||
err.detail = detail;
|
||||
throw err;
|
||||
}
|
||||
if (res.status === 204) return null;
|
||||
return await res.json();
|
||||
} finally { if (writing) navigationWrites--; }
|
||||
}
|
||||
|
||||
function el(id) { return document.getElementById(id); }
|
||||
@@ -347,6 +359,7 @@
|
||||
if (warn && e) { e.preventDefault(); e.returnValue = ""; }
|
||||
return warn;
|
||||
}
|
||||
navigationSavers.push(flushAll);
|
||||
return {
|
||||
track: track, queue: queue, flush: flush, flushAll: flushAll, isDirty: isDirty, anyDirty: anyDirty,
|
||||
prune: prune, onBeforeUnload: onBeforeUnload,
|
||||
@@ -8338,6 +8351,8 @@
|
||||
let failures = 0;
|
||||
let timer = null;
|
||||
async function syncOnce() {
|
||||
// 회의록 패널을 보는 동안은 이전 프로젝트 화면의 자동 갱신이 왼쪽 메뉴를 다시 만들지 않게 한다.
|
||||
if (document.querySelector(".pj-meeting-panel-host")) return;
|
||||
if (syncing || observed === null || observed === applied) return;
|
||||
syncing = true;
|
||||
const target = observed;
|
||||
|
||||
Reference in New Issue
Block a user