diff --git a/core/migrations/0017_remove_group_exam.py b/core/migrations/0017_remove_group_exam.py new file mode 100644 index 0000000000000000000000000000000000000000..eca14236faeb8d6b5f16d398c9c7415ba1a51c8e --- /dev/null +++ b/core/migrations/0017_remove_group_exam.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1.7 on 2022-05-18 08:08 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0016_auto_20210902_1140'), + ] + + operations = [ + migrations.RemoveField( + model_name='group', + name='exam', + ), + ] diff --git a/core/migrations/0018_group_exam.py b/core/migrations/0018_group_exam.py new file mode 100644 index 0000000000000000000000000000000000000000..b837ec6a51de34d441b4d9ffb5080a951e018389 --- /dev/null +++ b/core/migrations/0018_group_exam.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.7 on 2022-05-18 11:51 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0017_remove_group_exam'), + ] + + operations = [ + migrations.AddField( + model_name='group', + name='exam', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='groups', to='core.examtype'), + ), + ] diff --git a/frontend/src/components/student_list/StudentList.vue b/frontend/src/components/student_list/StudentList.vue index 40f8fcc45b0fc523faed16137ba9bcc3c21d2f85..9ec7f08ffdf8556116cf557c25298564da18a8b3 100644 --- a/frontend/src/components/student_list/StudentList.vue +++ b/frontend/src/components/student_list/StudentList.vue @@ -38,7 +38,7 @@ <v-divider /> <v-data-table :headers="headers" - :items="studentListItems" + :items="studentList" :search="search" sort-by="name" :loading="loading" @@ -65,6 +65,21 @@ <td> {{ item.name }} </td> + <v-select + v-model="item.exerciseGroups" + item-text="name" + item-value="pk" + :items="groups" + label="Set Groups" + single-line + return-object + multiple + chips + dense + hide-details + filled + @change="setExerciseGroups($event, item)" + /> <td> <v-tooltip top> <template #activator="{ on }"> @@ -141,7 +156,7 @@ import { mapActions, mapState } from 'vuex' import StudentListMenu from '@/components/student_list/StudentListMenu' import StudentListReverseMapper from '@/components/student_list/StudentListReverseMapper' -import { changeActiveForUser, fetchUser } from '@/api' +import { changeActiveForUser, fetchUser, setGroups, fetchUserGroups} from '@/api' import { getters } from '@/store/getters' import { Authentication } from '@/store/modules/authentication' import { ConfigModule } from '../../store/modules/config' @@ -160,13 +175,17 @@ export default { search: '', selectedGroup: null, userData: [], - userMap: null + userMap: null, + studentList: [] } }, computed: { ...mapState([ 'students' ]), + studentListItems (){ + return this.studentList + }, isReviever() { return Authentication.isReviewer }, @@ -193,6 +212,11 @@ export default { align: 'left', value: 'name', }, + { + text: 'Group', + align: 'left', + value: 'exerciseGroup' + }, { text: 'Has Access', align: 'left', @@ -206,32 +230,6 @@ export default { }, ] }, - studentListItems () { - if (!this.loading) { - let filteredStudents = this.students - if (this.selectedGroup !== null) { - filteredStudents = Object.values(filteredStudents).filter(student => { - let userGroups = this.userMap.get(student.userPk) - return userGroups.some(group => group.pk === this.selectedGroup.pk) - }) - } - return Object.values(filteredStudents).map(student => { - return { - pk: student.pk, - user: student.user, - userPk: student.userPk, - exam: student.exam, - name: student.name, - isActive: student.isActive, - matrikelNo: student.matrikelNo, - ...this.reduceArrToDict(student.submissions, 'type'), - total: this.sumSubmissionScores(student.submissions) - } - }) - } - - return [] - }, groups () { if (Authentication.isTutor) { return Authentication.state.user.exerciseGroups.filter( group => { @@ -250,13 +248,51 @@ export default { }, created () { this.getUserData() - this.getStudents().then(() => { this.loading = false }) + this.getStudents().then(() => { + this.loading = false + this.getStudentListItems() + }) const groups = Assignments.getGroups() }, methods: { ...mapActions([ 'getStudents' ]), + async userAccountGroups(student) { + const groups = await (await fetchUser(student.pk)).exerciseGroups + return groups + }, + getStudentListItems () { + if (!this.loading) { + let filteredStudents = this.students + if (this.selectedGroup !== null) { + filteredStudents = Object.values(filteredStudents).filter(student => { + let userGroups = this.userMap.get(student.userPk) + return userGroups.some(group => group.pk === this.selectedGroup.pk) + }) + } + + this.studentList = Object.values(filteredStudents).map(student => { + return { + pk: student.pk, + user: student.user, + userPk: student.userPk, + exam: student.exam, + name: student.name, + isActive: student.isActive, + exerciseGroup: [], + matrikelNo: student.matrikelNo, + ...this.reduceArrToDict(student.submissions, 'type'), + total: this.sumSubmissionScores(student.submissions) + } + }) + } + }, + setExerciseGroups (groups, student){ + console.log(student.pk) + console.log(fetchUser(student.pk).pk) + setGroups(fetchUser(student.pk).pk, groups) + }, reduceArrToDict (arr, key) { return arr.reduce((acc, curr) => { const keyInDict = curr[key]