Skip to content

Commit

Permalink
Merge branch 'dev' into query-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
reyniersbram committed May 10, 2024
2 parents 0a08785 + cc3f1f7 commit 8004cfa
Show file tree
Hide file tree
Showing 25 changed files with 836 additions and 106 deletions.
69 changes: 69 additions & 0 deletions frontend/src/components/buttons/GroupButtons.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<template>
<v-btn v-if="canLeaveGroup" @click="() => leaveGroup({ groupId: group.id })">
{{ $t("group.leave_group") }}
</v-btn>
<v-btn v-else-if="canJoinGroup" @click="() => joinGroup({ groupId: group.id })">
{{ $t("group.join_group") }}
</v-btn>
<v-btn v-if="isTeacher" @click="() => removeGroup({ groupId: group.id })">
{{ $t("group.remove_group") }}
</v-btn>
</template>

<script setup lang="ts">
import type Group from "@/models/Group.js";
import type Project from "@/models/Project.js";
import type User from "@/models/User.js";
import { computed, toRefs } from "vue";
import {
useJoinGroupUserMutation,
useLeaveGroupUserMutation,
useRemoveGroupMutation,
useUserGroupsQuery,
} from "@/queries/Group";
const props = defineProps<{
group: Group;
project: Project;
user: User;
amountOfMembers: number;
}>();
const { group, project, user, amountOfMembers } = toRefs(props);
const canJoinGroup = computed(() => {
return (
!isUserInGroup.value &&
amountOfMembers.value < project.value.capacity &&
!isTeacher.value &&
!isUserInAnotherGroup.value
);
});
const canLeaveGroup = computed(() => {
return project.value.capacity !== 1 && isUserInGroup.value && !isTeacher.value;
});
const isTeacher = computed(() => user.value.is_teacher || false);
const isUserInGroup = computed(() => {
return group.value.members.some((member) => member.uid === user.value.uid);
});
const { data: groups } = useUserGroupsQuery();
const isUserInAnotherGroup = computed(() => {
if (!groups.value) return true;
return groups.value.some((groupelem) => {
return groupelem.project_id === project.value.id && groupelem.id !== group.value.id;
});
});
const { mutateAsync: leaveGroup } = useLeaveGroupUserMutation();
const { mutateAsync: joinGroup } = useJoinGroupUserMutation();
const { mutateAsync: removeGroup } = useRemoveGroupMutation();
</script>

<style scoped></style>
59 changes: 28 additions & 31 deletions frontend/src/components/form_elements/FilesInput.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
<template>
<v-container>
<v-row>
<v-col>
<input @change="updateFiles" ref="fileInput" type="file" multiple hidden />
<v-btn class="mb-0" @click="onAddFilesClick">{{
$t("submit.add_files_button")
}}</v-btn>
</v-col>
</v-row>
<v-row class="mt-0">
<v-col>
<div v-if="inputFiles.length === 0">
<p>{{ $t("submit.no_files_added") }}</p>
</div>
<div v-else>
<v-chip
v-for="(item, index) in inputFiles"
:key="item.name"
class="ma-1"
closable
label
@click:close="() => onDeleteClick(index)"
>
<v-icon icon="mdi-file" start></v-icon>
{{ item.name }} ({{ formatBytes(item.size) }})
</v-chip>
</div>
</v-col>
</v-row>
</v-container>
<input @change="updateFiles" ref="fileInput" type="file" multiple hidden />
<v-btn variant="flat" class="mb-0" @click="onAddFilesClick">{{
$t("submit.add_files_button")
}}</v-btn>
<div v-if="inputFiles.length === 0" class="files">
<p>{{ $t("submit.no_files_added") }}</p>
</div>
<div v-else>
<v-chip
v-for="(item, index) in inputFiles"
:key="item.name"
class="ma-1"
closable
label
@click:close="() => onDeleteClick(index)"
>
<v-icon icon="mdi-file" start></v-icon>
{{ item.name }} ({{ formatBytes(item.size) }})
</v-chip>
</div>
</template>

<script setup lang="ts">
Expand Down Expand Up @@ -64,5 +54,12 @@ function onDeleteClick(index: number) {
inputFiles.value.splice(index, 1);
}
</script>
<style scoped>
.v-btn {
background-color: rgb(var(--v-theme-secondary));
}
<style scoped></style>
.files {
margin-top: 15px;
}
</style>
48 changes: 48 additions & 0 deletions frontend/src/components/home/cards/GroupCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<v-card class="v-card-padding">
<v-row>
<v-col cols="8">
<router-link :to="`/groups/${group.id}`">
{{ group.team_name }}
</router-link>
</v-col>
<v-col cols="2">
{{ amountOfMembers + "/" + project.capacity }}
</v-col>
<v-col cols="2">
<GroupButtons
:amountOfMembers="amountOfMembers"
:group="group"
:project="project"
:user="user"
/>
</v-col>
</v-row>
</v-card>
</template>

<script setup lang="ts">
import { computed, toRefs } from "vue";
import type Project from "@/models/Project";
import type Group from "@/models/Group";
import type User from "@/models/User";
import GroupButtons from "@/components/buttons/GroupButtons.vue";
const props = defineProps<{
group: Group;
project: Project;
user: User;
}>();
const { group, project, user } = toRefs(props);
const amountOfMembers = computed(() => {
return group.value.members.length;
});
</script>

<style scoped>
.v-card-padding {
padding: 5px;
}
</style>
13 changes: 3 additions & 10 deletions frontend/src/components/navigation/DropDownList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-list class="items bg-primary">
<v-list-item data-test="logoutButton" v-if="loggedInValue.value">
<v-list-item data-test="logoutButton" v-if="loggedInValue">
<LogoutButton />
</v-list-item>
<v-list-item data-test="localeSwitcher">
Expand All @@ -18,17 +18,10 @@ import LogoutButton from "@/components/buttons/LogoutButton.vue";
import ThemeSwitcher from "@/components/switcher/ThemeSwitcher.vue";
import { useAuthStore } from "@/stores/auth-store";
import { storeToRefs } from "pinia";
import { ref } from "vue";
const loggedInValue = ref(false);
const beforeCreate = async function beforeCreate() {
const { isLoggedIn } = storeToRefs(useAuthStore());
loggedInValue.value = isLoggedIn;
};
beforeCreate();
const { isLoggedIn } = useAuthStore();
const loggedInValue = ref(isLoggedIn);
</script>

<style scoped>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/navigation/DropDownMobile.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<v-menu transition="slide-y-transition">
<v-menu>
<template v-slot:activator="{ props }">
<v-btn v-bind="props" class="menu">
<v-icon class="mdi mdi-dots-vertical"></v-icon>
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/components/project/ProjectMiniCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<v-card>
<v-card variant="flat">
<v-skeleton-loader :loading="isSubjectLoading" type="article">
<v-card-item>
<v-card-title>
Expand Down Expand Up @@ -38,4 +38,10 @@ const { data: subject, isLoading: isSubjectLoading } = useSubjectQuery(
);
</script>

<style scoped></style>
<style scoped>
.v-card,
.v-skeleton-loader {
width: 100%;
background-color: rgb(var(--v-theme-secondary));
}
</style>
8 changes: 6 additions & 2 deletions frontend/src/components/project/ProjectSideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
{{ $t("project.group", { number: group!.id }) }}
</v-btn>
</router-link>
<router-link v-else-if="!isSoloProject && !isTeacher" :to="`/projects/${project!.id}/groups`">
<router-link v-else-if="!isSoloProject && !isTeacher" :to="`/project/${project!.id}/groups`">
<v-btn class="group-button" prepend-icon="mdi-account-group">
{{ $t("project.group_button") }}
</v-btn>
</router-link>
<NeedHelpButton v-if="!isTeacher" class="group-button" :email="subject!.email"></NeedHelpButton>
<NeedHelpButton
v-if="!isTeacher && subject!.email"
class="group-button"
:email="subject!.email"
></NeedHelpButton>
<router-link v-if="isTeacher" :to="`/projects/${project!.id}/edit`">
<v-btn class="group-button" prepend-icon="mdi-pencil">
{{ $t("project.edit") }}
Expand Down
44 changes: 15 additions & 29 deletions frontend/src/components/project/submit/SubmitCard.vue
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
<template>
<v-card>
<v-card-item>
<v-card-title>{{ $t("submit.submit_title") }}</v-card-title>
</v-card-item>
<v-card variant="flat">
<h1>{{ $t("submit.submit_title") }}</h1>
<h1 v-if="isError">Error</h1>
<v-container v-else class="card-container">
<v-row>
<v-col>
<v-skeleton-loader :loading="isLoading" type="article">
<ProjectMiniCard :project="project!" />
</v-skeleton-loader>
</v-col>
<v-spacer />
<v-spacer />
</v-row>
<v-row>
<v-col>
<h1>
{{ $t("submit.add_files") }}
</h1>
</v-col>
</v-row>
<v-row>
<v-col>
<SubmitForm :projectId="projectId" />
</v-col>
</v-row>
</v-container>
<v-skeleton-loader :loading="isLoading" type="article">
<ProjectMiniCard :project="project!" class="minicard" />
</v-skeleton-loader>
<h2>
{{ $t("submit.files") }}
</h2>
<SubmitForm :projectId="projectId" class="submitform" />
</v-card>
</template>

Expand All @@ -46,7 +28,11 @@ const { data: project, isLoading, isError } = useProjectQuery(projectId);
</script>

<style scoped>
.card-container {
background-color: var(--gray-8);
.minicard {
margin: 15px 0 30px 0;
width: 500px;
}
.submitform {
margin-top: 15px;
}
</style>
34 changes: 12 additions & 22 deletions frontend/src/components/project/submit/SubmitForm.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
<template>
<v-form validate-on="submit lazy" @submit.prevent="formOnSubmit">
<v-container>
<v-row>
<v-col>
<FilesInput v-model="inputFiles" />
</v-col>
</v-row>
<v-row>
<v-col>
<v-textarea
:label="$t('submit.remarks')"
name="remarks"
v-model="remarksInput"
/>
</v-col>
</v-row>
<v-row>
<v-col>
<v-btn type="submit">{{ $t("submit.submit_button") }}</v-btn>
</v-col>
</v-row>
</v-container>
<FilesInput v-model="inputFiles" />
<v-textarea :label="$t('submit.remarks')" name="remarks" v-model="remarksInput" />
<v-btn variant="flat" type="submit">{{ $t("submit.submit_button") }}</v-btn>
</v-form>
</template>

Expand Down Expand Up @@ -61,4 +43,12 @@ async function formOnSubmit(event: SubmitEvent) {
}
</script>

<style scoped></style>
<style scoped>
.v-btn {
background-color: rgb(var(--v-theme-secondary));
}
.v-textarea {
margin-top: 30px;
}
</style>
16 changes: 15 additions & 1 deletion frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
submit_title: "Submit solution",
submit_button: "Submit",
remarks: "Remarks",
add_files: "Add files",
files: "Files",
add_files_button: "Add files",
no_files_added: "No files have been added yet.",
no_files_warning: "Please add at least one file to submit a solution.",
Expand Down Expand Up @@ -77,6 +77,7 @@ export default {
},
admin: {
users: "Users",
search: "Search",
userTable: {
name: "Name",
uid: "UGent ID",
Expand Down Expand Up @@ -105,4 +106,17 @@ export default {
subjects: {
title: "My Subjects",
},
group: {
not_found: "Group not found",
not_found2: "No groups found",
groups: "Groups:",
members: "Members:",
actions: "Actions:",
no_members_found: "No members found.",
remove: "Remove",
join_group: "Join group",
leave_group: "Leave group",
remove_group: "Delete group",
create_group: "New group",
},
};
Loading

0 comments on commit 8004cfa

Please sign in to comment.