feat: edit assignments
This commit is contained in:
		
							parent
							
								
									6c28c0fc3d
								
							
						
					
					
						commit
						20173169b7
					
				
					 2 changed files with 331 additions and 170 deletions
				
			
		|  | @ -18,12 +18,22 @@ | ||||||
|     font-size: 1.1rem; |     font-size: 1.1rem; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .top-right-btn { | .top-buttons-wrapper { | ||||||
|     position: absolute; |     display: flex; | ||||||
|     right: 2%; |     justify-content: space-between; | ||||||
|     color: red; |     align-items: center; | ||||||
|  |     padding: 1rem; | ||||||
|  |     position: relative; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | .right-buttons { | ||||||
|  |     display: flex; | ||||||
|  |     gap: 0.5rem; | ||||||
|  |     align-items: center; | ||||||
|  |     color: #0e6942 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| .group-section { | .group-section { | ||||||
|     margin-top: 2rem; |     margin-top: 2rem; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,12 +4,12 @@ | ||||||
|     import { useAssignmentQuery, useDeleteAssignmentMutation } from "@/queries/assignments.ts"; |     import { useAssignmentQuery, useDeleteAssignmentMutation } from "@/queries/assignments.ts"; | ||||||
|     import UsingQueryResult from "@/components/UsingQueryResult.vue"; |     import UsingQueryResult from "@/components/UsingQueryResult.vue"; | ||||||
|     import { useGroupsQuery } from "@/queries/groups.ts"; |     import { useGroupsQuery } from "@/queries/groups.ts"; | ||||||
|     import { useGetLearningPathQuery } from "@/queries/learning-paths.ts"; |     import { useGetAllLearningPaths, useGetLearningPathQuery } from "@/queries/learning-paths.ts"; | ||||||
|     import type { Language } from "@/data-objects/language.ts"; |     import type { Language } from "@/data-objects/language.ts"; | ||||||
|     import type { AssignmentResponse } from "@/controllers/assignments.ts"; |     import type { AssignmentResponse } from "@/controllers/assignments.ts"; | ||||||
|     import type { GroupDTO } from "@dwengo-1/common/interfaces/group"; |     import type { GroupDTO } from "@dwengo-1/common/interfaces/group"; | ||||||
| import type { AssignmentDTO } from "@dwengo-1/common/interfaces/assignment"; |     import type { StudentDTO } from "@dwengo-1/common/interfaces/student"; | ||||||
| import type { StudentDTO } from "@dwengo-1/common/interfaces/student"; |     import type { LearningPath } from "@/data-objects/learning-paths/learning-path"; | ||||||
| 
 | 
 | ||||||
|     const props = defineProps<{ |     const props = defineProps<{ | ||||||
|         classId: string; |         classId: string; | ||||||
|  | @ -21,19 +21,43 @@ import type { StudentDTO } from "@dwengo-1/common/interfaces/student"; | ||||||
|         ) => { groupProgressMap: Map<number, number> }; |         ) => { groupProgressMap: Map<number, number> }; | ||||||
|     }>(); |     }>(); | ||||||
| 
 | 
 | ||||||
|  |     const isEditing = ref(false); | ||||||
|  | 
 | ||||||
|     const { t, locale } = useI18n(); |     const { t, locale } = useI18n(); | ||||||
|     const language = computed(() => locale.value); |     const language = computed(() => locale.value); | ||||||
|     const groups = ref(); |     const groups = ref(); | ||||||
|     const learningPath = ref(); |     const learningPath = ref(); | ||||||
|  |     const editingLearningPath = ref(learningPath); | ||||||
|  |     const description = ref(""); | ||||||
| 
 | 
 | ||||||
|     const assignmentQueryResult = useAssignmentQuery(props.classId, props.assignmentId); |     const assignmentQueryResult = useAssignmentQuery(props.classId, props.assignmentId); | ||||||
|     learningPath.value = assignmentQueryResult.data.value?.assignment?.learningPath; |     learningPath.value = assignmentQueryResult.data.value?.assignment?.learningPath; | ||||||
|  |     const learningPathsQueryResults = useGetAllLearningPaths(language); | ||||||
|  | 
 | ||||||
|     // Get learning path object |     // Get learning path object | ||||||
|     const lpQueryResult = useGetLearningPathQuery( |     const lpQueryResult = useGetLearningPathQuery( | ||||||
|         computed(() => assignmentQueryResult.data.value?.assignment?.learningPath ?? ""), |         computed(() => assignmentQueryResult.data.value?.assignment?.learningPath ?? ""), | ||||||
|         computed(() => language.value as Language), |         computed(() => language.value as Language), | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|  |     const learningPathRules = [ | ||||||
|  |         (value: { hruid: string; title: string }): string | boolean => { | ||||||
|  |             if (value && value.hruid) { | ||||||
|  |                 return true; // Valid if hruid is present | ||||||
|  |             } | ||||||
|  |             return "You must select a learning path."; | ||||||
|  |         }, | ||||||
|  |     ]; | ||||||
|  | 
 | ||||||
|  |     const descriptionRules = [ | ||||||
|  |         (value: string): string | boolean => { | ||||||
|  |             if (!value || value.trim() === "") { | ||||||
|  |                 return "Description cannot be empty."; | ||||||
|  |             } | ||||||
|  |             return true; | ||||||
|  |         }, | ||||||
|  |     ]; | ||||||
|  | 
 | ||||||
|     // Get all the groups withing the assignment |     // Get all the groups withing the assignment | ||||||
|     const groupsQueryResult = useGroupsQuery(props.classId, props.assignmentId, true); |     const groupsQueryResult = useGroupsQuery(props.classId, props.assignmentId, true); | ||||||
|     groups.value = groupsQueryResult.data.value?.groups; |     groups.value = groupsQueryResult.data.value?.groups; | ||||||
|  | @ -84,6 +108,13 @@ Const {groupProgressMap} = props.useGroupsWithProgress( | ||||||
|             }, |             }, | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     function saveChanges() { | ||||||
|  |         //TODO | ||||||
|  |         const new_learningpath = editingLearningPath.value; | ||||||
|  |         const new_description = description.value; | ||||||
|  |         isEditing.value = false; | ||||||
|  |     } | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <template> | <template> | ||||||
|  | @ -92,14 +123,26 @@ Const {groupProgressMap} = props.useGroupsWithProgress( | ||||||
|             :query-result="assignmentQueryResult" |             :query-result="assignmentQueryResult" | ||||||
|             v-slot="assignmentResponse: { data: AssignmentResponse }" |             v-slot="assignmentResponse: { data: AssignmentResponse }" | ||||||
|         > |         > | ||||||
|         <v-container fluid class="ma-4"> |             <v-container | ||||||
|             <v-row no-gutters class="custom-breakpoint"> |                 fluid | ||||||
|                 <v-col cols="12" sm="6" md="6" class="responsive-col"> |                 class="ma-4" | ||||||
|  |             > | ||||||
|  |                 <v-row | ||||||
|  |                     no-gutters | ||||||
|  |                     class="custom-breakpoint" | ||||||
|  |                 > | ||||||
|  |                     <v-col | ||||||
|  |                         cols="12" | ||||||
|  |                         sm="6" | ||||||
|  |                         md="6" | ||||||
|  |                         class="responsive-col" | ||||||
|  |                     > | ||||||
|                         <v-card |                         <v-card | ||||||
|                             v-if="assignmentResponse" |                             v-if="assignmentResponse" | ||||||
|                             class="assignment-card" |                             class="assignment-card" | ||||||
|                         > |                         > | ||||||
|                             <div class="top-buttons"> |                             <div class="top-buttons"> | ||||||
|  |                                 <div class="top-buttons-wrapper"> | ||||||
|                                     <v-btn |                                     <v-btn | ||||||
|                                         icon |                                         icon | ||||||
|                                         variant="text" |                                         variant="text" | ||||||
|  | @ -108,18 +151,63 @@ Const {groupProgressMap} = props.useGroupsWithProgress( | ||||||
|                                     > |                                     > | ||||||
|                                         <v-icon>mdi-arrow-left</v-icon> |                                         <v-icon>mdi-arrow-left</v-icon> | ||||||
|                                     </v-btn> |                                     </v-btn> | ||||||
|  |                                     <div class="right-buttons"> | ||||||
|  |                                         <v-btn | ||||||
|  |                                             v-if="!isEditing" | ||||||
|  |                                             icon | ||||||
|  |                                             variant="text" | ||||||
|  |                                             class="top_next_to_right_button" | ||||||
|  |                                             @click=" | ||||||
|  |                                                 () => { | ||||||
|  |                                                     isEditing = true; | ||||||
|  |                                                     description = assignmentResponse.data.assignment.description; | ||||||
|  |                                                 } | ||||||
|  |                                             " | ||||||
|  |                                         > | ||||||
|  |                                             <v-icon>mdi-pencil</v-icon> | ||||||
|  |                                         </v-btn> | ||||||
|  |                                         <v-btn | ||||||
|  |                                             v-else | ||||||
|  |                                             variant="text" | ||||||
|  |                                             class="top-right-btn" | ||||||
|  |                                             @click="() => {isEditing = false; editingLearningPath=learningPath}" | ||||||
|  |                                             >{{ t("cancel") }}</v-btn | ||||||
|  |                                         > | ||||||
| 
 | 
 | ||||||
|                                         <v-btn |                                         <v-btn | ||||||
|  |                                             v-if="!isEditing" | ||||||
|                                             icon |                                             icon | ||||||
|                                             variant="text" |                                             variant="text" | ||||||
|                                             class="top-right-btn" |                                             class="top-right-btn" | ||||||
|                                 @click="deleteAssignment(assignmentResponse.data.assignment.id, assignmentResponse.data.assignment.within)" |                                             @click=" | ||||||
|  |                                                 deleteAssignment( | ||||||
|  |                                                     assignmentResponse.data.assignment.id, | ||||||
|  |                                                     assignmentResponse.data.assignment.within, | ||||||
|  |                                                 ) | ||||||
|  |                                             " | ||||||
|                                         > |                                         > | ||||||
|                                             <v-icon>mdi-delete</v-icon> |                                             <v-icon>mdi-delete</v-icon> | ||||||
|                                         </v-btn> |                                         </v-btn> | ||||||
|  |                                         <v-btn | ||||||
|  |                                             v-else | ||||||
|  |                                             icon | ||||||
|  |                                             variant="text" | ||||||
|  |                                             class="top_next_to_right_button" | ||||||
|  |                                             @click="saveChanges" | ||||||
|  |                                         > | ||||||
|  |                                             <v-icon>mdi-content-save-edit-outline</v-icon> | ||||||
|  |                                         </v-btn> | ||||||
|                                     </div> |                                     </div> | ||||||
|                         <v-card-title class="text-h4 assignmentTopTitle">{{ assignmentResponse.data.assignment.title }}</v-card-title> |                                 </div> | ||||||
|                         <v-card-subtitle class="subtitle-section"> |                             </div> | ||||||
|  | 
 | ||||||
|  |                             <v-card-title class="text-h4 assignmentTopTitle">{{ | ||||||
|  |                                 assignmentResponse.data.assignment.title | ||||||
|  |                             }}</v-card-title> | ||||||
|  |                             <v-card-subtitle | ||||||
|  |                                 v-if="!isEditing" | ||||||
|  |                                 class="subtitle-section" | ||||||
|  |                             > | ||||||
|                                 <using-query-result |                                 <using-query-result | ||||||
|                                     :query-result="lpQueryResult" |                                     :query-result="lpQueryResult" | ||||||
|                                     v-slot="{ data: lpData }" |                                     v-slot="{ data: lpData }" | ||||||
|  | @ -134,10 +222,50 @@ Const {groupProgressMap} = props.useGroupsWithProgress( | ||||||
|                                     </v-btn> |                                     </v-btn> | ||||||
|                                 </using-query-result> |                                 </using-query-result> | ||||||
|                             </v-card-subtitle> |                             </v-card-subtitle> | ||||||
|  |                             <using-query-result | ||||||
|  |                                 v-else | ||||||
|  |                                 :query-result="learningPathsQueryResults" | ||||||
|  |                                 v-slot="{ data }: { data: LearningPath[] }" | ||||||
|  |                             > | ||||||
|  |                                 <v-card-text> | ||||||
|  |                                     <v-combobox | ||||||
|  |                                         v-model="editingLearningPath" | ||||||
|  |                                         :items="data" | ||||||
|  |                                         :label="t('choose-lp')" | ||||||
|  |                                         :rules="learningPathRules" | ||||||
|  |                                         variant="outlined" | ||||||
|  |                                         clearable | ||||||
|  |                                         hide-details | ||||||
|  |                                         density="compact" | ||||||
|  |                                         append-inner-icon="mdi-magnify" | ||||||
|  |                                         item-title="title" | ||||||
|  |                                         item-value="hruid" | ||||||
|  |                                         required | ||||||
|  |                                         :filter=" | ||||||
|  |                                             (item, query: string) => | ||||||
|  |                                                 item.title.toLowerCase().includes(query.toLowerCase()) | ||||||
|  |                                         " | ||||||
|  |                                     ></v-combobox> | ||||||
|  |                                 </v-card-text> | ||||||
|  |                             </using-query-result> | ||||||
| 
 | 
 | ||||||
|                         <v-card-text class="description"> |                             <v-card-text | ||||||
|  |                                 v-if="!isEditing" | ||||||
|  |                                 class="description" | ||||||
|  |                             > | ||||||
|                                 {{ assignmentResponse.data.assignment.description }} |                                 {{ assignmentResponse.data.assignment.description }} | ||||||
|                             </v-card-text> |                             </v-card-text> | ||||||
|  |                             <v-card-text v-else> | ||||||
|  |                                 <v-textarea | ||||||
|  |                                     v-model="description" | ||||||
|  |                                     :label="t('description')" | ||||||
|  |                                     variant="outlined" | ||||||
|  |                                     density="compact" | ||||||
|  |                                     auto-grow | ||||||
|  |                                     rows="3" | ||||||
|  |                                     :rules="descriptionRules" | ||||||
|  |                                 ></v-textarea> | ||||||
|  |                             </v-card-text> | ||||||
| 
 | 
 | ||||||
|                             <v-card-text class="group-section"> |                             <v-card-text class="group-section"> | ||||||
|                                 <h3>{{ t("groups") }}</h3> |                                 <h3>{{ t("groups") }}</h3> | ||||||
|  | @ -226,7 +354,12 @@ Const {groupProgressMap} = props.useGroupsWithProgress( | ||||||
|                         --> |                         --> | ||||||
|                         </v-card> |                         </v-card> | ||||||
|                     </v-col> |                     </v-col> | ||||||
|                 <v-col cols="12" sm="6" md="6" class="responsive-col"> |                     <v-col | ||||||
|  |                         cols="12" | ||||||
|  |                         sm="6" | ||||||
|  |                         md="6" | ||||||
|  |                         class="responsive-col" | ||||||
|  |                     > | ||||||
|                         <v-table class="table"> |                         <v-table class="table"> | ||||||
|                             <thead> |                             <thead> | ||||||
|                                 <tr> |                                 <tr> | ||||||
|  | @ -236,30 +369,48 @@ Const {groupProgressMap} = props.useGroupsWithProgress( | ||||||
|                                     </th> |                                     </th> | ||||||
|                                     <th class="header">{{ t("Members") }}</th> |                                     <th class="header">{{ t("Members") }}</th> | ||||||
|                                     <th class="header"> |                                     <th class="header"> | ||||||
|                                     <v-btn :to="`/assignment/${assignmentResponse.data.assignment.within}/${assignmentResponse.data.assignment.id}`" variant="text"> |                                         <v-btn | ||||||
|  |                                             :to="`/assignment/${assignmentResponse.data.assignment.within}/${assignmentResponse.data.assignment.id}`" | ||||||
|  |                                             variant="text" | ||||||
|  |                                         > | ||||||
|                                             <v-icon> mdi-pencil </v-icon> |                                             <v-icon> mdi-pencil </v-icon> | ||||||
|                                         </v-btn> |                                         </v-btn> | ||||||
|                                     </th> |                                     </th> | ||||||
|                                 </tr> |                                 </tr> | ||||||
|                             </thead> |                             </thead> | ||||||
|                             <tbody> |                             <tbody> | ||||||
|                             <tr v-for="g in assignmentResponse.data.assignment.groups as GroupDTO[]" :key="g.groupNumber"> |                                 <tr | ||||||
|  |                                     v-for="g in assignmentResponse.data.assignment.groups as GroupDTO[]" | ||||||
|  |                                     :key="g.groupNumber" | ||||||
|  |                                 > | ||||||
|                                     <td> |                                     <td> | ||||||
|                                     <v-btn :to="`/assignment/${assignmentResponse.data.assignment.within}/${assignmentResponse.data.assignment.id}`" variant="text"> |                                         <v-btn | ||||||
|  |                                             :to="`/assignment/${assignmentResponse.data.assignment.within}/${assignmentResponse.data.assignment.id}`" | ||||||
|  |                                             variant="text" | ||||||
|  |                                         > | ||||||
|                                             {{ g.groupNumber }} |                                             {{ g.groupNumber }} | ||||||
|                                             <v-icon end> mdi-menu-right </v-icon> |                                             <v-icon end> mdi-menu-right </v-icon> | ||||||
|                                         </v-btn> |                                         </v-btn> | ||||||
|                                     </td> |                                     </td> | ||||||
|                                     <td> |                                     <td> | ||||||
|                                     <v-progress-linear :model-value="0" color="blue-grey" height="25"> |                                         <v-progress-linear | ||||||
|  |                                             :model-value="0" | ||||||
|  |                                             color="blue-grey" | ||||||
|  |                                             height="25" | ||||||
|  |                                         > | ||||||
|                                             <template v-slot:default="{ value }"> |                                             <template v-slot:default="{ value }"> | ||||||
|                                                 <strong>{{ Math.ceil(value) }}%</strong> |                                                 <strong>{{ Math.ceil(value) }}%</strong> | ||||||
|                                             </template> |                                             </template> | ||||||
|                                         </v-progress-linear> |                                         </v-progress-linear> | ||||||
|                                     </td> |                                     </td> | ||||||
|                                 <td>{{ (g.members! as StudentDTO[]).map(member => member.username).join(', ') }}</td> |  | ||||||
|                                     <td> |                                     <td> | ||||||
|                                     <v-btn :to="`/assignment/${assignmentResponse.data.assignment.within}/${assignmentResponse.data.assignment.id}`" variant="text"> |                                         {{ (g.members! as StudentDTO[]).map((member) => member.username).join(", ") }} | ||||||
|  |                                     </td> | ||||||
|  |                                     <td> | ||||||
|  |                                         <v-btn | ||||||
|  |                                             :to="`/assignment/${assignmentResponse.data.assignment.within}/${assignmentResponse.data.assignment.id}`" | ||||||
|  |                                             variant="text" | ||||||
|  |                                         > | ||||||
|                                             <v-icon color="red"> mdi-delete </v-icon> |                                             <v-icon color="red"> mdi-delete </v-icon> | ||||||
|                                         </v-btn> |                                         </v-btn> | ||||||
|                                     </td> |                                     </td> | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 laurejablonski
						laurejablonski