Skip to content

Commit

Permalink
chore: projectcard group props
Browse files Browse the repository at this point in the history
  • Loading branch information
francisvaut committed Apr 18, 2024
1 parent a987dee commit b3e5d45
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
29 changes: 7 additions & 22 deletions frontend/src/components/projects/ProjectCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import MeterGroup from 'primevue/metergroup';
import Card from 'primevue/card';
import Button from 'primevue/button';
import { type Project } from '@/types/Project.ts';
import { type Group } from '@/types/Group.ts';
import { PrimeIcons } from 'primevue/api';
import { useI18n } from 'vue-i18n';
import { computed, watch } from 'vue';
import { type Course } from '@/types/Course.ts';
import { useSubmissionStatus } from '@/composables/services/submission_status.service.ts';
import { storeToRefs } from 'pinia';
import { useAuthStore } from '@/store/authentication.store.ts';
import { useGroup } from '@/composables/services/group.service';
/**
* TODO
Expand All @@ -24,6 +22,8 @@ const props = withDefaults(
type?: 'small' | 'large';
project: Project;
course: Course;
projectGroups: Group[];
studentGroups: Group[];
}>(),
{
type: 'large',
Expand Down Expand Up @@ -62,16 +62,13 @@ const meterItems = computed(() => {
/* Composable injections */
const { t } = useI18n();
const { submissionStatus, getSubmissionStatusByProject } = useSubmissionStatus();
const { groups, getGroupsByStudent } = useGroup();
const { user } = storeToRefs(useAuthStore());
/**
* Return True if the user is in a group in this project.
*/
// function isInGroup(): Boolean {
// console.log(groups)
// return true;
// }
function isInGroup(): Boolean {
return props.studentGroups.some(group => props.projectGroups.includes(group));
}
/* Watchers */
Expand All @@ -84,18 +81,6 @@ watch(
immediate: true,
},
);
watch(
user,
() => {
if (user.value !== null && user.value.isStudent()) {
getGroupsByStudent(user.value.id)
}
},
{
immediate: true,
},
);
</script>

<template>
Expand Down Expand Up @@ -203,7 +188,7 @@ watch(
/>
</RouterLink>
<RouterLink
v-if="false"
v-if="isInGroup()"
:to="{
name: 'submission',
params: {
Expand Down
35 changes: 34 additions & 1 deletion frontend/src/components/projects/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import moment from 'moment';
import Skeleton from 'primevue/skeleton';
import InputSwitch from 'primevue/inputswitch';
import ProjectCard from '@/components/projects/ProjectCard.vue';
import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { type Project } from '@/types/Project.ts';
import { type Group } from '@/types/Group.ts';
import { storeToRefs } from 'pinia';
import { useAuthStore } from '@/store/authentication.store.ts';
import { useStudents } from '@/composables/services/student.service';
/* Props */
const props = withDefaults(
Expand All @@ -21,10 +25,35 @@ const props = withDefaults(
/* Composables */
const { t } = useI18n();
const { user } = storeToRefs(useAuthStore());
const { student, getStudentByID } = useStudents();
/**
* Get the groups of the corresponding users
*/
function getUserGroups(): Group[] {
if (user.value?.isStudent()) {
return (student.value?.groups || []);
}
return [];
}
/* State */
const showPast = ref(false);
/* Watchers */
watch(
user,
() => {
if (user.value !== null && user.value.isStudent()) {
getStudentByID(user.value.id)
}
},
{
immediate: true,
},
);
/* Sorts the projects by deadline */
const sortedProjects = computed<Project[] | null>(() => {
const projects =
Expand Down Expand Up @@ -68,6 +97,8 @@ const incomingProjects = computed<Project[] | null>(() => {
type="small"
:project="project"
:course="project.course"
:projectGroups="project.groups"
:studentGroups="getUserGroups()"
v-if="project.course !== null"
/>
</div>
Expand Down Expand Up @@ -97,6 +128,8 @@ const incomingProjects = computed<Project[] | null>(() => {
class="h-100"
:project="project"
:course="project.course"
:projectGroups="project.groups"
:studentGroups="getUserGroups()"
v-if="project.course !== null"
/>
</div>
Expand Down

0 comments on commit b3e5d45

Please sign in to comment.