From 9ff315e42708348f4c53f58a77b5c7a8ff51f564 Mon Sep 17 00:00:00 2001 From: Hangzhi Yu <hangzhi@protonmail.com> Date: Sat, 17 Feb 2024 16:32:02 +0100 Subject: [PATCH] Introduce new URL scheme with my/all filtering --- .../frontend/components/Coursebook.vue | 23 +++++++++++++++---- .../frontend/components/coursebook.graphql | 6 +++-- aleksis/apps/alsijil/frontend/index.js | 14 +++++------ .../apps/alsijil/frontend/messages/de.json | 3 +++ .../apps/alsijil/frontend/messages/en.json | 3 +++ aleksis/apps/alsijil/models.py | 21 +++++++++++------ aleksis/apps/alsijil/schema/__init__.py | 9 ++++---- 7 files changed, 53 insertions(+), 26 deletions(-) diff --git a/aleksis/apps/alsijil/frontend/components/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/Coursebook.vue index 422a9c1be..2a2988867 100644 --- a/aleksis/apps/alsijil/frontend/components/Coursebook.vue +++ b/aleksis/apps/alsijil/frontend/components/Coursebook.vue @@ -19,6 +19,13 @@ hide-details :loading="selectLoading" @input="changeSelection" + @click:clear="changeSelection" + /> + <v-switch + :loading="selectLoading" + :label="$t('alsijil.coursebook.filter.own')" + :input-value="filterType === 'my'" + @change="changeSelection({ filterType: $event ? 'my' : 'all', type: objType, id: objId })" /> </template> <template #default="{ items }"> @@ -98,15 +105,19 @@ export default { props: { // Either as props OR route params // TODO: Remove default? + filterType: { + type: String, + required: true, + }, objId: { type: [Number, String], required: false, - default: 0, + default: null, }, objType: { type: String, required: false, - default: "group", + default: null, }, // Next two in ISODate dateStart: { @@ -141,8 +152,9 @@ export default { gqlQueryArgs() { return { // Assure courseId is a number - objId: Number(this.objId), - objType: this.objType.toUpperCase(), + own: this.filterType === "all" ? false : true, + objId: this.objId ? Number(this.objId) : null, + objType: this.objType?.toUpperCase(), dateStart: this.dateStart, dateEnd: this.dateEnd, }; @@ -163,8 +175,9 @@ export default { methods: { changeSelection(selection) { this.$router.push({ - name: "alsijil.coursebook_by_obj_id_and_date", + name: "alsijil.coursebook_by_type_and_date", params: { + filterType: selection.filterType ? selection.filterType : this.filterType, objType: selection.type, objId: selection.id, dateStart: this.dateStart, diff --git a/aleksis/apps/alsijil/frontend/components/coursebook.graphql b/aleksis/apps/alsijil/frontend/components/coursebook.graphql index ab7a3a901..a8067e79a 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook.graphql +++ b/aleksis/apps/alsijil/frontend/components/coursebook.graphql @@ -17,12 +17,14 @@ query coursesOfTeacher { } query documentationsForCoursebook( - $objId: ID! - $objType: String! + $own: Boolean! + $objId: ID + $objType: String $dateStart: Date! $dateEnd: Date! ) { items: documentationsForCoursebook( + own: $own objId: $objId objType: $objType dateStart: $dateStart diff --git a/aleksis/apps/alsijil/frontend/index.js b/aleksis/apps/alsijil/frontend/index.js index 60d897e95..eb09dd25f 100644 --- a/aleksis/apps/alsijil/frontend/index.js +++ b/aleksis/apps/alsijil/frontend/index.js @@ -387,21 +387,19 @@ export default { }, }, { - path: "coursebook/:objType(group|course|teacher)/:objId(\\d+)/", + path: "coursebook/", component: () => import("./components/Coursebook.vue"), redirect: (to) => { - console.log("redirect to", to); return { - name: "alsijil.coursebook_by_obj_id_and_date", + name: "alsijil.coursebook_by_type_and_date", params: { - objType: to.params.objType, - objId: to.params.objId, dateStart: DateTime.now().toISODate(), dateEnd: DateTime.now().plus({ weeks: 1 }).toISODate(), + filterType: "my", }, }; }, - name: "alsijil.coursebook_by_obj_id", + name: "alsijil.coursebook", props: true, meta: { inMenu: true, @@ -413,9 +411,9 @@ export default { }, children: [ { - path: ":dateStart(\\d\\d\\d\\d-\\d\\d-\\d\\d)/:dateEnd(\\d\\d\\d\\d-\\d\\d-\\d\\d)/", + path: ":dateStart(\\d\\d\\d\\d-\\d\\d-\\d\\d)/:dateEnd(\\d\\d\\d\\d-\\d\\d-\\d\\d)/:filterType(my|all)/:objType(group|course|teacher)?/:objId(\\d+)?/", component: () => import("./components/Coursebook.vue"), - name: "alsijil.coursebook_by_obj_id_and_date", + name: "alsijil.coursebook_by_type_and_date", meta: { titleKey: "alsijil.coursebook.menu_title", toolbarTitle: "alsijil.coursebook.menu_title", diff --git a/aleksis/apps/alsijil/frontend/messages/de.json b/aleksis/apps/alsijil/frontend/messages/de.json index 0d6f76832..a9dbb6b40 100644 --- a/aleksis/apps/alsijil/frontend/messages/de.json +++ b/aleksis/apps/alsijil/frontend/messages/de.json @@ -47,6 +47,9 @@ "value": "Gruppennotiz: {groupNote}", "empty": "Keine Gruppennotiz" } + }, + "filter": { + "own": "Nur eigene Stunden anzeigen" } } } diff --git a/aleksis/apps/alsijil/frontend/messages/en.json b/aleksis/apps/alsijil/frontend/messages/en.json index 2537974f9..b009570d7 100644 --- a/aleksis/apps/alsijil/frontend/messages/en.json +++ b/aleksis/apps/alsijil/frontend/messages/en.json @@ -47,6 +47,9 @@ "value": "Group note: {groupNote}", "empty": "No group note" } + }, + "filter": { + "own": "Only show own lessons" } } } diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index 8e80f165a..803efbfb8 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -518,11 +518,12 @@ class Documentation(CalendarEvent): @classmethod def get_for_coursebook( cls, - obj_type: str, - obj_id: str, + own: bool, date_start: datetime, date_end: datetime, request: HttpRequest, + obj_type: Optional[str], + obj_id: Optional[str], ) -> list: """Get all the documentations for an object and a time frame. @@ -530,15 +531,21 @@ class Documentation(CalendarEvent): """ # 1. Find all LessonEvents for all Lessons of this Course in this date range + event_params = { + "own": own, + "not_amended": True, + } + if obj_type is not None and obj_id is not None: + event_params.update({ + "type": obj_type, + "id": obj_id, + }) + events = LessonEvent.get_single_events( date_start, date_end, request, - { - "type": obj_type, - "id": obj_id, - "not_amended": True, - }, + event_params, with_reference_object=True, ) # (1.5 filter them by permissions) diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py index b74c77e13..1cfc2ca65 100644 --- a/aleksis/apps/alsijil/schema/__init__.py +++ b/aleksis/apps/alsijil/schema/__init__.py @@ -26,8 +26,9 @@ class Query(graphene.ObjectType): ) documentations_for_coursebook = FilterOrderList( DocumentationType, - obj_type=graphene.String(required=True), - obj_id=graphene.ID(required=True), + own=graphene.Boolean(required=True), + obj_type=graphene.String(required=False), + obj_id=graphene.ID(required=False), date_start=graphene.Date(required=True), date_end=graphene.Date(required=True), ) @@ -39,7 +40,7 @@ class Query(graphene.ObjectType): return documentations def resolve_documentations_for_coursebook( - root, info, obj_type, obj_id, date_start, date_end, **kwargs + root, info, own, date_start, date_end, obj_type=None, obj_id=None, **kwargs ): datetime_start = datetime.combine(date_start, datetime.min.time()) datetime_end = datetime.combine(date_end, datetime.max.time()) @@ -67,7 +68,7 @@ class Query(graphene.ObjectType): raise PermissionDenied() return Documentation.get_for_coursebook( - obj_type, obj_id, datetime_start, datetime_end, info.context + own, datetime_start, datetime_end, info.context, obj_type, obj_id ) -- GitLab