Skip to content

Commit

Permalink
chore: translations, import fixes and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed Apr 18, 2024
1 parent 64ca04e commit d75c3e9
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 18 deletions.
6 changes: 5 additions & 1 deletion frontend/src/assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@
"noProjects": "No projects on selected date."
},
"projects": {
"all": "All projects",
"coming": "Near deadlines",
"deadline": "Deadline",
"submissionStatus": "Indienstatus",
"days": "Today at {hour} | Tomorrow at {hour} | In {count} days",
"start": "Start date",
"submissionStatus": "Submission status",
"group": "Group",
"groupMembers": "Group members",
"chooseGroup": "Choose a group",
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/components/courses/CourseGeneralCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import { useGlob } from '@/composables/glob.ts';
/* Props */
defineProps<{
course: Course;
courses: Course[];
}>();
/* Emits */
const emit = defineEmits(['update:courses']);
/* Composable injections */
const { user } = storeToRefs(useAuthStore());
Expand All @@ -36,7 +40,12 @@ const { getImport } = useGlob(import.meta.glob('@/assets/img/faculties/*.png', {
</div>
</div>
<div v-if="user && user.isStudent()">
<StudentCourseJoinButton :student="user as Student" :course="course" />
<StudentCourseJoinButton
:student="user as Student"
:courses="courses"
:course="course"
@update:courses="emit('update:courses')"
/>
</div>
</div>
</div>
Expand Down
34 changes: 33 additions & 1 deletion frontend/src/components/courses/CourseList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { type Course } from '@/types/Course.ts';
import { useI18n } from 'vue-i18n';
import { PrimeIcons } from 'primevue/api';
import Button from 'primevue/button';
import { useCourses } from '@/composables/services/course.service.ts';
import { storeToRefs } from 'pinia';
import { useAuthStore } from '@/store/authentication.store.ts';
import { watch } from 'vue';
/* Props */
interface Props {
Expand All @@ -20,7 +24,29 @@ withDefaults(defineProps<Props>(), {
});
/* Composable injections */
const courseService = useCourses();
const { t } = useI18n();
const { user } = storeToRefs(useAuthStore());
/* State */
const userCourses = courseService.courses;
/**
* Load the courses based on the user role.
*/
async function loadCourses(): Promise<void> {
if (user.value !== null) {
if (user.value.isStudent()) {
await courseService.getCoursesByStudent(user.value.id);
} else if (user.value.isAssistant()) {
await courseService.getCourseByAssistant(user.value.id);
} else if (user.value.isTeacher()) {
await courseService.getCoursesByTeacher(user.value.id);
}
}
}
watch(user, loadCourses, { immediate: true });
</script>

<template>
Expand All @@ -42,7 +68,13 @@ const { t } = useI18n();
</slot>
</template>
</CourseDetailCard>
<CourseGeneralCard class="h-full" :course="course" v-else />
<CourseGeneralCard
class="h-full"
:course="course"
:courses="userCourses ?? []"
@update:courses="loadCourses"
v-else
/>
</div>
</template>
<template v-else>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@
import Button from 'primevue/button';
import { type Course } from '@/types/Course.ts';
import { type Student } from '@/types/users/Student.ts';
import { useAuthStore } from '@/store/authentication.store.ts';
import { useMessagesStore } from '@/store/messages.store.ts';
import { useStudents } from '@/composables/services/student.service.ts';
import { useI18n } from 'vue-i18n';
/* Props */
const props = defineProps<{ student: Student; course: Course }>();
const props = defineProps<{ student: Student; courses: Course[]; course: Course }>();
/* Composable injections */
const { refreshUser } = useAuthStore();
const { addSuccessMessage, addErrorMessage } = useMessagesStore();
const { studentJoinCourse, studentLeaveCourse } = useStudents();
const { t } = useI18n();
/* Emits */
const emit = defineEmits(['update:courses']);
/**
* Check if the student has already enrolled in the course.
*
* @param course The course to check
* @returns True if the student has the course, false otherwise
*/
function hasCourse(course: Course): boolean {
return props.courses.some((c) => c.id === course.id);
}
/**
* Enroll the student in the course.
*/
Expand All @@ -28,7 +39,7 @@ async function joinCourse(): Promise<void> {
t('toasts.messages.courses.enrollment.success', [props.course.name]),
);
await refreshUser();
emit('update:courses');
} catch (error) {
addErrorMessage(t('toasts.messages.error'), t('toasts.messages.courses.enrollment.error', [props.course.name]));
}
Expand All @@ -46,7 +57,7 @@ async function leaveCourse(): Promise<void> {
t('toasts.messages.courses.leave.success', [props.course.name]),
);
await refreshUser();
emit('update:courses');
} catch (error) {
addErrorMessage(t('toasts.messages.error'), t('toasts.messages.courses.leave.error', [props.course.name]));
}
Expand All @@ -60,7 +71,7 @@ async function leaveCourse(): Promise<void> {
icon-pos="right"
icon="pi pi-arrow-right"
@click="joinCourse"
v-if="!student.hasCourse(course)"
v-if="!hasCourse(course)"
link
/>
<Button
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/services/assistant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type User } from '@/types/users/User.ts';
import { Response } from '@/types/Response';
import { type Ref, ref } from 'vue';
import { endpoints } from '@/config/endpoints.ts';
import { get, getList, create, deleteId, deleteIdWithData } from '@/composables/services/helpers.ts';
import { get, getList, create, deleteId, deleteIdWithData, getPaginatedList } from '@/composables/services/helpers.ts';
import { type PaginatorResponse } from '@/types/filter/Paginator.ts';
import { type Filter } from '@/types/filter/Filter.ts';

Expand Down
8 changes: 0 additions & 8 deletions frontend/src/types/users/Student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,4 @@ export class Student extends User {
public getRole(): string {
return 'types.roles.student';
}

/**
* Check if the student has a course.
* @param course
*/
public hasCourse(course: Course): boolean {
return this.courses.some((c) => c.id === course.id);
}
}

0 comments on commit d75c3e9

Please sign in to comment.