Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ee4cd94
Initial setup with dummy data #1663
verheyenkoen Jul 30, 2024
c331870
Merge branch 'dev' into feature/details-sidebar
verheyenkoen Sep 26, 2024
1df2915
Refactored details sidebar into components #1663
verheyenkoen Sep 27, 2024
b6891f4
Refactored details sidebar concrete content to publication page #1663
verheyenkoen Sep 30, 2024
f526db1
Implemented info pane for publication #1663
verheyenkoen Sep 30, 2024
b639798
Merge branch 'dev' into feature/details-sidebar
verheyenkoen Oct 1, 2024
7a79479
Removed Plato link (not a general site) #1663
verheyenkoen Oct 1, 2024
8391f06
Implemented publication activity history pane #1663
verheyenkoen Oct 1, 2024
1a14563
Added more identifiers to publication info pane: (E-)ISSN & (E-)ISBN …
verheyenkoen Oct 3, 2024
cd9fe4f
Implemented dataset activity history and info panes #1663
verheyenkoen Oct 3, 2024
6b5ac09
Implemented publication messages pane #1663
verheyenkoen Oct 8, 2024
e9e891a
Fixed publication messages tests #1663
verheyenkoen Oct 9, 2024
ce031a3
Implemented dataset messages pane #1663
verheyenkoen Oct 9, 2024
560b8e4
Fixed dataset messages tests #1663
verheyenkoen Oct 9, 2024
a27b111
Use handle.net URL for public biblio location link in info pane #1663
verheyenkoen Oct 11, 2024
f2fd21d
Show only 20 most recent publication/dataset history activities #1663
verheyenkoen Oct 11, 2024
b88b7db
Added script for storing active sidebar pane by publication/dataset I…
verheyenkoen Oct 15, 2024
cc6b4c5
Only initialise details sidebar in HTMX load event cycle + fix close …
verheyenkoen Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import collapseSubSidebar from "./ui/collapsible_sub_sidebar.js";
import fileUpload from "./ui/file_upload.js";
import tags from "./ui/tags.js";
import facetDropdowns from "./ui/facet_dropdowns.js";
import initSidebarMenu from "./ui/sidebar_menu.ts";
import initSearchFields from "./ui/search";

// configure htmx
Expand Down Expand Up @@ -51,4 +52,5 @@ document.addEventListener("DOMContentLoaded", function () {
htmx.onLoad(function (el) {
clipboard(el);
initSearchFields(el);
initSidebarMenu(el);
});
125 changes: 125 additions & 0 deletions assets/js/ui/sidebar_menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
const LOCAL_STORAGE_KEY = "detail-sidebar-state";
const DEFAULT_SIDEBAR_STATE = "sidebar-message";

export default function initSidebarMenu(el) {
const menuButtons = el.querySelectorAll("[data-sidebar-menu] button");
const closeButtons = el.querySelectorAll("[data-sidebar-close]");

menuButtons.forEach((button) => {
button.addEventListener("click", () => {
const targetId = button.getAttribute("data-target-id");
const targetContent = document.getElementById(targetId);

// Check if the target content is currently displayed.
if (targetContent.classList.contains("open")) {
// If so, hide it.
targetContent.classList.remove("open");
button.classList.remove("active");

setActiveSidebar(null);
} else {
// If not, hide all contents and show the target content.
document
.querySelectorAll("[data-sidebar-content]")
.forEach((c) => c.classList.remove("open"));
menuButtons.forEach((btn) => btn.classList.remove("active"));

targetContent.classList.add("open");
button.classList.add("active");

setActiveSidebar(targetId);
}
});
});

closeButtons.forEach((button) => {
button.addEventListener("click", () => {
const parentContent = button.closest("[data-sidebar-content]");
if (parentContent) {
parentContent.classList.remove("open");

// Find the corresponding menu button and remove active class.
getSidebarNavLink(parentContent.id)?.classList.remove("active");

setActiveSidebar(null);
}
});
});

// Set initial active sidebar
const activeSidebar = getActiveSidebar();
if (activeSidebar) {
document.getElementById(activeSidebar)?.classList.add("open");
getSidebarNavLink(activeSidebar)?.classList.add("active");
}
}

function getSidebarNavLink(targetId: string): HTMLAnchorElement | null {
return document.querySelector(
`[data-sidebar-menu] .nav-link[data-target-id="${targetId}"]`,
);
}

function getActiveSidebar(): string | undefined {
const key = getPageKey();
if (key) {
const state = getDetailSidebarState();

if (state.has(key)) {
return state.get(key);
} else {
return DEFAULT_SIDEBAR_STATE;
}
}
}

function setActiveSidebar(activeSidebar: string | null) {
const key = getPageKey();
if (key) {
const state = getDetailSidebarState();
if (activeSidebar !== DEFAULT_SIDEBAR_STATE) {
state.set(key, activeSidebar);
} else {
state.delete(key);
}

localStorage.setItem(
LOCAL_STORAGE_KEY,
JSON.stringify(Object.fromEntries(state)),
);
}
}

let sidebarState: Map<string, string> = null;

function getDetailSidebarState(): Map<string, string> {
if (!sidebarState) {
const savedState = localStorage.getItem(LOCAL_STORAGE_KEY);
if (savedState) {
try {
const state = JSON.parse(savedState) as Record<string, string>;

sidebarState = new Map(Object.entries(state));
} catch (err) {
console.warn(
`There was an error parsing the saved state with key "${LOCAL_STORAGE_KEY}": `,
err,
);

sidebarState = new Map();
}
} else {
sidebarState = new Map();
}
}

return sidebarState;
}

function getPageKey() {
const regex = /^\/(publication|dataset)\/(?<id>[A-Z0-9]{10,})$/;

const match = document.location.pathname.match(regex);

return match?.groups?.id;
}
162 changes: 0 additions & 162 deletions cypress/e2e/datasets/edit/biblio-messages.cy.ts

This file was deleted.

Loading