From b81679e74aae09367c2773e6c48b68fd763645c7 Mon Sep 17 00:00:00 2001 From: Max <53796487+dyedwiper@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:06:47 +0200 Subject: [PATCH] BC-4782 Remove usage of years endpoint (#3288) * Adjust currentYear stuff * Remove unused modal --- controllers/administration.js | 21 ++++++-------- static/scripts/administration.js | 1 - .../scripts/administration/classes/manage.js | 23 --------------- .../forms/form-classes-manage.hbs | 28 ------------------- 4 files changed, 8 insertions(+), 65 deletions(-) diff --git a/controllers/administration.js b/controllers/administration.js index fe87363c08..828fffce9f 100644 --- a/controllers/administration.js +++ b/controllers/administration.js @@ -1737,7 +1737,6 @@ router.get( $sort: 'lastName', $limit: false, }); - const yearsPromise = getSelectOptions(req, 'years', { $limit: false }); const usersWithConsentsPromise = getUsersWithoutConsent(req, 'student', currentClass._id); @@ -1745,9 +1744,8 @@ router.get( classesPromise, teachersPromise, studentsPromise, - yearsPromise, usersWithConsentsPromise, - ]).then(([classes, teachers, students, schoolyears, allUsersWithoutConsent]) => { + ]).then(([classes, teachers, students, allUsersWithoutConsent]) => { const isAdmin = res.locals.currentUser.permissions.includes( 'ADMIN_VIEW', ); @@ -1849,7 +1847,6 @@ router.get( teachers, students: filterStudents(res, students), schoolUsesLdap: res.locals.currentSchoolData.ldapSchoolIdentifier, - schoolyears, notes, referrer: '/administration/classes/', consentsMissing: usersWithoutConsent.length !== 0, @@ -2101,16 +2098,14 @@ router.get( const schoolYears = res.locals.currentSchoolData.years.schoolYears .sort((a, b) => b.startDate.localeCompare(a.startDate)); const lastDefinedSchoolYear = (schoolYears[0] || {})._id; - const currentYear = res.locals.currentSchoolData.currentYear; - - const currentYearObj = schoolYears.filter((year) => year._id === currentYear).pop(); const showTab = (req.query || {}).showTab || 'current'; + const currentYear = res.locals.currentSchoolData.currentYear; const upcomingYears = schoolYears - .filter((year) => year.startDate > currentYearObj.endDate); + .filter((year) => year.startDate > currentYear.endDate); const archivedYears = schoolYears - .filter((year) => year.endDate < currentYearObj.startDate); + .filter((year) => year.endDate < currentYear.startDate); let defaultYear; switch (showTab) { @@ -2123,7 +2118,7 @@ router.get( break; case 'current': default: - query['year[$in]'] = [currentYear]; + query['year[$in]'] = [currentYear._id]; break; } @@ -2138,7 +2133,7 @@ router.get( }, { key: 'current', - title: `${currentYearObj.name}`, + title: `${currentYear.name}`, link: `/administration/classes/?showTab=current${filterQueryString}`, }, { key: 'archive', @@ -2217,7 +2212,7 @@ router.get( }; const years = schoolYears - .filter((year) => year.endDate < currentYearObj.startDate) + .filter((year) => year.endDate < currentYear.startDate) .map((year) => [ year._id, year.name, @@ -2814,7 +2809,7 @@ router.use( const [school, totalStorage, schoolMaintanance, consentVersions] = await Promise.all([ api(req).get(`/schools/${res.locals.currentSchool}`, { qs: { - $populate: ['systems', 'currentYear', 'federalState'], + $populate: ['systems', 'federalState'], $sort: req.query.sort, }, }), diff --git a/static/scripts/administration.js b/static/scripts/administration.js index 9ef5aa5745..4b900105a7 100644 --- a/static/scripts/administration.js +++ b/static/scripts/administration.js @@ -52,7 +52,6 @@ $(document).ready(() => { const $addPolicyModal = $('.add-modal--policy'); const $editModal = $('.edit-modal'); const $invitationModal = $('.invitation-modal'); - const $importModal = $('.import-modal'); const $deleteSystemsModal = $('.delete-modal'); const $deleteRSSModal = $('.delete-modal--rss'); diff --git a/static/scripts/administration/classes/manage.js b/static/scripts/administration/classes/manage.js index 6eb2de6d7f..a0e0a50ceb 100644 --- a/static/scripts/administration/classes/manage.js +++ b/static/scripts/administration/classes/manage.js @@ -1,7 +1,5 @@ import printQRs from '../../helpers/printQRs'; -/* globals populateModalForm */ - window.addEventListener('load', () => { document .getElementById('filter_schoolyear') @@ -31,27 +29,6 @@ window.addEventListener('load', () => { } }); - const $importModal = $('.import-modal'); - - $importModal.find('.btn-submit').on('click', async (event) => { - event.preventDefault(); - const selections = $('#student_from_class_import') - .val(); - const requestUrl = `/administration/classes/students?classes=${encodeURI( - JSON.stringify(selections), - )}`; - $importModal.modal('hide'); - const res = await fetch(requestUrl, { - credentials: 'same-origin', - }); - const students = await res.json(); - students.forEach((student) => { - document.querySelector( - `option[value="${student._id}"]`, - ).selected = true; - }); - }); - function btnSendLinksEmailsHandler(e) { e.preventDefault(); const $this = $(this); diff --git a/views/administration/forms/form-classes-manage.hbs b/views/administration/forms/form-classes-manage.hbs index d6099b558e..0b981b3a59 100644 --- a/views/administration/forms/form-classes-manage.hbs +++ b/views/administration/forms/form-classes-manage.hbs @@ -126,32 +126,4 @@ -{{#embed "lib/components/modal-form" class="import-modal"}} - {{#content "fields"}} - -
- - -

{{$t "administration.classes.text.attentionIfYouChangeTheSchoolYear" }}

-
-
- - -
- {{/content}} -{{/embed}} - {{#embed "lib/components/modal-cancel" class="cancel-modal"}}{{/embed}}