Skip to content

Commit 44b437c

Browse files
committed
some quick bugfixes & qol improvements
1 parent dedc26c commit 44b437c

File tree

4 files changed

+84
-94
lines changed

4 files changed

+84
-94
lines changed

src/ClassUser.svelte

Lines changed: 64 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
<script lang="ts">
22
import {navigate} from "svelte-navigator";
3-
43
import Button from "@smui/button";
5-
64
import DataTable, { Head, Body, Row, Cell } from '@smui/data-table';
75
import {baseurl, saveBlob} from "./constants";
8-
96
import FormField from '@smui/form-field';
107
import Switch from '@smui/switch';
11-
128
import IconButton, { Icon } from '@smui/icon-button';
13-
149
import Accordion, { Panel, Header, Content } from '@smui-extra/accordion';
15-
16-
1710
import * as marked from 'marked';
18-
1911
import List, {
2012
Item,
2113
Meta,
2214
} from '@smui/list';
2315
import insane from "insane";
2416
import Cookies from "js-cookie";
2517
import Tooltip, {Wrapper} from "@smui/tooltip";
18+
import {onMount} from "svelte";
2619
2720
2821
let grades;
@@ -52,94 +45,80 @@
5245
let isPassing = true;
5346
let printTemplate = false;
5447
55-
function getUserData() {
56-
fetch(`${baseurl}/user/get/data/${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
57-
.then((r) => r.json())
58-
.then((r) => {
59-
userData = r["data"];
60-
isPassing = userData.IsPassing;
61-
});
48+
async function getUserData() {
49+
let response = await fetch(`${baseurl}/user/get/data/${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
50+
let r = await response.json()
51+
userData = r["data"];
52+
isPassing = userData.IsPassing;
6253
}
6354
64-
function getImprovements() {
65-
fetch(`${baseurl}/user/get/improvements?studentId=${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
66-
.then((r) => r.json())
67-
.then((r) => {
68-
improvements = r.data;
69-
});
55+
async function getImprovements() {
56+
let response = await fetch(`${baseurl}/user/get/improvements?studentId=${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
57+
let r = await response.json()
58+
improvements = r.data;
7059
}
7160
72-
function getAbsences() {
73-
fetch(`${baseurl}/user/get/absences/${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
74-
.then((r) => r.json())
75-
.then((r) => {
76-
absences = r["data"];
77-
let al = [];
78-
for (let absence in absences) {
79-
al = [...al, !(absences[absence].IsExcused)]
80-
}
81-
console.log(al);
82-
absenceList = al;
83-
});
61+
async function getAbsences() {
62+
let response = await fetch(`${baseurl}/user/get/absences/${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
63+
let r = await response.json()
64+
absences = r["data"];
65+
let al = [];
66+
for (let absence in absences) {
67+
al = [...al, !(absences[absence].IsExcused)]
68+
}
69+
console.log(al);
70+
absenceList = al;
8471
}
8572
86-
function getUserGradings() {
87-
fetch(`${baseurl}/my/gradings?studentId=${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
88-
.then((r) => r.json())
89-
.then((r) => {
90-
gradings = r["data"];
91-
});
73+
async function getUserGradings() {
74+
let response = await fetch(`${baseurl}/my/gradings?studentId=${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
75+
let r = await response.json()
76+
gradings = r["data"];
9277
}
9378
94-
function getHomework() {
95-
fetch(`${baseurl}/user/get/homework/${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
96-
.then((r) => r.json())
97-
.then((r) => {
98-
homework = r["data"];
99-
});
79+
async function getHomework() {
80+
let response = await fetch(`${baseurl}/user/get/homework/${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
81+
let r = await response.json()
82+
homework = r["data"];
10083
}
10184
102-
function getGrades() {
103-
fetch(`${baseurl}/my/grades?studentId=${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
104-
.then((r) => r.json())
105-
.then((r) => {
106-
if (r.data !== "Forbidden") {
107-
grades = r.data;
108-
}
109-
});
85+
async function getGrades() {
86+
let response = await fetch(`${baseurl}/my/grades?studentId=${studentId}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
87+
let r = await response.json();
88+
if (r.data !== "Forbidden") {
89+
grades = r.data;
90+
}
11091
}
11192
112-
function getParentConfig() {
93+
async function getParentConfig() {
11394
if (localStorage.getItem("role") === "parent") {
114-
fetch(`${baseurl}/parents/get/config`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
115-
.then((r) => r.json())
116-
.then((r) => {
117-
let data = r["data"];
118-
viewAbsences = data["parent_view_absences"];
119-
viewHomework = data["parent_view_homework"];
120-
viewGrades = data["parent_view_grades"];
121-
viewGradings = data["parent_view_gradings"];
122-
if (viewGrades) {
123-
getGrades();
124-
}
125-
if (viewHomework) {
126-
getHomework();
127-
}
128-
if (viewAbsences) {
129-
getAbsences();
130-
}
131-
if (viewGradings) {
132-
getUserGradings();
133-
}
134-
});
95+
let response = await fetch(`${baseurl}/parents/get/config`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
96+
let r = await response.json()
97+
let data = r["data"];
98+
viewAbsences = data["parent_view_absences"];
99+
viewHomework = data["parent_view_homework"];
100+
viewGrades = data["parent_view_grades"];
101+
viewGradings = data["parent_view_gradings"];
102+
if (viewGrades) {
103+
await getGrades();
104+
}
105+
if (viewHomework) {
106+
await getHomework();
107+
}
108+
if (viewAbsences) {
109+
await getAbsences();
110+
}
111+
if (viewGradings) {
112+
await getUserGradings();
113+
}
135114
} else {
136-
getGrades();
137-
getUserData();
138-
getAbsences();
139-
getHomework();
140-
getUserGradings();
115+
await getGrades();
116+
await getUserData();
117+
await getAbsences();
118+
await getHomework();
119+
await getUserGradings();
141120
}
142-
getImprovements();
121+
await getImprovements();
143122
}
144123
145124
const gradeColors = [
@@ -164,7 +143,10 @@
164143
"NOT MANAGED": "NI VPISANO"
165144
}
166145
167-
getParentConfig();
146+
$: {
147+
console.log(studentId)
148+
getParentConfig();
149+
}
168150
</script>
169151

170152
{#if userData}

src/Drawer.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import {useLocation} from "svelte-navigator";
2727
import Checkbox from "@smui/checkbox";
2828
import Cookies from "js-cookie";
29+
import * as child_process from "child_process";
2930
3031
3132
const location = useLocation();
@@ -101,6 +102,10 @@
101102
if (communicationActive !== undefined) {
102103
allPaths[`/communication/${communicationActive}`] = `communication${communicationActive}`
103104
}
105+
for (let i in children) {
106+
const child = children[i];
107+
allPaths[`/class/user/${child.ID}`] = `student${child.ID}`
108+
}
104109
105110
active = allPaths[path]
106111

src/Home.svelte

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
<script lang="ts">
2-
32
import Timetable from "./Widgets/Timetable.svelte";
43
import Select, {Option} from "@smui/select";
54
65
import {baseurl} from "./constants";
76
import * as marked from 'marked';
87
import isMobile from "is-mobile";
98
import insane from "insane";
10-
import Cookies from "js-cookie";
11-
129
10+
import Cookies from "js-cookie";
11+
import {onMount} from "svelte";
1312
const token = Cookies.get("key");
1413
if (token === null || token === undefined) {
1514
document.cookie = "";
1615
window.location.href = "/login";
1716
}
1817
18+
let date = new Date();
19+
1920
let items = [];
2021
let classId = "";
2122
2223
let systemNotifications = [];
2324
2425
const mobile = isMobile();
2526
26-
27-
2827
function loadThings() {
2928
fetch(`${baseurl}/${(localStorage.getItem("role") === "student" || localStorage.getItem("role") === "parent" ? 'user/get/classes' : "classes/get")}`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
3029
.then((response) => {
@@ -44,14 +43,16 @@
4443
});
4544
}
4645
47-
function getSystemNotifications() {
48-
fetch(`${baseurl}/system/notifications`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
49-
.then((response) => response.json())
50-
.then((json) => systemNotifications = json.data);
46+
async function getSystemNotifications() {
47+
let response = await fetch(`${baseurl}/system/notifications`, {headers: {"Authorization": "Bearer " + Cookies.get("key")}})
48+
let json = await response.json()
49+
systemNotifications = json.data
5150
}
5251
53-
loadThings()
54-
getSystemNotifications();
52+
onMount(async () => {
53+
loadThings()
54+
await getSystemNotifications();
55+
});
5556
</script>
5657

5758
{#each systemNotifications as notification}
@@ -92,5 +93,5 @@
9293
</Select>
9394
<p/>
9495
{#if classId !== undefined}
95-
<Timetable classId={classId} />
96+
<Timetable classId={classId} dateCallback={(d) => date = d} date={date} />
9697
{/if}

src/Widgets/Timetable.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949
export let date: Date = new Date();
5050
let currentDate = new Date(date);
5151
export let hour = -1;
52+
export let dateCallback = (day) => {};
5253
5354
let start: Date = startOfWeek(currentDate, {weekStartsOn: 1})
5455
let end: Date = endOfWeek(currentDate, {weekStartsOn: 1})
5556
5657
const mobile: boolean = isMobile();
5758
5859
function remakeCalendar() {
60+
dateCallback(currentDate);
5961
start = startOfWeek(currentDate, {weekStartsOn: 1})
6062
end = endOfWeek(currentDate, {weekStartsOn: 1})
6163
fmtStart = fmtDate(start);

0 commit comments

Comments
 (0)