Skip to content

Commit

Permalink
A lot of improvements:
Browse files Browse the repository at this point in the history
- Principal & assistant principal role - Resolves #24 & Resolves #23
- Principal name in official documents - Linked to #15
- Start of school psychologist role - Linked to #22
- And a lot more small tweaks and big security updates
  • Loading branch information
mytja committed Apr 17, 2022
1 parent c7ab577 commit a7668fc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
28 changes: 22 additions & 6 deletions src/Admin/Users.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
let loaded: boolean = false;
let items = [];
let principalId = undefined;
loadThings();
function loadThings() {
Expand All @@ -20,11 +22,18 @@
.then((json) => {
items = json["data"];
loaded = true;
for (let i in items) {
let item = items[i]
if (item.Role === "principal") {
principalId = item.ID;
break
}
}
},
);
}
let choices = ["student", "parent", "teacher", "admin"];
let choices = ["student", "parent", "teacher", "principal assistant", "principal"];
import jwt_decode, { JwtPayload } from "jwt-decode";
import { navigate } from "svelte-routing";
Expand Down Expand Up @@ -58,14 +67,16 @@
<Cell>{item["Name"]}</Cell>
<Cell>{item["Email"]}</Cell>
<Cell>
{#if decoded["email"] !== item["Email"]}
{#if decoded["user_id"] !== item["ID"]}
<SegmentedButton segments={choices} let:segment singleSelect on:change={(e) => {
e.stopPropagation();
console.log(e);

let fd = new FormData();
fd.append("role", e.detail.segmentId);

principalId = undefined;

fetch(`${baseurl}/user/role/update/${item["ID"]}`, {
headers: {"Authorization": "Bearer " + localStorage.getItem("key")},
body: fd,
Expand All @@ -77,10 +88,15 @@
},
);
}} bind:selected="{item['Role']}">
<!-- Note: the `segment` property is required! -->
<Segment {segment}>
<Label>{segment}</Label>
</Segment>
{#if
(decoded["role"] !== "principal assistant" && segment !== "principal") ||
(decoded["role"] !== "principal assistant" && segment !== "principal assistant")}
{#if !(segment === "principal" && principalId !== undefined && principalId !== item.ID)}
<Segment {segment}>
<Label>{segment}</Label>
</Segment>
{/if}
{/if}
</SegmentedButton>
{/if}
</Cell>
Expand Down
8 changes: 5 additions & 3 deletions src/ClassUser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
fetch(`${baseurl}/my/grades?studentId=${studentId}`, {headers: {"Authorization": "Bearer " + localStorage.getItem("key")}})
.then((r) => r.json())
.then((r) => {
grades = r["data"];
if (grades.data !== "Forbidden") {
grades = r["data"];
}
});
}
Expand Down Expand Up @@ -138,7 +140,7 @@
{#if userData}
<h1>{userData.Name}</h1>
{/if}
{#if decoded.role === "admin"}
{#if decoded.role === "admin" || decoded.role === "principal" || decoded.role === "principal assistant" || decoded.role === "school psychologist"}
<Button on:click={() => {
fetch(`${baseurl}/user/get/certificate_of_schooling/${studentId}`, {headers: {"Authorization": "Bearer " + localStorage.getItem("key")}})
.then((response) => response.blob())
Expand Down Expand Up @@ -199,7 +201,7 @@
{:else}
Sistemski administrator je izključil vpogled v ocene otroka za vse starše.
{/if}
{#if decoded.role === "teacher" || decoded.role === "admin"}
{#if decoded.role === "teacher" || decoded.role === "admin" || decoded.role === "principal" || decoded.role === "principal assistant"}
<p/>
<Button on:click={() => {
fetch(`${baseurl}/user/get/ending_certificate/${studentId}`, {headers: {"Authorization": "Bearer " + localStorage.getItem("key")}})
Expand Down
2 changes: 1 addition & 1 deletion src/Classes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<Textfield label="Nov razred" bind:value={nclass}>
<HelperText slot="helper">Vpišite prosimo ime novega razreda</HelperText>
</Textfield>
<Textfield label="Dolgo ime predmeta" bind:value={classYear} style="width: 100%;" on:change={() => patchClass()}>
<Textfield label="Šolsko leto" bind:value={classYear} style="width: 100%;" on:change={() => patchClass()}>
<HelperText slot="helper">Vpišite prosimo šolsko leto - to ime se bo prikazalo na spričevalu, zato bodite še posebej previdni (primer - 2021/2022)</HelperText>
</Textfield>
<Select bind:teacherId label="Izberite razrednika" variant="outlined">
Expand Down
8 changes: 4 additions & 4 deletions src/Drawer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<Text>Pregled</Text>
</Item>
{#if meetingActive === -1}
{#if decoded.role === "admin" || decoded.role === "teacher" || decoded.role === "student"}
{#if decoded.role === "admin" || decoded.role === "principal" || decoded.role === "principal assistant" || decoded.role === "teacher" || decoded.role === "student"}
<Item
href="javascript:void(0)"
on:click={() => navigate('/samotestiranje')}
Expand Down Expand Up @@ -133,7 +133,7 @@
</Item>
{/each}
{/if}
{#if decoded["role"] === "teacher" || decoded["role"] === "admin"}
{#if decoded["role"] === "teacher" || decoded.role === "principal" || decoded.role === "principal assistant" || decoded["role"] === "admin"}
<Item
href="javascript:void(0)"
on:click={() => navigate('/new/meeting')}
Expand Down Expand Up @@ -169,7 +169,7 @@
<Text>Redovalnica</Text>
</Item>-->
{/if}
{#if decoded["role"] === "admin"}
{#if decoded["role"] === "admin" || decoded.role === "principal" || decoded.role === "principal assistant"}
<Item
href="javascript:void(0)"
on:click={() => navigate('/users')}
Expand Down Expand Up @@ -212,7 +212,7 @@
</Item>
{/if}
{/if}
{#if meetingActive !== -1 && (decoded["role"] === "admin" || decoded["role"] === "teacher")}
{#if meetingActive !== -1 && (decoded["role"] === "admin" || decoded["role"] === "teacher" || decoded.role === "principal" || decoded.role === "principal assistant")}
<Item
href="javascript:void(0)"
on:click={() => navigate(`/meeting/${meetingActive}`)}
Expand Down
4 changes: 2 additions & 2 deletions src/Meals.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<Drawer active="meals" />
<AppContent class="app-content">
<main class="main-content">
{#if decoded.role === "admin"}
{#if decoded.role === "admin" || decoded.role === "principal" || decoded.role === "principal assistant" || decoded.role === "food organizer"}
<h1>Dodaj nov meni</h1>
<Textfield bind:value={date} label="Datum menija" type="date" required on:click={() => date = ""}>
<Icon class="material-icons" slot="leadingIcon">event</Icon>
Expand Down Expand Up @@ -267,7 +267,7 @@
{/if}
<p/>
{/if}
{#if decoded.role === "admin"}
{#if decoded.role === "admin" || decoded.role === "principal" || decoded.role === "principal assistant" || decoded.role === "food organizer"}
<Button on:click={() => {
mealDescription = meal.Meals;
date = meal.Date;
Expand Down
4 changes: 2 additions & 2 deletions src/Meeting.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
const decoded = jwt_decode<JwtPayload>(token);
if (decoded["role"] === "admin") {
if (decoded["role"] === "admin" || decoded["role"] === "principal" || decoded["role"] === "principal assistant") {
getTeachers();
}
</script>
Expand Down Expand Up @@ -125,7 +125,7 @@
<Label>Izbriši</Label>
</Button>
{/if}
{#if decoded["role"] === "admin"}
{#if decoded["role"] === "admin" || decoded.role === "principal" || decoded.role === "principal assistant"}
<p/>
<FormField>
<Switch bind:checked={isSubstitution} on:click={() => {
Expand Down
2 changes: 1 addition & 1 deletion src/Samotestiranje.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</script>

<Drawer active="samotestiranje" />
{#if decoded.role === "teacher" || decoded.role === "admin"}
{#if decoded.role === "teacher" || decoded.role === "admin" || decoded.role === "principal" || decoded.role === "principal assistant"}
<AppContent class="app-content">
<div
tabindex="0"
Expand Down

0 comments on commit a7668fc

Please sign in to comment.