- 「구조물 관리」 컨테이너 삭제 · 「시스템 설정」을 모든 역할 맨 위 한 줄 · 통째로 접힘(attachCollapsible) - 안은 작은 카드(제목 + 한 줄 설명) 공용 양식 하나 · 역할로 숨김 - 시스템 관리자: 마스터 데이터 · 일위대가 조합 · 구조물 조합 · 구조물 옵션 · 도면 양식 - 회사 관리자 · 개인: 일위대가 조합 · 구조물 조합(마스터 읽기 · 회사 수정|읽기 · 개인 수정) - 카드 누르면 #/m02-master-template?open=…&root=… · 마스터 데이터는 M01 - 시험 test_b01_settings_cards 새로 · test_m02_layer_screen 옛 대시보드 카드 시험 뺌 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ly2oHAaTDYRjcniAmHR81z
265 lines
10 KiB
TypeScript
265 lines
10 KiB
TypeScript
import { ROUTES } from "@config/config_frontend";
|
|
import { attachCollapsible } from "@ui/ui_template_collapsible";
|
|
import {
|
|
createButton,
|
|
createTag,
|
|
hideLoadingOverlay,
|
|
showLoadingOverlay,
|
|
showToast,
|
|
} from "@ui/ui_template_elements";
|
|
import { section } from "@ui/ui_template_general_blocks";
|
|
import { createGeneralLayout } from "@ui/ui_template_general_layout";
|
|
import { navigateTo } from "../A00_Common/router";
|
|
import {
|
|
fetchAllCompanies,
|
|
fetchAllJoinRequests,
|
|
fetchAllProjects,
|
|
fetchAllUsers,
|
|
fetchAuditLogs,
|
|
fetchCompanyJoinRequests,
|
|
fetchCompanyMembers,
|
|
fetchCompanyProjects,
|
|
fetchDashboardMe,
|
|
fetchSystemResources,
|
|
fetchUserCompany,
|
|
fetchUserProjects,
|
|
type AuditLog,
|
|
type CompanyInfo,
|
|
type DashboardUser,
|
|
type JoinRequest,
|
|
type Member,
|
|
type ProjectItem,
|
|
type ResourceData,
|
|
} from "./B01_Dashboard_Api_Fetch";
|
|
import { auditLogTable, userTable } from "./B01_Dashboard_UI_Admin";
|
|
import { L, roleLabel } from "./B01_Dashboard_UI_Common";
|
|
import {
|
|
buildCompanyPanel,
|
|
companyTable,
|
|
joinRequestTable,
|
|
memberTable,
|
|
} from "./B01_Dashboard_UI_Company";
|
|
import { openAddMemberModal, openCreateCompanyModal } from "./B01_Dashboard_UI_Modals";
|
|
import { buildProfileForm, buildSecurityForm } from "./B01_Dashboard_UI_Profile";
|
|
import { projectTable } from "./B01_Dashboard_UI_Projects";
|
|
import { buildResourcePanel } from "./B01_Dashboard_UI_Resources";
|
|
import { buildTempUploadSection } from "./B01_Dashboard_UI_TempUpload";
|
|
import "./B01_Dashboard_UI_Style.css";
|
|
|
|
export interface DashboardState {
|
|
user: DashboardUser;
|
|
userProjects: ProjectItem[];
|
|
companyProjects: ProjectItem[];
|
|
allProjects: ProjectItem[];
|
|
company: CompanyInfo | null;
|
|
members: Member[];
|
|
joinRequests: JoinRequest[];
|
|
allCompanies: CompanyInfo[];
|
|
allUsers: DashboardUser[];
|
|
allJoinRequests: JoinRequest[];
|
|
auditLogs: AuditLog[];
|
|
resources: ResourceData | null;
|
|
}
|
|
|
|
export async function renderB01Dashboard(root: HTMLElement): Promise<void> {
|
|
showLoadingOverlay();
|
|
try {
|
|
const user = await fetchDashboardMe();
|
|
const state: DashboardState = {
|
|
user,
|
|
userProjects: [],
|
|
companyProjects: [],
|
|
allProjects: [],
|
|
company: null,
|
|
members: [],
|
|
joinRequests: [],
|
|
allCompanies: [],
|
|
allUsers: [],
|
|
allJoinRequests: [],
|
|
auditLogs: [],
|
|
resources: null,
|
|
};
|
|
await loadRoleData(state);
|
|
root.innerHTML = "";
|
|
root.append(buildPage(state));
|
|
} catch (error) {
|
|
showToast(error instanceof Error ? error.message : L("B01_Dashboard_LoadFailed"), "error");
|
|
} finally {
|
|
hideLoadingOverlay();
|
|
}
|
|
}
|
|
|
|
async function loadRoleData(state: DashboardState): Promise<void> {
|
|
if (state.user.role === "SYSTEM_ADMIN") {
|
|
const results = await Promise.allSettled([
|
|
fetchAllCompanies(),
|
|
fetchAllUsers(),
|
|
fetchAllJoinRequests(),
|
|
fetchAuditLogs(),
|
|
fetchSystemResources(7),
|
|
fetchAllProjects(),
|
|
]);
|
|
state.allCompanies = results[0].status === "fulfilled" ? results[0].value : [];
|
|
state.allUsers = results[1].status === "fulfilled" ? results[1].value : [];
|
|
state.allJoinRequests = results[2].status === "fulfilled" ? results[2].value : [];
|
|
state.auditLogs = results[3].status === "fulfilled" ? results[3].value : [];
|
|
state.resources = results[4].status === "fulfilled" ? results[4].value : null;
|
|
state.allProjects = results[5].status === "fulfilled" ? results[5].value : [];
|
|
|
|
results.forEach((res, idx) => {
|
|
if (res.status === "rejected") {
|
|
console.error(`System Admin API failed at index ${idx}:`, res.reason);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
const [projects, company] = await Promise.all([
|
|
fetchUserProjects().catch(() => []),
|
|
fetchUserCompany().catch(() => null),
|
|
]);
|
|
state.userProjects = projects;
|
|
state.company = company;
|
|
if (state.user.role === "ADMIN") {
|
|
const [members, requests, companyProjects] = await Promise.all([
|
|
fetchCompanyMembers().catch(() => []),
|
|
fetchCompanyJoinRequests().catch(() => []),
|
|
fetchCompanyProjects().catch(() => []),
|
|
]);
|
|
state.members = members;
|
|
state.joinRequests = requests;
|
|
state.companyProjects = companyProjects;
|
|
}
|
|
}
|
|
|
|
/** 설정 카드 공용 양식 — 제목 + 한 줄 설명 · 누르면 이동 */
|
|
function settingCard(title: string, desc: string, go: () => void): HTMLElement {
|
|
const card = document.createElement("button");
|
|
card.type = "button";
|
|
card.className = "b01-dashboard__setting-card";
|
|
const head = document.createElement("strong");
|
|
head.className = "b01-dashboard__setting-title";
|
|
head.textContent = title;
|
|
const sub = document.createElement("span");
|
|
sub.className = "b01-dashboard__setting-desc";
|
|
sub.textContent = desc;
|
|
card.append(head, sub);
|
|
card.addEventListener("click", go);
|
|
return card;
|
|
}
|
|
|
|
/** 시스템 설정 — 역할로 카드 숨김 · M02 카드는 `?open=&root=` 로 진입(27-1d) */
|
|
function buildSystemSettingsPanel(user: DashboardUser): HTMLElement {
|
|
const wrap = document.createElement("div");
|
|
wrap.className = "b01-dashboard__setting-grid";
|
|
const m02 = (title: string, open: string, root: string, desc: string): HTMLElement =>
|
|
settingCard(title, desc, () => navigateTo(ROUTES.M02_MASTER_TEMPLATE, { open, root }));
|
|
if (user.role === "SYSTEM_ADMIN") {
|
|
const desc = L("B01_Dashboard_PermMasterWrite");
|
|
wrap.append(
|
|
settingCard(L("B01_Dashboard_MasterElements"), L("B01_Dashboard_PermSourceRead"), () =>
|
|
navigateTo(ROUTES.M01_MASTER_DATA),
|
|
),
|
|
m02(L("B01_Dashboard_CardUnitCombo"), "일위대가", "master", desc),
|
|
m02(L("B01_Dashboard_CardStructCombo"), "구조물조합", "master", desc),
|
|
m02(L("B01_Dashboard_CardStructOption"), "옵션", "master", desc),
|
|
m02(L("B01_Dashboard_CardDrawing"), "도면", "master", desc),
|
|
);
|
|
return wrap;
|
|
}
|
|
// 회사 수정 = 회사 관리자 · 회사 마스터(M02 accessFor 와 같은 규칙)
|
|
const companyAdmin = user.role === "ADMIN" || user.is_master;
|
|
const root = companyAdmin ? "company" : "personal";
|
|
const desc = [
|
|
L("B01_Dashboard_PermMasterRead"),
|
|
L(companyAdmin ? "B01_Dashboard_PermCompanyWrite" : "B01_Dashboard_PermCompanyRead"),
|
|
L("B01_Dashboard_PermPersonalWrite"),
|
|
].join(" · ");
|
|
wrap.append(
|
|
m02(L("B01_Dashboard_CardUnitCombo"), "일위대가", root, desc),
|
|
m02(L("B01_Dashboard_CardStructCombo"), "구조물조합", root, desc),
|
|
);
|
|
return wrap;
|
|
}
|
|
|
|
/** 시스템 설정 컨테이너 — 모든 역할 · 한 줄 통째 · 제목 눌러 통째로 접힘 */
|
|
function buildSystemSettingsSection(user: DashboardUser): HTMLElement {
|
|
const card = section(L("B01_Dashboard_SystemSettings"), buildSystemSettingsPanel(user), true);
|
|
card.querySelector(".ui-card__body")?.classList.add("ui-collapsible");
|
|
card.querySelector(".b01-dashboard__section-header")?.classList.add("ui-collapsible__title");
|
|
attachCollapsible(card);
|
|
return card;
|
|
}
|
|
|
|
function buildPage(state: DashboardState): HTMLElement {
|
|
// 제목·여백은 공용 템플릿을 따른다 (2026-09-06 사용자 지시) — B02 등 다른 화면과 같은 모양.
|
|
const page = document.createElement("div");
|
|
|
|
const grid = document.createElement("div");
|
|
grid.className = "b01-dashboard__grid";
|
|
// 시스템 설정은 모든 역할 맨 위 한 줄(27-3a)
|
|
grid.append(buildSystemSettingsSection(state.user));
|
|
|
|
if (state.user.role === "SYSTEM_ADMIN") {
|
|
grid.append(
|
|
section(L("B01_Dashboard_Resources"), buildResourcePanel(state.resources), true),
|
|
section(L("B01_Dashboard_Projects"), projectTable(state.allProjects, state.user), true, [
|
|
createButton({ label: "+", onClick: () => navigateTo(ROUTES.B02_PROJ_REGISTER) }),
|
|
]),
|
|
buildTempUploadSection(),
|
|
section(L("B01_Dashboard_Users"), userTable(state.allUsers, state.user), true, [
|
|
createButton({ label: "+", onClick: () => openAddMemberModal() }),
|
|
]),
|
|
section(L("B01_Dashboard_JoinRequests"), joinRequestTable(state.allJoinRequests, true), true),
|
|
section(L("B01_Dashboard_Companies"), companyTable(state.allCompanies, state.user), true, [
|
|
createButton({ label: "+", onClick: () => openCreateCompanyModal() }),
|
|
]),
|
|
);
|
|
} else if (state.user.role === "ADMIN") {
|
|
grid.append(
|
|
section(L("B01_Dashboard_Projects"), projectTable(state.companyProjects, state.user), true, [
|
|
createButton({ label: "+", onClick: () => navigateTo(ROUTES.B02_PROJ_REGISTER) }),
|
|
]),
|
|
buildTempUploadSection(),
|
|
section(L("B01_Dashboard_Members"), memberTable(state.members, state.user), true, [
|
|
createButton({ label: "+", onClick: () => openAddMemberModal() }),
|
|
]),
|
|
section(L("B01_Dashboard_JoinRequests"), joinRequestTable(state.joinRequests, false), true),
|
|
section(L("B01_Dashboard_Company"), buildCompanyPanel(state), true),
|
|
);
|
|
} else {
|
|
grid.append(
|
|
section(L("B01_Dashboard_Projects"), projectTable(state.userProjects, state.user), true, [
|
|
createButton({ label: "+", onClick: () => navigateTo(ROUTES.B02_PROJ_REGISTER) }),
|
|
]),
|
|
// 임시 보관함 — 프로젝트를 만들기 전에 자료를 올려 두는 곳이라 프로젝트 목록
|
|
// 바로 아래에 둔다(2026-08-08 사용자 지시).
|
|
buildTempUploadSection(),
|
|
section(L("B01_Dashboard_Company"), buildCompanyPanel(state), true),
|
|
);
|
|
}
|
|
|
|
grid.append(
|
|
section(L("B01_Dashboard_Profile"), buildProfileForm(state.user)),
|
|
section(L("B01_Account_Section_Security"), buildSecurityForm()),
|
|
);
|
|
// 시스템 로그는 맨 아래 (2026-09-06 사용자 지시).
|
|
if (state.user.role === "SYSTEM_ADMIN") {
|
|
grid.append(section(L("B01_Dashboard_AuditLogs"), auditLogTable(state.auditLogs), true));
|
|
}
|
|
page.append(grid);
|
|
const layout = createGeneralLayout({
|
|
pageClass: "b01-dashboard",
|
|
title: L("B01_Dashboard_Title"),
|
|
subtitle: L("B01_Dashboard_Subtitle"),
|
|
content: page,
|
|
});
|
|
// 역할 배지는 제목 줄 오른쪽에 둔다(자리는 CSS 격자가 잡는다).
|
|
const tag = createTag(
|
|
roleLabel(state.user.role),
|
|
state.user.role === "SYSTEM_ADMIN" ? "accent" : "neutral",
|
|
);
|
|
tag.classList.add("b01-dashboard__role");
|
|
layout.root.querySelector(".ui-general-layout__header")?.append(tag);
|
|
return layout.root;
|
|
}
|