fix(project): keep sidebar on week navigation
This commit is contained in:
@@ -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();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user