mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-08 22:42:54 +00:00
fix: catalog semester selection
This commit is contained in:
committed by
Thea Schöbl
parent
260fbe01db
commit
b2a8cba1aa
@@ -111,17 +111,22 @@ export class CatalogComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
async fetchSemesters(): Promise<void> {
|
||||
const today = moment().startOf('day').toISOString();
|
||||
const semesters = await this.catalogProvider.getRelevantSemesters();
|
||||
this.availableSemesters = semesters.slice(0, 3).reverse();
|
||||
const currentSemester = semesters.find(
|
||||
semester => semester.startDate <= today && semester.endDate > today,
|
||||
);
|
||||
const currentSemesterIndex = semesters.findIndex(semester => semester.uid === currentSemester?.uid);
|
||||
this.availableSemesters = semesters.slice(currentSemesterIndex - 1, currentSemesterIndex + 2).reverse();
|
||||
|
||||
if (typeof this.activeSemester !== 'undefined') {
|
||||
return;
|
||||
}
|
||||
const today = moment().startOf('day').toISOString();
|
||||
|
||||
this.activeSemester = this.availableSemesters[0];
|
||||
this.activeSemester =
|
||||
this.selectedSemesterUID === ''
|
||||
? this.availableSemesters.find(semester => semester.startDate <= today && semester.endDate > today)
|
||||
? currentSemester
|
||||
: this.availableSemesters.find(semester => semester.uid === this.selectedSemesterUID);
|
||||
if (this.activeSemester && this.selectedSemesterUID === '') {
|
||||
this.selectedSemesterUID = this.activeSemester.uid;
|
||||
|
||||
@@ -107,14 +107,46 @@ export class CatalogProvider {
|
||||
const response = await this.dataProvider.search({
|
||||
filter: {
|
||||
arguments: {
|
||||
field: 'type',
|
||||
value: SCThingType.Semester,
|
||||
operation: 'and',
|
||||
filters: [
|
||||
{
|
||||
type: 'value',
|
||||
arguments: {
|
||||
field: 'type',
|
||||
value: SCThingType.Semester,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'date range',
|
||||
arguments: {
|
||||
bounds: {
|
||||
lowerBound: {
|
||||
limit: `${new Date().setFullYear(new Date().getFullYear() - 1)}`,
|
||||
mode: 'inclusive',
|
||||
},
|
||||
upperBound: {
|
||||
limit: `${new Date().setFullYear(new Date().getFullYear() + 1)}`,
|
||||
mode: 'inclusive',
|
||||
},
|
||||
},
|
||||
field: 'startDate',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: 'value',
|
||||
type: 'boolean',
|
||||
},
|
||||
size: 10,
|
||||
sort: [
|
||||
{
|
||||
arguments: {
|
||||
field: 'startDate',
|
||||
},
|
||||
order: 'desc',
|
||||
type: 'generic',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return (response.data as SCSemester[]).sort((a, b) => b.startDate.localeCompare(a.startDate, 'en'));
|
||||
return response.data as SCSemester[];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user