@@ -93,7 +93,7 @@ type EventAccess = Partial<Record<AccessMode, Access[]>>;
9393// key is event name
9494type EventsAccess = Record < string , EventAccess | null > ;
9595
96- let events : ims . EventData [ ] ;
96+ let sortedEvents : ims . EventData [ ] ;
9797let accessControlList : EventsAccess | null = null ;
9898
9999async function loadAccessControlList ( ) : Promise < { err : string | null } > {
@@ -106,7 +106,7 @@ async function loadAccessControlList() : Promise<{err: string|null}> {
106106 window . alert ( message ) ;
107107 return { err : message } ;
108108 }
109- events = eventsJson ?? [ ] ;
109+ const events = eventsJson ?? [ ] ;
110110 const { json, err} = await ims . fetchNoThrow < EventsAccess > ( url_acl , null ) ;
111111 if ( err != null ) {
112112 const message = `Failed to load access control list: ${ err } ` ;
@@ -115,6 +115,18 @@ async function loadAccessControlList() : Promise<{err: string|null}> {
115115 return { err : message } ;
116116 }
117117 accessControlList = json ;
118+ // Sort by group status first, then by name
119+ sortedEvents = events . toSorted ( ( a : ims . EventData , b : ims . EventData ) : number => {
120+ const aGroup = a . is_group ? a . id : ( a . parent_group ?? - 1 ) ;
121+ const bGroup = b . is_group ? b . id : ( b . parent_group ?? - 1 ) ;
122+ if ( aGroup !== bGroup ) {
123+ return bGroup - aGroup ;
124+ }
125+ if ( a . is_group !== b . is_group ) {
126+ return a . is_group ? - 1 : 1 ;
127+ }
128+ return b . name . localeCompare ( a . name ) ;
129+ } ) ;
118130 return { err : null } ;
119131}
120132
@@ -128,19 +140,6 @@ function drawAccess(): void {
128140 const accessTemplate = document . getElementById ( "event_access_template" ) as HTMLTemplateElement ;
129141 const accessModeTemplate = document . getElementById ( "event_access_mode_template" ) as HTMLTemplateElement ;
130142
131- // Sort by group status first, then by name
132- const sortedEvents : ims . EventData [ ] = events . toSorted ( ( a : ims . EventData , b : ims . EventData ) : number => {
133- const aGroup = a . is_group ? a . id : ( a . parent_group ?? - 1 ) ;
134- const bGroup = b . is_group ? b . id : ( b . parent_group ?? - 1 ) ;
135- if ( aGroup !== bGroup ) {
136- return bGroup - aGroup ;
137- }
138- if ( a . is_group !== b . is_group ) {
139- return a . is_group ? - 1 : 1 ;
140- }
141- return b . name . localeCompare ( a . name ) ;
142- } ) ;
143-
144143 for ( const event of sortedEvents ) {
145144 const eventAccessFrag = accessTemplate . content . cloneNode ( true ) as DocumentFragment ;
146145
@@ -149,7 +148,7 @@ function drawAccess(): void {
149148 eventWithGroupName = `Group: ${ eventWithGroupName } ` ;
150149 }
151150 if ( event . parent_group ) {
152- const parentGroup = events . find ( value => { return value . id === event . parent_group } ) ;
151+ const parentGroup = sortedEvents . find ( value => { return value . id === event . parent_group } ) ;
153152 if ( parentGroup ) {
154153 eventWithGroupName += ` (${ parentGroup . name } )` ;
155154 }
@@ -170,7 +169,7 @@ function drawAccess(): void {
170169
171170 // groups can't have parent groups
172171 parentGroupInput . disabled = event . is_group ?? false ;
173- const currentParent = events . find ( value => { return value . id === event . parent_group } ) ;
172+ const currentParent = sortedEvents . find ( value => { return value . id === event . parent_group } ) ;
174173 parentGroupInput . value = currentParent ?. name ?? "" ;
175174
176175 editEventModal ?. show ( ) ;
@@ -290,7 +289,17 @@ function updateEventAccess(event: string, mode: AccessMode): void {
290289 if ( explainMsgs . length === 0 ) {
291290 explainMsgs . push ( "No permissions" ) ;
292291 }
293- modal . querySelector ( ".modal-body" ) ! . textContent = explainMsgs . join ( "\n" ) ;
292+ const modalBody = modal . querySelector ( ".modal-body" ) ! ;
293+ modalBody . textContent = explainMsgs . join ( "\n" ) ;
294+ const eventData = sortedEvents . find ( value => { return value . name === event } ) ;
295+ if ( eventData && eventData . is_group ) {
296+ modalBody . textContent += "\n\nThis is an event group, so all permissions above also apply to its child events:\n" ;
297+ for ( const event of sortedEvents ) {
298+ if ( event . parent_group === eventData . id ) {
299+ modalBody . textContent += `${ indent } ${ event . name } \n` ;
300+ }
301+ }
302+ }
294303 explainModal ?. show ( ) ;
295304 } )
296305}
@@ -540,7 +549,7 @@ async function setParentGroup(sender: HTMLInputElement): Promise<void> {
540549 // unset parent_group
541550 requestBod . parent_group = 0 ;
542551 } else {
543- const newParent = events . find ( value => { return value . name === parentGroupName } ) ;
552+ const newParent = sortedEvents . find ( value => { return value . name === parentGroupName } ) ;
544553 if ( ! newParent ) {
545554 const message = `No group by that name` ;
546555 console . log ( message ) ;
0 commit comments