@@ -67,6 +67,7 @@ if (!schoolName && !accessToken) {
6767 document
6868 . querySelector ( "#dialog #closeBtn" )
6969 . setAttribute ( "onclick" , "resetAfterWelcomeScreen()" ) ;
70+ document . querySelector ( "#dialog" ) . setAttribute ( "closedby" , "none" ) ;
7071 document . querySelector ( "#dialog #closeBtn" ) . removeAttribute ( "command" ) ;
7172 document . querySelector ( "#dialog #closeBtn" ) . removeAttribute ( "commandfor" ) ;
7273 document . querySelector ( "#dialog #closeBtn span" ) . innerHTML = "Volgende" ;
@@ -126,7 +127,7 @@ announcements();
126127
127128async function userInfo ( ) {
128129 const response = await fetch (
129- `https://${ schoolName } .zportal.nl/api/users/~me?fields=code,isEmployee` ,
130+ `https://${ schoolName } .zportal.nl/api/users/~me?fields=code,isEmployee,schoolInSchoolYears ` ,
130131 {
131132 headers : {
132133 Authorization : `Bearer ${ accessToken } ` ,
@@ -139,11 +140,70 @@ async function userInfo() {
139140 userType1 = "teacher" ;
140141 } else if ( ! data . response . data [ 0 ] ) {
141142 console . error ( data ) ;
143+ } else {
144+ schoolInSchoolYears ( data . response . data [ 0 ] . schoolInSchoolYears ) ;
142145 }
143146 localStorage . setItem ( "userType" , userType1 ) ;
144147 userType = localStorage . getItem ( "userType" ) ;
145148 fetchSchedule ( ) ;
146149}
150+ async function schoolInSchoolYears ( years ) {
151+ const response = await fetch (
152+ `https://${ schoolName } .zportal.nl/api/schoolsinschoolyears?fields=id,year` ,
153+ {
154+ headers : {
155+ Authorization : `Bearer ${ accessToken } ` ,
156+ } ,
157+ }
158+ ) ;
159+ const data = await response . json ( ) ;
160+ const schoolYears = data . response . data ;
161+ const current = schoolYears . reduce (
162+ ( latest , item ) =>
163+ years . includes ( item . id ) && ( ! latest || item . year > latest . year )
164+ ? item
165+ : latest ,
166+ null
167+ ) ;
168+ localStorage . setItem ( "schoolInSchoolYear" , current . id ) ;
169+ fetchTeachers ( ) ;
170+ }
171+ async function fetchTeachers ( ) {
172+ const schoolYear = Number ( localStorage . getItem ( "schoolInSchoolYear" ) ) ;
173+ let teacherTranslations = { } ;
174+ return fetch (
175+ `https://${ schoolName } .zportal.nl/api/users?archived=false&schoolInSchoolYear=${ schoolYear } &fields=code%2ClastName%2Cprefix&isEmployee=true` ,
176+ {
177+ headers : {
178+ Authorization : `Bearer ${ accessToken } ` ,
179+ } ,
180+ }
181+ )
182+ . then ( ( r ) => r . json ( ) )
183+ . then ( ( result ) => {
184+ let teachers = result . response . data ;
185+ teachers . forEach ( ( teacher ) => {
186+ let prefix = teacher . prefix ;
187+ let lastName = teacher . lastName ;
188+ // For my school the format {2 letters last name}{2 letters first name} is used which can be used to find the initial letter of the first name, possibly other schools??
189+ if ( schoolName == "csvincentvangogh" && teacher . code . length == 4 )
190+ prefix = `${ teacher . code . split ( "" ) [ 2 ] . toUpperCase ( ) } .${ prefix ? " " + prefix : "" } ` ;
191+
192+ if ( ! lastName ) {
193+ return ;
194+ }
195+
196+ let commaIndex = lastName . indexOf ( "," ) ;
197+ if ( commaIndex != - 1 ) {
198+ lastName = lastName . substring ( 0 , commaIndex ) ;
199+ }
200+
201+ let fullName = ( prefix ? prefix + " " : "" ) + lastName ;
202+ teacherTranslations [ teacher . code ] = fullName ;
203+ } ) ;
204+ localStorage . setItem ( "teachers" , JSON . stringify ( teacherTranslations ) ) ;
205+ } ) ;
206+ }
147207const inputs = document . querySelectorAll ( "input" ) ;
148208inputs . forEach ( ( input ) => {
149209 if ( localStorage . getItem ( input . id ) ) {
@@ -294,6 +354,7 @@ function show(id, title, hideBack) {
294354 } else {
295355 document . querySelector ( "#dialog h2" ) . innerHTML = title ;
296356 if ( ! hideBack ) {
357+ document . querySelector ( "#dialog" ) . setAttribute ( "closedby" , "any" ) ;
297358 document . querySelector ( "#dialog #closeBtn span" ) . innerHTML = "Sluiten" ;
298359 document
299360 . querySelector ( "#dialog #closeBtn" )
@@ -432,7 +493,7 @@ async function fetchSchedule(year, week, isFirstLoad) {
432493 return ;
433494 }
434495 const response = await fetch (
435- `https://${ schoolName } .zportal.nl/api/liveschedule?${ userType } =~me&week=${ year } ${ week } &fields` ,
496+ `https://${ schoolName } .zportal.nl/api/liveschedule?${ userType } =~me&week=${ year } ${ week } &fields=week,user,appointments,replacements,status ` ,
436497 {
437498 headers : {
438499 Authorization : `Bearer ${ accessToken } ` ,
@@ -756,9 +817,7 @@ async function fetchSchedule(year, week, isFirstLoad) {
756817 } ) ;
757818}
758819async function fetchFullSubjectNames ( ) {
759- let url = `https://${ localStorage . getItem (
760- "schoolName"
761- ) } .zportal.nl/api/subjectselectionsubjects?fields=code,name`;
820+ let url = `https://${ schoolName } .zportal.nl/api/subjectselectionsubjects?fields=code,name` ;
762821 return fetch ( url , {
763822 headers : {
764823 Authorization : `Bearer ${ localStorage . getItem ( "access_token" ) } ` ,
@@ -1083,14 +1142,26 @@ async function showLessonInfo(lessonHTML, lesson) {
10831142 : "" ;
10841143 const calendarClockIcon = `<svg xmlns="http://www.w3.org/2000/svg" height="1.25rem" viewBox="0 -960 960 960" width="1.25rem" fill="var(--accent-text)" style="vertical-align: sub; translate: 0 -1px;"><path d="M200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-40q0-17 11.5-28.5T280-880q17 0 28.5 11.5T320-840v40h320v-40q0-17 11.5-28.5T680-880q17 0 28.5 11.5T720-840v40h40q33 0 56.5 23.5T840-720v187q0 17-11.5 28.5T800-493q-17 0-28.5-11.5T760-533v-27H200v400h232q17 0 28.5 11.5T472-120q0 17-11.5 28.5T432-80H200Zm520 40q-83 0-141.5-58.5T520-240q0-83 58.5-141.5T720-440q83 0 141.5 58.5T920-240q0 83-58.5 141.5T720-40Zm20-208v-92q0-8-6-14t-14-6q-8 0-14 6t-6 14v91q0 8 3 15.5t9 13.5l61 61q6 6 14 6t14-6q6-6 6-14t-6-14l-61-61Z"/></svg>` ;
10851144 const updateIcon = `<svg xmlns="http://www.w3.org/2000/svg" height="1.25rem" viewBox="0 -960 960 960" width="1.25rem" fill="var(--accent-text)" style="vertical-align: sub;"><path d="M480-120q-75 0-140.5-28.5t-114-77q-48.5-48.5-77-114T120-480q0-75 28.5-140.5t77-114q48.5-48.5 114-77T480-840q82 0 155.5 35T760-706v-54q0-17 11.5-28.5T800-800q17 0 28.5 11.5T840-760v160q0 17-11.5 28.5T800-560H640q-17 0-28.5-11.5T600-600q0-17 11.5-28.5T640-640h70q-41-56-101-88t-129-32q-117 0-198.5 81.5T200-480q0 117 81.5 198.5T480-200q95 0 170-57t99-147q5-16 18-24t29-6q17 2 27 14.5t6 27.5q-29 119-126 195.5T480-120Zm40-376 100 100q11 11 11 28t-11 28q-11 11-28 11t-28-11L452-452q-6-6-9-13.5t-3-15.5v-159q0-17 11.5-28.5T480-680q17 0 28.5 11.5T520-640v144Z"/></svg>` ;
1145+ const teacherIcon = `<svg xmlns="http://www.w3.org/2000/svg" height="1.25rem" viewBox="0 -960 960 960" width="1.25rem" fill="var(--accent-text)" style="vertical-align: sub;"><path d="M609-389q-29-29-29-71t29-71q29-29 71-29t71 29q29 29 29 71t-29 71q-29 29-71 29t-71-29Zm-89 229q-17 0-28.5-11.5T480-200v-16q0-24 12.5-44.5T528-290q36-15 74.5-22.5T680-320q39 0 77.5 7.5T832-290q23 9 35.5 29.5T880-216v16q0 17-11.5 28.5T840-160H520ZM287-527q-47-47-47-113t47-113q47-47 113-47t113 47q47 47 47 113t-47 113q-47 47-113 47t-113-47ZM80-272q0-34 17-62.5t47-43.5q60-30 124.5-46T400-440q35 0 70 6t70 14l-68 68q-25 25-48.5 51T400-240v39q0 12 4.5 22.5T419-160H160q-33 0-56.5-23.5T80-240v-32Z"/></svg>` ;
1146+ let fullTeacherNames = JSON . parse ( localStorage . getItem ( "teachers" ) ) ;
1147+ if ( JSON . parse ( localStorage . getItem ( "teachers" ) ) ) {
1148+ fullTeacherNames = lesson . teachers . map (
1149+ ( teacher ) => `${ fullTeacherNames [ teacher ] } (${ teacher } )`
1150+ ) ;
1151+ } else if ( userType == "student" ) {
1152+ userInfo ( ) ;
1153+ }
1154+ const teacherDiv = fullTeacherNames
1155+ ? `<div><span class="pill">${ teacherIcon } ${ fullTeacherNames . join ( ", " ) } </span></div>`
1156+ : "" ;
10861157 document . querySelector ( "#info #content" ) . innerHTML +=
1087- `${ warningSymbol } <div class="moreInfo"><span class="pill">${ groupIcon } ${ lesson . expectedStudentCount } <span style="translate: 0 1.5px">${ lesson . groups . join ( ", " ) } </span></span>${ onlinePill } </div>` ;
1158+ `${ warningSymbol } ${ teacherDiv } <div class="moreInfo"><span class="pill">${ groupIcon } ${ lesson . expectedStudentCount } <span style="translate: 0 1.5px">${ lesson . groups . join ( ", " ) } </span></span>${ onlinePill } </div>` ;
10881159 const url = `https://${ schoolName } .zportal.nl/api/appointments?appointmentInstance=${
10891160 lesson . appointmentInstance
10901161 } &user=~me&valid=true&start=${ lesson . start } &end=${
10911162 lesson . end
10921163 } &fields=created,modified,lastModified${
1093- localStorage . getItem ( " userType" ) == "teacher" ? `,students` : ""
1164+ userType == "teacher" ? `,students` : ""
10941165 } `;
10951166 const response = await fetch ( url , {
10961167 headers : {
0 commit comments