Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 27 additions & 17 deletions web/static/admin_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var Validity;
Validity["onsite"] = "onsite";
})(Validity || (Validity = {}));
const allAccessModes = ["readers", "writers", "reporters"];
let events;
let sortedEvents;
let accessControlList = null;
async function loadAccessControlList() {
const { json: eventsJson, err: eventsErr } = await ims.fetchNoThrow(url_events + "?include_groups=true", {
Expand All @@ -63,7 +63,7 @@ async function loadAccessControlList() {
window.alert(message);
return { err: message };
}
events = eventsJson ?? [];
const events = eventsJson ?? [];
const { json, err } = await ims.fetchNoThrow(url_acl, null);
if (err != null) {
const message = `Failed to load access control list: ${err}`;
Expand All @@ -72,18 +72,8 @@ async function loadAccessControlList() {
return { err: message };
}
accessControlList = json;
return { err: null };
}
function drawAccess() {
const container = document.getElementById("event_access_container");
container.replaceChildren();
if (accessControlList == null) {
return;
}
const accessTemplate = document.getElementById("event_access_template");
const accessModeTemplate = document.getElementById("event_access_mode_template");
// Sort by group status first, then by name
const sortedEvents = events.toSorted((a, b) => {
sortedEvents = events.toSorted((a, b) => {
const aGroup = a.is_group ? a.id : (a.parent_group ?? -1);
const bGroup = b.is_group ? b.id : (b.parent_group ?? -1);
if (aGroup !== bGroup) {
Expand All @@ -94,14 +84,24 @@ function drawAccess() {
}
return b.name.localeCompare(a.name);
});
return { err: null };
}
function drawAccess() {
const container = document.getElementById("event_access_container");
container.replaceChildren();
if (accessControlList == null) {
return;
}
const accessTemplate = document.getElementById("event_access_template");
const accessModeTemplate = document.getElementById("event_access_mode_template");
for (const event of sortedEvents) {
const eventAccessFrag = accessTemplate.content.cloneNode(true);
let eventWithGroupName = event.name;
if (event.is_group) {
eventWithGroupName = `Group: ${eventWithGroupName}`;
}
if (event.parent_group) {
const parentGroup = events.find(value => { return value.id === event.parent_group; });
const parentGroup = sortedEvents.find(value => { return value.id === event.parent_group; });
if (parentGroup) {
eventWithGroupName += ` (${parentGroup.name})`;
}
Expand All @@ -117,7 +117,7 @@ function drawAccess() {
const parentGroupInput = editEventModalElement.querySelector("#edit_parent_group");
// groups can't have parent groups
parentGroupInput.disabled = event.is_group ?? false;
const currentParent = events.find(value => { return value.id === event.parent_group; });
const currentParent = sortedEvents.find(value => { return value.id === event.parent_group; });
parentGroupInput.value = currentParent?.name ?? "";
editEventModal?.show();
});
Expand Down Expand Up @@ -223,7 +223,17 @@ function updateEventAccess(event, mode) {
if (explainMsgs.length === 0) {
explainMsgs.push("No permissions");
}
modal.querySelector(".modal-body").textContent = explainMsgs.join("\n");
const modalBody = modal.querySelector(".modal-body");
modalBody.textContent = explainMsgs.join("\n");
const eventData = sortedEvents.find(value => { return value.name === event; });
if (eventData && eventData.is_group) {
modalBody.textContent += "\n\nThis is an event group, so all permissions above also apply to its child events:\n";
for (const event of sortedEvents) {
if (event.parent_group === eventData.id) {
modalBody.textContent += `${indent}${event.name}\n`;
}
}
}
explainModal?.show();
});
}
Expand Down Expand Up @@ -430,7 +440,7 @@ async function setParentGroup(sender) {
requestBod.parent_group = 0;
}
else {
const newParent = events.find(value => { return value.name === parentGroupName; });
const newParent = sortedEvents.find(value => { return value.name === parentGroupName; });
if (!newParent) {
const message = `No group by that name`;
console.log(message);
Expand Down
47 changes: 28 additions & 19 deletions web/typescript/admin_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type EventAccess = Partial<Record<AccessMode, Access[]>>;
// key is event name
type EventsAccess = Record<string, EventAccess|null>;

let events: ims.EventData[];
let sortedEvents: ims.EventData[];
let accessControlList: EventsAccess|null = null;

async function loadAccessControlList() : Promise<{err: string|null}> {
Expand All @@ -106,7 +106,7 @@ async function loadAccessControlList() : Promise<{err: string|null}> {
window.alert(message);
return {err: message};
}
events = eventsJson??[];
const events = eventsJson??[];
const {json, err} = await ims.fetchNoThrow<EventsAccess>(url_acl, null);
if (err != null) {
const message = `Failed to load access control list: ${err}`;
Expand All @@ -115,6 +115,18 @@ async function loadAccessControlList() : Promise<{err: string|null}> {
return {err: message};
}
accessControlList = json;
// Sort by group status first, then by name
sortedEvents = events.toSorted((a: ims.EventData, b: ims.EventData): number => {
const aGroup = a.is_group ? a.id : (a.parent_group??-1);
const bGroup = b.is_group ? b.id : (b.parent_group??-1);
if (aGroup !== bGroup) {
return bGroup-aGroup;
}
if (a.is_group !== b.is_group) {
return a.is_group ? -1 : 1;
}
return b.name.localeCompare(a.name);
});
return {err: null};
}

Expand All @@ -128,19 +140,6 @@ function drawAccess(): void {
const accessTemplate = document.getElementById("event_access_template") as HTMLTemplateElement;
const accessModeTemplate = document.getElementById("event_access_mode_template") as HTMLTemplateElement;

// Sort by group status first, then by name
const sortedEvents: ims.EventData[] = events.toSorted((a: ims.EventData, b: ims.EventData): number => {
const aGroup = a.is_group ? a.id : (a.parent_group??-1);
const bGroup = b.is_group ? b.id : (b.parent_group??-1);
if (aGroup !== bGroup) {
return bGroup-aGroup;
}
if (a.is_group !== b.is_group) {
return a.is_group ? -1 : 1;
}
return b.name.localeCompare(a.name);
});

for (const event of sortedEvents) {
const eventAccessFrag = accessTemplate.content.cloneNode(true) as DocumentFragment;

Expand All @@ -149,7 +148,7 @@ function drawAccess(): void {
eventWithGroupName = `Group: ${eventWithGroupName}`;
}
if (event.parent_group) {
const parentGroup = events.find(value => {return value.id === event.parent_group});
const parentGroup = sortedEvents.find(value => {return value.id === event.parent_group});
if (parentGroup) {
eventWithGroupName += ` (${parentGroup.name})`;
}
Expand All @@ -170,7 +169,7 @@ function drawAccess(): void {

// groups can't have parent groups
parentGroupInput.disabled = event.is_group??false;
const currentParent = events.find(value => {return value.id === event.parent_group});
const currentParent = sortedEvents.find(value => {return value.id === event.parent_group});
parentGroupInput.value = currentParent?.name??"";

editEventModal?.show();
Expand Down Expand Up @@ -290,7 +289,17 @@ function updateEventAccess(event: string, mode: AccessMode): void {
if (explainMsgs.length === 0) {
explainMsgs.push("No permissions");
}
modal.querySelector(".modal-body")!.textContent = explainMsgs.join("\n");
const modalBody = modal.querySelector(".modal-body")!;
modalBody.textContent = explainMsgs.join("\n");
const eventData = sortedEvents.find(value => {return value.name === event});
if (eventData && eventData.is_group) {
modalBody.textContent += "\n\nThis is an event group, so all permissions above also apply to its child events:\n";
for (const event of sortedEvents) {
if (event.parent_group === eventData.id) {
modalBody.textContent += `${indent}${event.name}\n`;
}
}
}
explainModal?.show();
})
}
Expand Down Expand Up @@ -540,7 +549,7 @@ async function setParentGroup(sender: HTMLInputElement): Promise<void> {
// unset parent_group
requestBod.parent_group = 0;
} else {
const newParent = events.find(value => {return value.name === parentGroupName});
const newParent = sortedEvents.find(value => {return value.name === parentGroupName});
if (!newParent) {
const message = `No group by that name`;
console.log(message);
Expand Down
Loading