252 lines
12 KiB
JavaScript
252 lines
12 KiB
JavaScript
/* 생성된 회의록만 읽어서 목표 연도 아래에 월별 폴더를 만든다. */
|
|
(function () {
|
|
"use strict";
|
|
function init() {
|
|
const branches = Array.from(document.querySelectorAll(".pj-side-goal-branch"));
|
|
if (!branches.length) return;
|
|
let loading = false, retry = null;
|
|
const navigation = initMeetingNavigation();
|
|
// 연도 접기는 월 폴더를 지우지 않고 숨겨서 각 월의 펼침 상태도 그대로 남긴다.
|
|
branches.forEach(function (branch) {
|
|
const button = branch.querySelector(".pj-side-goal-year-toggle");
|
|
const list = branch.querySelector(".pj-side-meeting-months");
|
|
if (!button || !list) return;
|
|
const key = "pj_goal_year_open:" + branch.dataset.goalYear;
|
|
function setOpen(open) {
|
|
list.hidden = !open;
|
|
button.setAttribute("aria-expanded", String(open));
|
|
const action = open ? "하위 월 접기" : "하위 월 펼치기";
|
|
button.setAttribute("aria-label", branch.dataset.goalYear + "년 " + action);
|
|
button.title = action;
|
|
}
|
|
let saved = null;
|
|
try { saved = localStorage.getItem(key); } catch (_) {}
|
|
setOpen(saved !== "0");
|
|
button.addEventListener("click", function () {
|
|
const open = list.hidden;
|
|
setOpen(open);
|
|
try { localStorage.setItem(key, open ? "1" : "0"); } catch (_) {}
|
|
});
|
|
});
|
|
|
|
// 문자열을 HTML로 해석하지 않고 넣어 회의록 메뉴의 글자를 그대로 표시한다.
|
|
function icon(name, cls) {
|
|
const span = document.createElement("span");
|
|
span.className = "material-symbols-outlined " + cls;
|
|
span.setAttribute("aria-hidden", "true");
|
|
span.textContent = name;
|
|
return span;
|
|
}
|
|
function render(branch, months) {
|
|
const list = branch.querySelector(".pj-side-meeting-months");
|
|
const current = list.dataset.currentWeek;
|
|
list.replaceChildren();
|
|
months.forEach(function (month) {
|
|
const folder = document.createElement("details");
|
|
folder.className = "pj-side-meeting-month";
|
|
const key = "pj_goal_month_open:" + branch.dataset.goalYear + ":" + month.month;
|
|
let saved = null;
|
|
try { saved = localStorage.getItem(key); } catch (_) {}
|
|
folder.open = saved == null ? month.weeks.some(function (w) { return w.start === current; }) : saved === "1";
|
|
const summary = document.createElement("summary");
|
|
summary.append(icon("chevron_right", "pj-side-meeting-caret"),
|
|
icon("folder", "pj-side-meeting-folder pj-side-meeting-folder-closed"),
|
|
icon("folder_open", "pj-side-meeting-folder pj-side-meeting-folder-open"),
|
|
document.createTextNode(month.month + "월"));
|
|
summary.setAttribute("aria-label", month.month + "월 주간 회의록");
|
|
folder.append(summary);
|
|
const weeks = document.createElement("div");
|
|
weeks.className = "pj-side-meeting-weeks";
|
|
month.weeks.forEach(function (week) {
|
|
const link = document.createElement("a");
|
|
link.className = "pj-side-meeting-week";
|
|
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");
|
|
}
|
|
weeks.append(link);
|
|
});
|
|
folder.append(weeks);
|
|
list.append(folder);
|
|
// 접기·펼치기 선택은 같은 브라우저에서 다음 화면에도 유지한다.
|
|
folder.addEventListener("toggle", function () {
|
|
try { localStorage.setItem(key, folder.open ? "1" : "0"); } catch (_) {}
|
|
});
|
|
});
|
|
}
|
|
async function load() {
|
|
if (loading) return;
|
|
loading = true;
|
|
if (retry) retry.disabled = true;
|
|
try {
|
|
const response = await fetch("/project/api/goals/meeting-nav", { credentials: "same-origin" });
|
|
if (!response.ok) throw new Error("회의록 조회 실패");
|
|
const data = await response.json();
|
|
branches.forEach(function (branch) {
|
|
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 (_) {
|
|
// 목록 조회가 실패해도 기존 목표·프로젝트 메뉴는 계속 사용할 수 있다.
|
|
if (!retry) {
|
|
retry = document.createElement("button");
|
|
retry.type = "button";
|
|
retry.className = "pj-side-meeting-retry";
|
|
retry.textContent = "회의록 목록 다시 불러오기";
|
|
retry.addEventListener("click", load);
|
|
branches[branches.length - 1].after(retry);
|
|
}
|
|
retry.disabled = false;
|
|
} finally { loading = false; }
|
|
}
|
|
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();
|
|
})();
|