Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed May 21, 2024
1 parent 7a839b9 commit 1fb9ec5
Show file tree
Hide file tree
Showing 42 changed files with 614 additions and 497 deletions.
3 changes: 1 addition & 2 deletions backend/api/serializers/project_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ class ProjectSerializer(serializers.ModelSerializer):
)

extra_checks = serializers.HyperlinkedIdentityField(
view_name="project-extra-checks",
read_only=True
view_name="project-extra-checks"
)

groups = serializers.HyperlinkedIdentityField(
Expand Down
1 change: 1 addition & 0 deletions frontend/src/assets/lang/app/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"courses": {
"create": "Create course",
"edit": "Edit course",
"save": "Save course",
"clone": "Clone course",
"cloneAssistants": "Clone assistants:",
"cloneTeachers": "Clone teachers:",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/assets/lang/app/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"courses": {
"create": "Creëer vak",
"edit": "Bewerk vak",
"save": "Vak opslaan",
"clone": "Kloon vak",
"cloneAssistants": "Kloon assistenten:",
"cloneTeachers": "Kloon lesgevers:",
Expand Down
12 changes: 5 additions & 7 deletions frontend/src/components/Loading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
import ProgressSpinner from 'primevue/progressspinner';
import { useTimeout } from '@vueuse/core';
withDefaults(defineProps<{height?:string}>(), {
height: '4rem'
withDefaults(defineProps<{ height?: string }>(), {
height: '4rem',
});
const show = useTimeout(250);
</script>

<template>
<div :style="{minHeight: height}" class="loader w-full p-3 flex justify-content-center">
<ProgressSpinner stroke="blue" v-if="show"/>
<div :style="{ minHeight: height }" class="loader w-full p-3 flex justify-content-center">
<ProgressSpinner stroke="blue" v-if="show" />
</div>
</template>

<style scoped lang="scss">
</style>
<style scoped lang="scss"></style>
60 changes: 28 additions & 32 deletions frontend/src/components/courses/CourseForm.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<script setup lang="ts">
import { Course } from '@/types/Course.ts';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { useFaculty } from '@/composables/services/faculty.service.ts';
import { useCourses } from '@/composables/services/course.service.ts';
import { computed, onMounted, ref } from 'vue';
import { computed, ref, watchEffect } from 'vue';
import { helpers, required } from '@vuelidate/validators';
import { useVuelidate } from '@vuelidate/core';
import Textarea from 'primevue/textarea';
Expand All @@ -14,17 +11,19 @@ import ErrorMessage from '@/components/forms/ErrorMessage.vue';
import Button from 'primevue/button';
import Editor from '@/components/forms/Editor.vue';
import InputSwitch from 'primevue/inputswitch';
import { type Faculty } from '@/types/Faculty.ts';
/* Props */
const props = defineProps<{
faculties: Faculty[];
course?: Course | undefined;
}>();
/* Emits */
const emit = defineEmits(['update:course']);
/* Composable injections */
const { t } = useI18n();
const { push } = useRouter();
const { faculties, getFaculties } = useFaculty();
const { createCourse, updateCourse } = useCourses();
/* State */
const form = ref(new Course());
Expand All @@ -48,27 +47,30 @@ async function saveCourse(): Promise<void> {
// Only submit the form if the validation was successful
if (result) {
// Update the course if it has been provided before.
if (props.course !== undefined) {
await updateCourse(form.value);
await push({ name: 'course', params: { courseId: props.course.id } });
}
// Create a course in the other case.
if (props.course === undefined) {
await createCourse(form.value);
await push({ name: 'dashboard' });
}
emit('update:course', form.value);
}
}
onMounted(async () => {
await getFaculties();
/* Set the form values with the existing course */
if (props.course !== undefined) {
// Convenient way of copying the course fields.
form.value = Course.fromJSON(props.course);
/**
* Watch for changes in the course prop and update the form values.
*/
watchEffect(() => {
/* Set the form values with the existing project */
const course = props.course;
if (course !== undefined) {
form.value = new Course(
course.id,
course.name,
course.excerpt,
course.description,
course.academic_startyear,
course.private_course,
course.invitation_link,
course.invitation_link_expires,
course.parent_course,
course.faculty,
);
}
});
</script>
Expand Down Expand Up @@ -120,13 +122,7 @@ onMounted(async () => {
</div>

<!-- Submit button -->
<Button
:label="course === undefined ? t('views.courses.create') : t('views.courses.edit')"
type="submit"
icon="pi pi-check"
iconPos="right"
rounded
/>
<Button :label="t('views.courses.save')" type="submit" icon="pi pi-check" iconPos="right" rounded />
</form>
</template>

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/courses/ShareCourseButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { type Course } from '@/types/Course.ts';
import { PrimeIcons } from 'primevue/api';
import { ref, computed } from 'vue';
import { useCourses } from '@/composables/services/course.service';
import Editor from '@/components/forms/Editor.vue';
/* Composable injections */
const { t } = useI18n();
Expand Down Expand Up @@ -87,7 +86,7 @@ const invitationLink = computed(() => {
<div class="field col">
<label for="link">{{ t('views.courses.share.link') }}</label>
<div class="flex">
<InputText v-model="invitationLink" disabled/>
<InputText v-model="invitationLink" disabled />
<Button @click="copyToClipboard()" icon="pi pi-copy" class="p-button-text no-outline" />
</div>
</div>
Expand Down
67 changes: 33 additions & 34 deletions frontend/src/components/projects/ProjectForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ErrorMessage from '@/components/forms/ErrorMessage.vue';
import Button from 'primevue/button';
import Editor from '@/components/forms/Editor.vue';
import Calendar from 'primevue/calendar';
import Skeleton from 'primevue/skeleton';
import InputSwitch from 'primevue/inputswitch';
import { Project } from '@/types/Project.ts';
import { useI18n } from 'vue-i18n';
Expand Down Expand Up @@ -81,12 +80,22 @@ watchEffect(() => {
const project = props.project;
if (project !== undefined) {
form.value = Project.fromJSON(project);
form.value.structure_checks = [...(project.structure_checks ?? [])];
form.value.extra_checks = [...(project.extra_checks ?? [])];
} else {
form.value.structure_checks = [];
form.value.extra_checks = [];
form.value = new Project(
project.id,
project.name,
project.description,
project.visible,
project.archived,
project.locked_groups,
project.start_date,
project.deadline,
project.max_score,
project.score_visible,
project.group_size,
);
form.value.structure_checks = [...project.structure_checks];
form.value.extra_checks = [...project.extra_checks];
}
});
</script>
Expand Down Expand Up @@ -191,41 +200,31 @@ watchEffect(() => {

<div class="col-12 lg:col-6">
<!-- Define the submission structure checks -->
<template v-if="form.structure_checks !== null">
<div class="grid">
<div class="field col">
<label for="structure">{{ t('views.projects.structureChecks') }}</label>
<ProjectStructureTree id="structure" v-model="form.structure_checks" />
</div>
<div class="grid">
<div class="field col">
<label for="structure">{{ t('views.projects.structureChecks') }}</label>
<ProjectStructureTree id="structure" v-model="form.structure_checks" />
</div>
</template>
<template v-else>
<Skeleton height="10rem" />
</template>
</div>

<!-- Upload field for docker script -->
<template v-if="form.extra_checks !== null">
<div class="grid">
<div class="field col">
<label for="dockerScript" class="block">
{{ t('views.projects.extraChecks.title') }}
</label>
<ExtraChecksUpload
v-model="form.extra_checks"
:docker-images="dockerImages"
@create:docker-image="saveDockerImage"
/>
</div>
<div class="grid">
<div class="field col">
<label for="dockerScript" class="block">
{{ t('views.projects.extraChecks.title') }}
</label>
<ExtraChecksUpload
v-model="form.extra_checks"
:docker-images="dockerImages"
@create:docker-image="saveDockerImage"
/>
</div>
</template>
<template v-else>
<Skeleton height="10rem" />
</template>
</div>
</div>
</div>

<!-- Submit button -->
<Button :label="t('views.projects.edit')" type="submit" icon="pi pi-check" iconPos="right" rounded />
<Button :label="t('views.projects.save')" type="submit" icon="pi pi-check" iconPos="right" rounded />
</form>
</template>

Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/projects/ProjectList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import moment from 'moment';
import Skeleton from 'primevue/skeleton';
import InputSwitch from 'primevue/inputswitch';
import ProjectDetailCard from '@/components/projects/ProjectDetailCard.vue';
import ProjectDeadlineCard from '@/components/projects/ProjectDeadlineCard.vue';
Expand Down Expand Up @@ -110,7 +109,7 @@ const incomingProjects = computed<Project[] | null>(() => {
</template>
</template>
<template v-else>
<Loading height="50vh"/>
<Loading height="50vh" />
</template>
</div>
</div>
Expand All @@ -130,7 +129,7 @@ const incomingProjects = computed<Project[] | null>(() => {
</div>
</template>
<template v-else>
<Loading height="50vh"/>
<Loading height="50vh" />
</template>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/unit/services/group_service.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { describe, it, expect } from 'vitest';
import { describe, it } from 'vitest';

describe('placeholder', (): void => {
it('aaaaaaaa', () => {});
Expand Down
13 changes: 1 addition & 12 deletions frontend/src/test/unit/services/setup/delete_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
import { HttpResponse, http } from 'msw';

import { endpoints } from '@/config/endpoints.ts';
import {
groups,
projects,
courses,
faculties,
students,
teachers,
assistants,
admins,
structureChecks,
submissions,
} from './data';
import { assistants, admins, structureChecks } from './data';

const baseUrl = 'http://localhost';

Expand Down
13 changes: 1 addition & 12 deletions frontend/src/test/unit/services/setup/post_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
import { HttpResponse, http } from 'msw';

import { endpoints } from '@/config/endpoints.ts';
import {
groups,
projects,
courses,
faculties,
students,
teachers,
assistants,
admins,
structureChecks,
submissions,
} from './data';
import { groups, projects, courses, faculties, students, assistants, admins, structureChecks } from './data';

const baseUrl = 'http://localhost';

Expand Down
11 changes: 1 addition & 10 deletions frontend/src/test/unit/services/structure_check.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { describe, it, expect } from 'vitest';
import { useStructureCheck } from '@/composables/services/structure_check.service.ts';
import { StructureCheck } from '@/types/StructureCheck';

const {
structureChecks,
structureCheck,
getStructureCheckByID,
getStructureCheckByProject,

createStructureCheck,
deleteStructureCheck,
} = useStructureCheck();
const { structureChecks, structureCheck, getStructureCheckByID } = useStructureCheck();

function resetService(): void {
structureCheck.value = null;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/unit/types/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { describe, it, expect } from 'vitest';
import { describe, it } from 'vitest';

describe('placeholder', (): void => {
it('aaaaaaaa', () => {});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/unit/types/project.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { describe, it, expect } from 'vitest';
import { describe, it } from 'vitest';

describe('placeholder', (): void => {
it('aaaaaaaa', () => {});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/ApiResponse.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type HyperlinkedRelation = string;
export type HyperlinkedRelation = string;
8 changes: 4 additions & 4 deletions frontend/src/types/Course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { type Assistant } from './users/Assistant.ts';
import { type Project } from './Project.ts';
import { type Student } from './users/Student.ts';
import { type Teacher } from './users/Teacher.ts';
import { Faculty, FacultyJSON } from '@/types/Faculty.ts';
import { HyperlinkedRelation } from '@/types/ApiResponse.ts';
import { Faculty, type FacultyJSON } from '@/types/Faculty.ts';
import { type HyperlinkedRelation } from '@/types/ApiResponse.ts';

export type CourseJSON = {
export interface CourseJSON {
id: string;
name: string;
academic_startyear: number;
Expand Down Expand Up @@ -81,7 +81,7 @@ export class Course {
* @param course
*/
static fromJSON(course: CourseJSON): Course {
let parent: CourseJSON|Course|null = course.parent_course;
let parent: CourseJSON | Course | null = course.parent_course;

if (parent !== null) {
parent = Course.fromJSON(parent);
Expand Down
Loading

0 comments on commit 1fb9ec5

Please sign in to comment.