feat: kleine correctie in form component
This commit is contained in:
parent
36f7cfa4bd
commit
83b15a392d
3 changed files with 64 additions and 53 deletions
|
@ -4,37 +4,30 @@ import { useI18n } from 'vue-i18n';
|
|||
|
||||
const props = defineProps({
|
||||
students: Array, // All students
|
||||
availableClasses: Array, // Selected classes
|
||||
availableClass: Object, // Selected class
|
||||
groups: Array, // All groups
|
||||
});
|
||||
const emit = defineEmits(['groupCreated']);
|
||||
const { t } = useI18n();
|
||||
|
||||
const selectedClass = ref(null);
|
||||
const selectedStudents = ref([]);
|
||||
|
||||
// Filter students based on the selected class and exclude students already in a group
|
||||
const filteredStudents = computed(() => {
|
||||
if (selectedClass.value) {
|
||||
// Find the class based on selectedClass id
|
||||
const selected = props.availableClasses.find(cl => cl.id === selectedClass.value.id);
|
||||
if (selected) {
|
||||
// Get all students from the selected class
|
||||
const studentsInClass = selected.students.map(st => ({
|
||||
title: `${st.firstName} ${st.lastName}`,
|
||||
value: st.username,
|
||||
}));
|
||||
if (props.availableClass) {
|
||||
const studentsInClass = props.availableClass.students.map(st => ({
|
||||
title: `${st.firstName} ${st.lastName}`,
|
||||
value: st.username,
|
||||
}));
|
||||
|
||||
// Get the list of students already in any group
|
||||
const studentsInGroups = props.groups.flat();
|
||||
const studentsInGroups = props.groups.flat();
|
||||
|
||||
// Filter out students that are already in a group
|
||||
return studentsInClass.filter(student => !studentsInGroups.includes(student.value));
|
||||
}
|
||||
return studentsInClass.filter(student => !studentsInGroups.includes(student.value));
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
|
||||
const createGroup = () => {
|
||||
if (selectedStudents.value.length) {
|
||||
// Extract only usernames (student.value)
|
||||
|
@ -48,19 +41,6 @@ const createGroup = () => {
|
|||
|
||||
<template>
|
||||
<v-card-text>
|
||||
<v-combobox
|
||||
v-model="selectedClass"
|
||||
:items="props.availableClasses"
|
||||
item-title="displayName"
|
||||
item-value="id"
|
||||
:label="t('pick-class')"
|
||||
variant="outlined"
|
||||
clearable
|
||||
hide-details
|
||||
density="compact"
|
||||
class="mb-4"
|
||||
></v-combobox>
|
||||
|
||||
<v-combobox
|
||||
v-model="selectedStudents"
|
||||
:items="filteredStudents"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue