Skip to content
Snippets Groups Projects
Commit 3ab4d88e authored by Ewen Le Bihan's avatar Ewen Le Bihan
Browse files

feat(frappe): improve /documents

parent 8c7a7803
Branches
Tags v1.14.0
No related merge requests found
......@@ -9,6 +9,7 @@ export const MajorType = builder.prismaObject('Major', {
shortName: t.exposeString('shortName'),
schools: t.relation('schools', { query: { orderBy: { name: 'asc' } } }),
minors: t.relation('minors', { query: { orderBy: { name: 'asc' } } }),
subjects: t.relation('subjects', { query: { orderBy: { name: 'asc' } } }),
}),
});
......
<script lang="ts">
import Breadcrumbs from '$lib/components/Breadcrumbs.svelte';
import CardMajor from '$lib/components/CardMajor.svelte';
import groupBy from 'lodash.groupby';
import type { PageData } from './$types';
import { me } from '$lib/session';
export let data: PageData;
const majorsBySchool = Object.entries(groupBy(data.majors, (m) => m.schools[0]?.uid))
.map(([schoolUid, majors]) => [schoolUid, majors.filter((m) => m.subjects.length > 0)])
.filter(([_, majors]) => majors.length > 0)
.sort(([schoolUid]) => {
// Put schools of the user first
if ($me?.major.schools.some((s) => s.uid === schoolUid)) return -1;
return 1;
}) as Array<[string, typeof data.majors]>;
</script>
<Breadcrumbs root="/documents"></Breadcrumbs>
{#each majorsBySchool as [schoolUid, majorsOfSchool]}
{@const school = data.schools.find((s) => s.uid === schoolUid)}
<section class="majors-of-school">
{#if school}
<h2 class="typo-field-label">{school.name}</h2>
{:else}
<pre>{schoolUid}</pre>
{/if}
<ul class="nobullet">
{#each data.majors as major}
{#each majorsOfSchool as major}
<li>
<CardMajor href="./{major.uid}" {...major}></CardMajor>
</li>
{/each}
</ul>
</section>
{/each}
<style>
ul {
display: flex;
flex-direction: column;
gap: 1rem;
margin-top: 2rem;
}
h2 {
margin-top: 1.5rem;
margin-bottom: 1em;
font-size: 1rem;
font-weight: bold;
}
</style>
......@@ -9,6 +9,17 @@ export const load: PageLoad = async ({ fetch, parent }) =>
name: true,
shortName: true,
uid: true,
schools: {
uid: true,
name: true,
},
subjects: {
id: true,
},
},
schools: {
uid: true,
name: true,
},
},
{ fetch, parent },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment