Merge pull request #255 from SELab-2/feat/deadline

feat: Assignment deadline
This commit is contained in:
Joyelle Ndagijimana 2025-05-13 09:14:22 +02:00 committed by GitHub
commit 8bad3b3dff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 213 additions and 5928 deletions

View file

@ -26,6 +26,9 @@ export class Assignment {
@Property({ type: 'string' }) @Property({ type: 'string' })
learningPathHruid!: string; learningPathHruid!: string;
@Property({ type: 'datetime', nullable: true })
deadline?: Date;
@Enum({ @Enum({
items: () => Language, items: () => Language,
}) })

View file

@ -20,6 +20,7 @@ export function mapToAssignmentDTO(assignment: Assignment): AssignmentDTO {
description: assignment.description, description: assignment.description,
learningPath: assignment.learningPathHruid, learningPath: assignment.learningPathHruid,
language: assignment.learningPathLanguage, language: assignment.learningPathLanguage,
deadline: assignment.deadline ?? new Date(),
groups: assignment.groups.map((group) => mapToGroupDTO(group, assignment.within)), groups: assignment.groups.map((group) => mapToGroupDTO(group, assignment.within)),
}; };
} }
@ -31,6 +32,7 @@ export function mapToAssignment(assignmentData: AssignmentDTO, cls: Class): Assi
description: assignmentData.description, description: assignmentData.description,
learningPathHruid: assignmentData.learningPath, learningPathHruid: assignmentData.learningPath,
learningPathLanguage: languageMap[assignmentData.language], learningPathLanguage: languageMap[assignmentData.language],
deadline: assignmentData.deadline,
groups: [], groups: [],
}); });
} }

View file

@ -6,13 +6,20 @@ import { testLearningPathWithConditions } from '../content/learning-paths.testda
import { getClassWithTestleerlingAndTestleerkracht } from '../classes/classes.testdata'; import { getClassWithTestleerlingAndTestleerkracht } from '../classes/classes.testdata';
export function makeTestAssignemnts(em: EntityManager, classes: Class[]): Assignment[] { export function makeTestAssignemnts(em: EntityManager, classes: Class[]): Assignment[] {
const futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
const pastDate = new Date();
pastDate.setDate(pastDate.getDate() - 7);
const today = new Date();
today.setHours(23, 59);
assignment01 = em.create(Assignment, { assignment01 = em.create(Assignment, {
id: 21000, id: 21000,
within: classes[0], within: classes[0],
title: 'dire straits', title: 'dire straits',
description: 'reading', description: 'reading',
learningPathHruid: 'id02', learningPathHruid: 'un_ai',
learningPathLanguage: Language.English, learningPathLanguage: Language.English,
deadline: today,
groups: [], groups: [],
}); });
@ -23,6 +30,7 @@ export function makeTestAssignemnts(em: EntityManager, classes: Class[]): Assign
description: 'reading', description: 'reading',
learningPathHruid: 'id01', learningPathHruid: 'id01',
learningPathLanguage: Language.English, learningPathLanguage: Language.English,
deadline: futureDate,
groups: [], groups: [],
}); });
@ -33,6 +41,7 @@ export function makeTestAssignemnts(em: EntityManager, classes: Class[]): Assign
description: 'will be deleted', description: 'will be deleted',
learningPathHruid: 'id02', learningPathHruid: 'id02',
learningPathLanguage: Language.English, learningPathLanguage: Language.English,
deadline: pastDate,
groups: [], groups: [],
}); });
@ -43,6 +52,7 @@ export function makeTestAssignemnts(em: EntityManager, classes: Class[]): Assign
description: 'with a description', description: 'with a description',
learningPathHruid: 'id01', learningPathHruid: 'id01',
learningPathLanguage: Language.English, learningPathLanguage: Language.English,
deadline: pastDate,
groups: [], groups: [],
}); });
@ -53,6 +63,7 @@ export function makeTestAssignemnts(em: EntityManager, classes: Class[]): Assign
description: 'You have to do the testing learning path with a condition.', description: 'You have to do the testing learning path with a condition.',
learningPathHruid: testLearningPathWithConditions.hruid, learningPathHruid: testLearningPathWithConditions.hruid,
learningPathLanguage: testLearningPathWithConditions.language as Language, learningPathLanguage: testLearningPathWithConditions.language as Language,
deadline: futureDate,
groups: [], groups: [],
}); });

View file

@ -7,6 +7,7 @@ export interface AssignmentDTO {
description: string; description: string;
learningPath: string; learningPath: string;
language: string; language: string;
deadline: Date;
groups: GroupDTO[] | string[][]; groups: GroupDTO[] | string[][];
} }

View file

@ -1,49 +1,30 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed } from "vue"; import { ref, watch } from "vue";
import { deadlineRules } from "@/utils/assignment-rules.ts"; import { deadlineRules } from "@/utils/assignment-rules.ts";
const date = ref(""); const emit = defineEmits<(e: "update:deadline", value: Date) => void>();
const time = ref("23:59");
const emit = defineEmits(["update:deadline"]);
const formattedDeadline = computed(() => { const datetime = ref("");
if (!date.value || !time.value) return "";
return `${date.value} ${time.value}`; // Watch the datetime value and emit the update
watch(datetime, (val) => {
const newDate = new Date(val);
if (!isNaN(newDate.getTime())) {
emit("update:deadline", newDate);
}
}); });
function updateDeadline(): void {
if (date.value && time.value) {
emit("update:deadline", formattedDeadline.value);
}
}
</script> </script>
<template> <template>
<div>
<v-card-text> <v-card-text>
<v-text-field <v-text-field
v-model="date" v-model="datetime"
label="Select Deadline Date" type="datetime-local"
type="date" label="Select Deadline"
variant="outlined" variant="outlined"
density="compact" density="compact"
:rules="deadlineRules" :rules="deadlineRules"
required required
@update:modelValue="updateDeadline" />
></v-text-field>
</v-card-text> </v-card-text>
<v-card-text>
<v-text-field
v-model="time"
label="Select Deadline Time"
type="time"
variant="outlined"
density="compact"
@update:modelValue="updateDeadline"
></v-text-field>
</v-card-text>
</div>
</template> </template>
<style scoped></style>

View file

@ -133,5 +133,7 @@
"see-submission": "Einsendung anzeigen", "see-submission": "Einsendung anzeigen",
"view-submissions": "Einsendungen anzeigen", "view-submissions": "Einsendungen anzeigen",
"valid-username": "Bitte geben Sie einen gültigen Benutzernamen ein", "valid-username": "Bitte geben Sie einen gültigen Benutzernamen ein",
"creationFailed": "Erstellung fehlgeschlagen, bitte versuchen Sie es erneut" "creationFailed": "Erstellung fehlgeschlagen, bitte versuchen Sie es erneut",
"no-assignments": "Derzeit gibt es keine Zuweisungen.",
"deadline": "deadline"
} }

View file

@ -133,5 +133,7 @@
"see-submission": "view submission", "see-submission": "view submission",
"view-submissions": "view submissions", "view-submissions": "view submissions",
"valid-username": "please enter a valid username", "valid-username": "please enter a valid username",
"creationFailed": "creation failed, please try again" "creationFailed": "creation failed, please try again",
"no-assignments": "There are currently no assignments.",
"deadline": "deadline"
} }

View file

@ -134,5 +134,7 @@
"see-submission": "voir la soumission", "see-submission": "voir la soumission",
"view-submissions": "voir les soumissions", "view-submissions": "voir les soumissions",
"valid-username": "veuillez entrer un nom d'utilisateur valide", "valid-username": "veuillez entrer un nom d'utilisateur valide",
"creationFailed": "échec de la création, veuillez réessayer" "creationFailed": "échec de la création, veuillez réessayer",
"no-assignments": "Il n'y a actuellement aucun travail.",
"deadline": "délai"
} }

View file

@ -133,5 +133,7 @@
"see-submission": "inzending bekijken", "see-submission": "inzending bekijken",
"view-submissions": "inzendingen bekijken", "view-submissions": "inzendingen bekijken",
"valid-username": "voer een geldige gebruikersnaam in", "valid-username": "voer een geldige gebruikersnaam in",
"creationFailed": "aanmaak mislukt, probeer het opnieuw" "creationFailed": "aanmaak mislukt, probeer het opnieuw",
"no-assignments": "Er zijn momenteel geen opdrachten.",
"deadline": "deadline"
} }

View file

@ -48,7 +48,7 @@
// Disable combobox when learningPath prop is passed // Disable combobox when learningPath prop is passed
const lpIsSelected = route.query.hruid !== undefined; const lpIsSelected = route.query.hruid !== undefined;
const deadline = ref(null); const deadline = ref(new Date());
const description = ref(""); const description = ref("");
const groups = ref<string[][]>([]); const groups = ref<string[][]>([]);
@ -86,6 +86,7 @@
title: assignmentTitle.value, title: assignmentTitle.value,
description: description.value, description: description.value,
learningPath: lp || "", learningPath: lp || "",
deadline: deadline.value,
language: language.value, language: language.value,
groups: groups.value, groups: groups.value,
}; };

View file

@ -11,7 +11,7 @@
import { useDeleteAssignmentMutation } from "@/queries/assignments.ts"; import { useDeleteAssignmentMutation } from "@/queries/assignments.ts";
import "../../assets/common.css"; import "../../assets/common.css";
const { t } = useI18n(); const { t, locale } = useI18n();
const router = useRouter(); const router = useRouter();
const role = ref(auth.authState.activeRole); const role = ref(auth.authState.activeRole);
@ -28,13 +28,13 @@
classesQueryResults = useStudentClassesQuery(username, true); classesQueryResults = useStudentClassesQuery(username, true);
} }
//TODO: remove later
const classController = new ClassController(); const classController = new ClassController();
//TODO: replace by query that fetches all user's assignment const assignments = asyncComputed(
const assignments = asyncComputed(async () => { async () => {
const classes = classesQueryResults?.data?.value?.classes; const classes = classesQueryResults?.data?.value?.classes;
if (!classes) return []; if (!classes) return [];
const result = await Promise.all( const result = await Promise.all(
(classes as ClassDTO[]).map(async (cls) => { (classes as ClassDTO[]).map(async (cls) => {
const { assignments } = await classController.getAssignments(cls.id); const { assignments } = await classController.getAssignments(cls.id);
@ -45,13 +45,30 @@
description: a.description, description: a.description,
learningPath: a.learningPath, learningPath: a.learningPath,
language: a.language, language: a.language,
deadline: a.deadline,
groups: a.groups, groups: a.groups,
})); }));
}), }),
); );
return result.flat(); // Order the assignments by deadline
}, []); return result.flat().sort((a, b) => {
const now = Date.now();
const aTime = new Date(a.deadline).getTime();
const bTime = new Date(b.deadline).getTime();
const aIsPast = aTime < now;
const bIsPast = bTime < now;
if (aIsPast && !bIsPast) return 1;
if (!aIsPast && bIsPast) return -1;
return aTime - bTime;
});
},
[],
{ evaluating: true },
);
async function goToCreateAssignment(): Promise<void> { async function goToCreateAssignment(): Promise<void> {
await router.push("/assignment/create"); await router.push("/assignment/create");
@ -73,6 +90,35 @@
mutate({ cid: clsId, an: num }); mutate({ cid: clsId, an: num });
} }
function formatDate(date?: string | Date): string {
if (!date) return "";
const d = new Date(date);
// Choose locale based on selected language
const currentLocale = locale.value;
return d.toLocaleDateString(currentLocale, {
weekday: "short",
day: "2-digit",
month: "long",
year: "numeric",
hour: "numeric",
minute: "2-digit",
});
}
function getDeadlineClass(deadline?: string | Date): string {
if (!deadline) return "";
const date = new Date(deadline);
const now = new Date();
const in24Hours = new Date(now.getTime() + 24 * 60 * 60 * 1000);
if (date.getTime() < now.getTime()) return "deadline-passed";
if (date.getTime() <= in24Hours.getTime()) return "deadline-in24hours";
return "deadline-upcoming";
}
onMounted(async () => { onMounted(async () => {
const user = await auth.loadUser(); const user = await auth.loadUser();
username.value = user?.profile?.preferred_username ?? ""; username.value = user?.profile?.preferred_username ?? "";
@ -108,6 +154,13 @@
{{ assignment.class.displayName }} {{ assignment.class.displayName }}
</span> </span>
</div> </div>
<div
class="assignment-deadline"
:class="getDeadlineClass(assignment.deadline)"
>
{{ t("deadline") }}:
<span>{{ formatDate(assignment.deadline) }}</span>
</div>
</div> </div>
<div class="spacer"></div> <div class="spacer"></div>
@ -132,6 +185,13 @@
</v-card> </v-card>
</v-col> </v-col>
</v-row> </v-row>
<v-row v-if="assignments.length === 0">
<v-col cols="12">
<div class="no-assignments">
{{ t("no-assignments") }}
</div>
</v-col>
</v-row>
</v-container> </v-container>
</div> </div>
</template> </template>
@ -145,12 +205,27 @@
.center-btn { .center-btn {
display: block; display: block;
margin-left: auto; margin: 0 auto 2rem auto;
margin-right: auto; font-weight: 600;
background-color: #10ad61;
color: white;
transition: background-color 0.2s;
}
.center-btn:hover {
background-color: #0e6942;
} }
.assignment-card { .assignment-card {
padding: 1rem; padding: 1.25rem;
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
background-color: white;
transition:
transform 0.2s,
box-shadow 0.2s;
}
.assignment-card:hover {
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
} }
.top-content { .top-content {
@ -158,6 +233,35 @@
word-break: break-word; word-break: break-word;
} }
.assignment-title {
font-weight: 700;
font-size: 1.4rem;
color: #0e6942;
margin-bottom: 0.3rem;
}
.assignment-class,
.assignment-deadline {
font-size: 0.95rem;
color: #444;
margin-bottom: 0.2rem;
}
.class-name {
font-weight: 600;
color: #097180;
}
.assignment-deadline.deadline-passed {
color: #d32f2f;
font-weight: bold;
}
.assignment-deadline.deadline-in24hours {
color: #f57c00;
font-weight: bold;
}
.spacer { .spacer {
flex: 1; flex: 1;
} }
@ -165,24 +269,14 @@
.button-row { .button-row {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
gap: 0.5rem; gap: 0.75rem;
flex-wrap: wrap; flex-wrap: wrap;
} }
.assignment-title { .no-assignments {
font-weight: bold; text-align: center;
font-size: 1.5rem; font-size: 1.2rem;
margin-bottom: 0.1rem; color: #777;
word-break: break-word; padding: 3rem 0;
}
.assignment-class {
color: #666;
font-size: 0.95rem;
}
.class-name {
font-weight: 500;
color: #333;
} }
</style> </style>

5868
package-lock.json generated

File diff suppressed because it is too large Load diff