feat: add scenarios list page with metrics and quick actions
- Introduced a new template for listing scenarios associated with a project. - Added metrics for total, active, draft, and archived scenarios. - Implemented quick actions for creating new scenarios and reviewing project overview. - Enhanced navigation with breadcrumbs for better user experience. refactor: update Opex and Profitability templates for consistency - Changed titles and button labels for clarity in Opex and Profitability templates. - Updated form IDs and action URLs for better alignment with new naming conventions. - Improved navigation links to include scenario and project overviews. test: add integration tests for Opex calculations - Created new tests for Opex calculation HTML and JSON flows. - Validated successful calculations and ensured correct data persistence. - Implemented tests for currency mismatch and unsupported frequency scenarios. test: enhance project and scenario route tests - Added tests to verify scenario list rendering and calculator shortcuts. - Ensured scenario detail pages link back to the portfolio correctly. - Validated project detail pages show associated scenarios accurately.
This commit is contained in:
@@ -367,17 +367,17 @@ a.sidebar-brand:focus {
|
||||
.sidebar-nav-controls {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
gap: 1rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.nav-chevron {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
width: 5rem;
|
||||
height: 5rem;
|
||||
border: none;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
font-size: 1.2rem;
|
||||
font-size: 4.5rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
@@ -388,8 +388,9 @@ a.sidebar-brand:focus {
|
||||
|
||||
.nav-chevron:hover,
|
||||
.nav-chevron:focus {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(1.05);
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
color: rgba(255, 255, 255, 1);
|
||||
transform: scale(0.9);
|
||||
}
|
||||
|
||||
.nav-chevron:disabled {
|
||||
@@ -1188,8 +1189,16 @@ footer a:focus {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.sidebar-nav-controls {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar-link-block {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sidebar-link {
|
||||
flex: 1 1 140px;
|
||||
flex: 1 1 40px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
@@ -1219,6 +1228,10 @@ footer a:focus {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body.sidebar-open .app-main {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
body.sidebar-open .app-sidebar {
|
||||
display: block;
|
||||
position: fixed;
|
||||
@@ -1227,7 +1240,7 @@ footer a:focus {
|
||||
width: min(320px, 82vw);
|
||||
height: 100vh;
|
||||
overflow-y: auto;
|
||||
z-index: 900;
|
||||
z-index: 999;
|
||||
box-shadow: 0 12px 30px rgba(8, 14, 25, 0.4);
|
||||
}
|
||||
|
||||
@@ -1235,9 +1248,4 @@ footer a:focus {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
body.sidebar-open .app-main {
|
||||
position: relative;
|
||||
z-index: 950;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,108 @@
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.projects-grid {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.project-card {
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--card-border);
|
||||
box-shadow: var(--shadow);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.25rem;
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.project-card:hover,
|
||||
.project-card:focus-within {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 22px 45px rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
.project-card__header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.project-card__title {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.project-card__title a {
|
||||
color: var(--brand);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.project-card__title a:hover,
|
||||
.project-card__title a:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.project-card__type {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.project-card__description {
|
||||
margin: 0;
|
||||
color: var(--color-text-subtle);
|
||||
min-height: 3rem;
|
||||
}
|
||||
|
||||
.project-card__meta {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||
}
|
||||
|
||||
.project-card__meta div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.project-card__meta dt {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
color: var(--muted);
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.project-card__meta dd {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.project-card__footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.project-card__links {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.project-card__links .btn-link {
|
||||
padding: 3px 4px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.project-metrics {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
@@ -87,6 +189,163 @@
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.project-column {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.project-actions-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.quick-link-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.quick-link-list li a {
|
||||
font-weight: 600;
|
||||
color: var(--brand-2);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.quick-link-list li a:hover,
|
||||
.quick-link-list li a:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.quick-link-list p {
|
||||
margin: 0.25rem 0 0;
|
||||
color: var(--color-text-subtle);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.project-scenarios-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.project-scenarios-card__header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.project-scenarios-card__header h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.scenario-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.scenario-item {
|
||||
background: rgba(21, 27, 35, 0.85);
|
||||
border: 1px solid var(--card-border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.25rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.scenario-item__body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.scenario-item__header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.scenario-item__header h3 {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.scenario-item__header a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.scenario-item__header a:hover,
|
||||
.scenario-item__header a:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.status-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.status-pill--draft {
|
||||
background: rgba(59, 130, 246, 0.15);
|
||||
color: #93c5fd;
|
||||
}
|
||||
|
||||
.status-pill--active {
|
||||
background: rgba(34, 197, 94, 0.18);
|
||||
color: #86efac;
|
||||
}
|
||||
|
||||
.status-pill--archived {
|
||||
background: rgba(148, 163, 184, 0.24);
|
||||
color: #cbd5f5;
|
||||
}
|
||||
|
||||
.scenario-item__meta {
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
}
|
||||
|
||||
.scenario-item__meta dt {
|
||||
margin: 0;
|
||||
font-size: 0.75rem;
|
||||
color: var(--muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.scenario-item__meta dd {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.scenario-item__actions {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.scenario-item__actions .btn-link {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -151,6 +410,16 @@
|
||||
.header-actions {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.scenario-item {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.scenario-item__body {
|
||||
max-width: 70%;
|
||||
}
|
||||
}
|
||||
|
||||
.form {
|
||||
|
||||
@@ -106,6 +106,76 @@
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
.scenario-form .card {
|
||||
background: rgba(21, 27, 35, 0.9);
|
||||
border: 1px solid var(--card-border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.scenario-form .card h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.scenario-form .form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.scenario-form .form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.scenario-form .form-group label {
|
||||
font-weight: 600;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.scenario-form .form-group input,
|
||||
.scenario-form .form-group select,
|
||||
.scenario-form .form-group textarea {
|
||||
padding: 0.75rem 0.85rem;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--card-border);
|
||||
background: rgba(8, 12, 19, 0.78);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.scenario-form .form-group textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.scenario-form .form-group input:focus,
|
||||
.scenario-form .form-group select:focus,
|
||||
.scenario-form .form-group textarea:focus {
|
||||
outline: 2px solid var(--brand-2);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
.form-group--error input,
|
||||
.form-group--error select,
|
||||
.form-group--error textarea {
|
||||
border-color: rgba(209, 75, 75, 0.6);
|
||||
box-shadow: 0 0 0 1px rgba(209, 75, 75, 0.3);
|
||||
}
|
||||
|
||||
.field-help {
|
||||
margin: 0;
|
||||
font-size: 0.85rem;
|
||||
color: var(--color-text-subtle);
|
||||
}
|
||||
|
||||
.field-error {
|
||||
margin: 0;
|
||||
font-size: 0.85rem;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.table-responsive {
|
||||
width: 100%;
|
||||
@@ -165,12 +235,214 @@
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
.scenario-column {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.quick-actions-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.quick-link-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.quick-link-list li a {
|
||||
font-weight: 600;
|
||||
color: var(--brand-2);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.quick-link-list li a:hover,
|
||||
.quick-link-list li a:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.quick-link-list p {
|
||||
margin: 0.25rem 0 0;
|
||||
color: var(--color-text-subtle);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.status-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.35rem 0.85rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.status-pill--draft {
|
||||
background: rgba(59, 130, 246, 0.15);
|
||||
color: #93c5fd;
|
||||
}
|
||||
|
||||
.status-pill--active {
|
||||
background: rgba(34, 197, 94, 0.18);
|
||||
color: #86efac;
|
||||
}
|
||||
|
||||
.status-pill--archived {
|
||||
background: rgba(148, 163, 184, 0.24);
|
||||
color: #cbd5f5;
|
||||
}
|
||||
|
||||
@media (min-width: 960px) {
|
||||
.scenario-layout {
|
||||
grid-template-columns: 1.1fr 1.9fr;
|
||||
align-items: start;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
color: var(--muted);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.scenario-portfolio {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.scenario-portfolio__header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.scenario-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.scenario-item {
|
||||
background: rgba(21, 27, 35, 0.85);
|
||||
border: 1px solid var(--card-border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.25rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.scenario-item__body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.scenario-item__header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.scenario-item__header h3 {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.scenario-item__header a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.scenario-item__header a:hover,
|
||||
.scenario-item__header a:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.scenario-item__meta {
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
}
|
||||
|
||||
.scenario-item__meta dt {
|
||||
margin: 0;
|
||||
font-size: 0.75rem;
|
||||
color: var(--muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.scenario-item__meta dd {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.scenario-item__actions {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.scenario-item__actions .btn-link {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@media (min-width: 960px) {
|
||||
.scenario-item {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.scenario-item__body {
|
||||
max-width: 70%;
|
||||
}
|
||||
}
|
||||
|
||||
.scenario-context-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.scenario-context-card .definition-list {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.scenario-defaults {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.scenario-defaults li {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.scenario-defaults li strong {
|
||||
font-size: 0.9rem;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
@media (min-width: 960px) {
|
||||
.header-actions {
|
||||
justify-content: flex-start;
|
||||
|
||||
230
static/js/navigation_sidebar.js
Normal file
230
static/js/navigation_sidebar.js
Normal file
@@ -0,0 +1,230 @@
|
||||
(function () {
|
||||
const NAV_ENDPOINT = "/navigation/sidebar";
|
||||
const SIDEBAR_SELECTOR = ".sidebar-nav";
|
||||
const DATA_SOURCE_ATTR = "navigationSource";
|
||||
const ROLE_ATTR = "navigationRoles";
|
||||
|
||||
function onReady(callback) {
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", callback, { once: true });
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function isActivePath(pathname, matchPrefix) {
|
||||
if (!matchPrefix) {
|
||||
return false;
|
||||
}
|
||||
if (matchPrefix === "/") {
|
||||
return pathname === "/";
|
||||
}
|
||||
return pathname.startsWith(matchPrefix);
|
||||
}
|
||||
|
||||
function createAnchor({
|
||||
href,
|
||||
label,
|
||||
matchPrefix,
|
||||
tooltip,
|
||||
isExternal,
|
||||
isActive,
|
||||
className,
|
||||
}) {
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = href;
|
||||
anchor.className = className + (isActive ? " is-active" : "");
|
||||
anchor.dataset.matchPrefix = matchPrefix || href;
|
||||
if (tooltip) {
|
||||
anchor.title = tooltip;
|
||||
}
|
||||
if (isExternal) {
|
||||
anchor.target = "_blank";
|
||||
anchor.rel = "noopener noreferrer";
|
||||
anchor.classList.add("is-external");
|
||||
}
|
||||
anchor.textContent = label;
|
||||
return anchor;
|
||||
}
|
||||
|
||||
function buildLinkBlock(link, pathname) {
|
||||
if (!link || !link.href) {
|
||||
return null;
|
||||
}
|
||||
const matchPrefix = link.match_prefix || link.matchPrefix || link.href;
|
||||
const isActive = isActivePath(pathname, matchPrefix);
|
||||
|
||||
const block = document.createElement("div");
|
||||
block.className = "sidebar-link-block";
|
||||
if (typeof link.id === "number") {
|
||||
block.dataset.linkId = String(link.id);
|
||||
}
|
||||
|
||||
const anchor = createAnchor({
|
||||
href: link.href,
|
||||
label: link.label,
|
||||
matchPrefix,
|
||||
tooltip: link.tooltip,
|
||||
isExternal: Boolean(link.is_external ?? link.isExternal),
|
||||
isActive,
|
||||
className: "sidebar-link",
|
||||
});
|
||||
block.appendChild(anchor);
|
||||
|
||||
const children = Array.isArray(link.children) ? link.children : [];
|
||||
if (children.length > 0) {
|
||||
const container = document.createElement("div");
|
||||
container.className = "sidebar-sublinks";
|
||||
for (const child of children) {
|
||||
if (!child || !child.href) {
|
||||
continue;
|
||||
}
|
||||
const childMatch =
|
||||
child.match_prefix || child.matchPrefix || child.href;
|
||||
const childActive = isActivePath(pathname, childMatch);
|
||||
const childAnchor = createAnchor({
|
||||
href: child.href,
|
||||
label: child.label,
|
||||
matchPrefix: childMatch,
|
||||
tooltip: child.tooltip,
|
||||
isExternal: Boolean(child.is_external ?? child.isExternal),
|
||||
isActive: childActive,
|
||||
className: "sidebar-sublink",
|
||||
});
|
||||
container.appendChild(childAnchor);
|
||||
}
|
||||
if (container.children.length > 0) {
|
||||
block.appendChild(container);
|
||||
}
|
||||
}
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
function buildGroupSection(group, pathname) {
|
||||
if (!group) {
|
||||
return null;
|
||||
}
|
||||
const links = Array.isArray(group.links) ? group.links : [];
|
||||
if (links.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const section = document.createElement("div");
|
||||
section.className = "sidebar-section";
|
||||
if (typeof group.id === "number") {
|
||||
section.dataset.groupId = String(group.id);
|
||||
}
|
||||
|
||||
const label = document.createElement("div");
|
||||
label.className = "sidebar-section-label";
|
||||
label.textContent = group.label;
|
||||
section.appendChild(label);
|
||||
|
||||
const linksContainer = document.createElement("div");
|
||||
linksContainer.className = "sidebar-section-links";
|
||||
|
||||
for (const link of links) {
|
||||
const block = buildLinkBlock(link, pathname);
|
||||
if (block) {
|
||||
linksContainer.appendChild(block);
|
||||
}
|
||||
}
|
||||
|
||||
if (linksContainer.children.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
section.appendChild(linksContainer);
|
||||
return section;
|
||||
}
|
||||
|
||||
function buildEmptyState() {
|
||||
const section = document.createElement("div");
|
||||
section.className = "sidebar-section sidebar-empty-state";
|
||||
|
||||
const label = document.createElement("div");
|
||||
label.className = "sidebar-section-label";
|
||||
label.textContent = "Navigation";
|
||||
section.appendChild(label);
|
||||
|
||||
const copyWrapper = document.createElement("div");
|
||||
copyWrapper.className = "sidebar-section-links";
|
||||
|
||||
const copy = document.createElement("p");
|
||||
copy.className = "sidebar-empty-copy";
|
||||
copy.textContent = "Navigation is unavailable.";
|
||||
copyWrapper.appendChild(copy);
|
||||
|
||||
section.appendChild(copyWrapper);
|
||||
return section;
|
||||
}
|
||||
|
||||
function renderSidebar(navContainer, payload) {
|
||||
const pathname = window.location.pathname;
|
||||
const groups = Array.isArray(payload?.groups) ? payload.groups : [];
|
||||
navContainer.replaceChildren();
|
||||
|
||||
const rendered = [];
|
||||
for (const group of groups) {
|
||||
const section = buildGroupSection(group, pathname);
|
||||
if (section) {
|
||||
rendered.push(section);
|
||||
}
|
||||
}
|
||||
|
||||
if (rendered.length === 0) {
|
||||
navContainer.appendChild(buildEmptyState());
|
||||
navContainer.dataset[DATA_SOURCE_ATTR] = "client-empty";
|
||||
delete navContainer.dataset[ROLE_ATTR];
|
||||
return;
|
||||
}
|
||||
|
||||
for (const section of rendered) {
|
||||
navContainer.appendChild(section);
|
||||
}
|
||||
|
||||
navContainer.dataset[DATA_SOURCE_ATTR] = "client";
|
||||
const roles = Array.isArray(payload?.roles) ? payload.roles : [];
|
||||
if (roles.length > 0) {
|
||||
navContainer.dataset[ROLE_ATTR] = roles.join(",");
|
||||
} else {
|
||||
delete navContainer.dataset[ROLE_ATTR];
|
||||
}
|
||||
}
|
||||
|
||||
async function hydrateSidebar(navContainer) {
|
||||
try {
|
||||
const response = await fetch(NAV_ENDPOINT, {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status !== 401 && response.status !== 403) {
|
||||
console.warn(
|
||||
"Navigation sidebar hydration failed with status",
|
||||
response.status
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = await response.json();
|
||||
renderSidebar(navContainer, payload);
|
||||
} catch (error) {
|
||||
console.warn("Navigation sidebar hydration failed", error);
|
||||
}
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
const navContainer = document.querySelector(SIDEBAR_SELECTOR);
|
||||
if (!navContainer) {
|
||||
return;
|
||||
}
|
||||
hydrateSidebar(navContainer);
|
||||
});
|
||||
})();
|
||||
@@ -1,14 +1,35 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const table = document.querySelector("[data-project-table]");
|
||||
const rows = table ? Array.from(table.querySelectorAll("tbody tr")) : [];
|
||||
const container = document.querySelector("[data-project-table]");
|
||||
const filterInput = document.querySelector("[data-project-filter]");
|
||||
|
||||
if (table && filterInput) {
|
||||
const resolveFilterItems = () => {
|
||||
if (!container) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const entries = Array.from(
|
||||
container.querySelectorAll("[data-project-entry]")
|
||||
);
|
||||
|
||||
if (entries.length) {
|
||||
return entries;
|
||||
}
|
||||
|
||||
if (container.tagName === "TABLE") {
|
||||
return Array.from(container.querySelectorAll("tbody tr"));
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
const filterItems = resolveFilterItems();
|
||||
|
||||
if (container && filterInput && filterItems.length) {
|
||||
filterInput.addEventListener("input", () => {
|
||||
const query = filterInput.value.trim().toLowerCase();
|
||||
rows.forEach((row) => {
|
||||
const match = row.textContent.toLowerCase().includes(query);
|
||||
row.style.display = match ? "" : "none";
|
||||
filterItems.forEach((item) => {
|
||||
const match = item.textContent.toLowerCase().includes(query);
|
||||
item.style.display = match ? "" : "none";
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user