From e62af26e4e909703fd8146f497e2aa6c788e7034 Mon Sep 17 00:00:00 2001 From: Julian Leucker <leuckerj@gmail.com> Date: Mon, 18 Jul 2022 13:09:01 +0200 Subject: [PATCH] Query lesson documentations via graphql --- .../alsijil/class_register/coursebook.html | 2 +- .../js/vue/components/alsijil/CourseBook.js | 746 +++--------------- 2 files changed, 105 insertions(+), 643 deletions(-) diff --git a/aleksis/apps/alsijil/templates/alsijil/class_register/coursebook.html b/aleksis/apps/alsijil/templates/alsijil/class_register/coursebook.html index 15b58b05b..1c5acfcf6 100644 --- a/aleksis/apps/alsijil/templates/alsijil/class_register/coursebook.html +++ b/aleksis/apps/alsijil/templates/alsijil/class_register/coursebook.html @@ -9,7 +9,7 @@ {% endblock %} {% block browser_title %}{% trans "Coursebook" %} {{ lesson }}{% endblock %} {% block content %} -<course-book></course-book> +<course-book lesson-id="{{ lesson.id }}"></course-book> {% endblock %} {% block extra_body %} diff --git a/assets/js/vue/components/alsijil/CourseBook.js b/assets/js/vue/components/alsijil/CourseBook.js index 96bd7dd75..18770f536 100644 --- a/assets/js/vue/components/alsijil/CourseBook.js +++ b/assets/js/vue/components/alsijil/CourseBook.js @@ -23,653 +23,115 @@ export default { }, 500) } }, - props: [], + props: ["lessonId"], name: "course-book", data: () => { return { + ping: "ping", status: SAVED, - "excuseTypes": [ - { - "name": "ðŸ¬", - "shortName": "ðŸ¬" - }, - { - "name": ":", - "shortName": ":" - }, - { - "name": ":))))", - "shortName": "(😀)" - }, - { - "name": "Schulisch entschuldigt", - "shortName": "s" - }, - { - "name": "asdlasdhlaksdhalkshd", - "shortName": "a" - }, - { - "name": "ddddd", - "shortName": "d" - }, - { - "name": "smiley", - "shortName": "😀" - }, - { - "name": "ääääääääääääääääääääääääääääää", - "shortName": "üüüüüüüüüüüüüüüüüüüüüüüüüüüü" - } - ], - "lesson": { - "groups": [ - { - "name": "Ea, Eb, Ec, Ed: La1", - "shortName": "EaEbEcEd-La1", - "members": [ - { - "id": "87", - "fullName": "Mustermann, Max" - }, - { - "id": "76", - "fullName": "Weth, Jonathan" - } - ] - } - ], - "subject": { - "name": "Latein 1" - } - }, - "lessonDocumentations": [ - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 1, - "date": "2020-08-03", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": true, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "Ovid gelesen", - "homework": "übersetzen zeile 1", - "groupNote": "", - "period": 5, - "date": "2020-06-26", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "sehr laut", - "extraMarks": [ - { - "name": "Homework forgotten", - "shortName": "HA" - } - ] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 2, - "date": "2020-06-22", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": true, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 1, - "date": "2020-06-22", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": true, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 5, - "date": "2020-06-19", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 2, - "date": "2020-06-15", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 1, - "date": "2020-06-15", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [ - { - "name": "Homework forgotten", - "shortName": "HA" - } - ] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [ - { - "name": "Homework forgotten", - "shortName": "HA" - } - ] - } - ] - }, - { - "topic": "Blub", - "homework": "Das ist die HA", - "groupNote": "", - "period": 5, - "date": "2020-06-12", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": true, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 2, - "date": "2020-06-08", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": { - "name": "Schulisch entschuldigt", - "shortName": "s" - }, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 5, - "date": "2020-05-08", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 5, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [ - { - "name": "Homework forgotten", - "shortName": "HA" - } - ] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [ - { - "name": "Homework forgotten", - "shortName": "HA" - } - ] - } - ] - }, - { - "topic": "Test", - "homework": "AB beenden", - "groupNote": "Stört!", - "period": 2, - "date": "2020-05-04", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 5, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "Petta", - "extraMarks": [ - { - "name": "Homework forgotten", - "shortName": "HA" - } - ] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "Metrische Analyse des Proömiums, Ãœbersetzung bis V.11, Charakterisierung Aeneas' und Junos", - "homework": "Ãœbersetzung bis V. 17 \"fuit\", Vokabeln Rest, Proömium üben!!", - "groupNote": "Einige Mitglieder des Kurses leiden an Vokabeleritis", - "period": 1, - "date": "2020-05-04", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 5, - "date": "2020-05-01", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 5, - "date": "2020-03-06", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 2, - "date": "2020-03-02", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - }, - { - "topic": "", - "homework": "", - "groupNote": "", - "period": 1, - "date": "2020-03-02", - "personalNotes": [ - { - "person": { - "id": "87", - "fullName": "Mustermann, Max" - }, - "late": 0, - "absent": false, - "excused": false, - "excuseType": null, - "remarks": "", - "extraMarks": [] - }, - { - "person": { - "id": "76", - "fullName": "Weth, Jonathan" - }, - "late": 0, - "absent": true, - "excused": true, - "excuseType": null, - "remarks": "", - "extraMarks": [] - } - ] - } - ], - "extraMarks": [ - { - "name": "Homework forgotten", - "shortName": "HA" - } - ] - + // lessonId: 352 } }, template: ` - <div> - <update-indicator @manual-update="updateManually()" ref="indicator" :status="status"></update-indicator> - <v-subheader>{{ lesson.subject.name }}</v-subheader> - <v-row> - <v-col v-for="item in lessonDocumentations" cols="12" v-bind:key="item.id"> - <lesson-documentation - v-bind:key="item.id" :groups="lesson.groups" :excuse-types="excuseTypes" :extra-marks="extraMarks" - :period="item.period" - - :personal-notes="item.personalNotes" - @change-personal-notes="processDataChange" - - :date="item.date" - @change-date="processDataChange" - - :topic="item.topic" - @change-topic="processDataChange" - - :homework="item.homework" - @change-homework="processDataChange" - - :group-note="item.groupNote" - @change-group-note="processDataChange" - ></lesson-documentation> - </v-col> - </v-row> - </div> -` + <ApolloQuery + :query="gql => gql\` + query CourseBook($lessonId: ID!) { + excuseTypes { + name + shortName + } + lesson: lessonsById(id: $lessonId) { + groups { + name + shortName + members { + id + fullName + } + } + subject { + name + } + } + lessonDocumentations: lessonDocumentationsByLessonId(id: $lessonId) { + topic + homework + groupNote + period + date + personalNotes { + person { + id + fullName + } + late + absent + excused + excuseType { + name + shortName + } + remarks + extraMarks { + name + shortName + } + } + } + + extraMarks { + name + shortName + } +} + + \`" + :variables="{ lessonId }" + > + <template v-slot="{ result: { loading, error, data } }"> + <!-- Error --> + <div v-if="error" class="error apollo">An error occurred</div> + + <!-- Result --> + <div v-else-if="data" class="result apollo"> + <update-indicator @manual-update="updateManually()" ref="indicator" :status="status"></update-indicator> + <v-subheader>{{ data.lesson.subject.name }}</v-subheader> + <v-row v-if="data.lessonDocumentations.length > 0"> + <v-col v-for="item in data.lessonDocumentations" cols="12" v-bind:key="item.id"> + <lesson-documentation + v-bind:key="item.id" + :groups="data.lesson.groups" + :excuse-types="data.excuseTypes" + :extra-marks="data.extraMarks" + :period="item.period" + + :personal-notes="item.personalNotes" + @change-personal-notes="processDataChange" + + :date="item.date" + @change-date="processDataChange" + + :topic="item.topic" + @change-topic="processDataChange" + + :homework="item.homework" + @change-homework="processDataChange" + + :group-note="item.groupNote" + @change-group-note="processDataChange" + ></lesson-documentation> + </v-col> + </v-row> + <message-box v-else type="info">No coursebook for you :(</message-box> + </div> + <!-- No result or Loading --> + <div v-else> + <v-progress-circular + indeterminate + color="primary" + class="ma-auto" + ></v-progress-circular> + </div> + </template> +</ApolloQuery>` } -- GitLab