Skip to content

Commit

Permalink
BC-4782 Remove usage of years endpoint (#3288)
Browse files Browse the repository at this point in the history
* Adjust currentYear stuff

* Remove unused modal
  • Loading branch information
dyedwiper authored Sep 1, 2023
1 parent b2833e4 commit b81679e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 65 deletions.
21 changes: 8 additions & 13 deletions controllers/administration.js
Original file line number Diff line number Diff line change
Expand Up @@ -1737,17 +1737,15 @@ router.get(
$sort: 'lastName',
$limit: false,
});
const yearsPromise = getSelectOptions(req, 'years', { $limit: false });

const usersWithConsentsPromise = getUsersWithoutConsent(req, 'student', currentClass._id);

Promise.all([
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',
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -2123,7 +2118,7 @@ router.get(
break;
case 'current':
default:
query['year[$in]'] = [currentYear];
query['year[$in]'] = [currentYear._id];
break;
}

Expand All @@ -2138,7 +2133,7 @@ router.get(
},
{
key: 'current',
title: `${currentYearObj.name}`,
title: `${currentYear.name}`,
link: `/administration/classes/?showTab=current${filterQueryString}`,
}, {
key: 'archive',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
}),
Expand Down
1 change: 0 additions & 1 deletion static/scripts/administration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
23 changes: 0 additions & 23 deletions static/scripts/administration/classes/manage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import printQRs from '../../helpers/printQRs';

/* globals populateModalForm */

window.addEventListener('load', () => {
document
.getElementById('filter_schoolyear')
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 0 additions & 28 deletions views/administration/forms/form-classes-manage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,4 @@
</div>
</div>

{{#embed "lib/components/modal-form" class="import-modal"}}
{{#content "fields"}}

<div class="form-group">
<label for="filter_schoolyear">{{$t "administration.classes.label.filterBySchoolYear" }}</label>
<select id="filter_schoolyear" name="classes" data-placeholder="{{$t "administration.classes.label.filterBySchoolYear" }}">
<option value="" selected>{{$t "administration.classes.label.all" }}</option>
{{#each schoolyears}}
<option value="{{this._id}}">
{{this.name}}
</option>
{{/each}}
</select>
<p>{{$t "administration.classes.text.attentionIfYouChangeTheSchoolYear" }}</p>
</div>
<div class="form-group">
<label for="student_from_class_import">{{$t "administration.classes.label.addStudentFromPreviousYearClass" }}</label>
<select id="student_from_class_import" name="classes" multiple data-placeholder="{{$t "administration.global.placeholder.selectOldClasses" }}">
{{#each classes}}
<option value="{{this._id}}" {{#if this.selected}}selected{{/if}}>
{{this.displayName}}
</option>
{{/each}}
</select>
</div>
{{/content}}
{{/embed}}

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

0 comments on commit b81679e

Please sign in to comment.