Skip to content
Snippets Groups Projects
Commit 57327011 authored by Egi Brako's avatar Egi Brako Committed by Jakob Dieterle
Browse files

added dropdown list of exercise groups for students

parent cb20245c
No related branches found
No related tags found
1 merge request!291Resolve "Add dropdown to participantspage to set students groups"
# 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',
),
]
# 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'),
),
]
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<v-divider /> <v-divider />
<v-data-table <v-data-table
:headers="headers" :headers="headers"
:items="studentListItems" :items="studentList"
:search="search" :search="search"
sort-by="name" sort-by="name"
:loading="loading" :loading="loading"
...@@ -65,6 +65,21 @@ ...@@ -65,6 +65,21 @@
<td> <td>
{{ item.name }} {{ item.name }}
</td> </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> <td>
<v-tooltip top> <v-tooltip top>
<template #activator="{ on }"> <template #activator="{ on }">
...@@ -141,7 +156,7 @@ ...@@ -141,7 +156,7 @@
import { mapActions, mapState } from 'vuex' import { mapActions, mapState } from 'vuex'
import StudentListMenu from '@/components/student_list/StudentListMenu' import StudentListMenu from '@/components/student_list/StudentListMenu'
import StudentListReverseMapper from '@/components/student_list/StudentListReverseMapper' 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 { getters } from '@/store/getters'
import { Authentication } from '@/store/modules/authentication' import { Authentication } from '@/store/modules/authentication'
import { ConfigModule } from '../../store/modules/config' import { ConfigModule } from '../../store/modules/config'
...@@ -160,13 +175,17 @@ export default { ...@@ -160,13 +175,17 @@ export default {
search: '', search: '',
selectedGroup: null, selectedGroup: null,
userData: [], userData: [],
userMap: null userMap: null,
studentList: []
} }
}, },
computed: { computed: {
...mapState([ ...mapState([
'students' 'students'
]), ]),
studentListItems (){
return this.studentList
},
isReviever() { isReviever() {
return Authentication.isReviewer return Authentication.isReviewer
}, },
...@@ -193,6 +212,11 @@ export default { ...@@ -193,6 +212,11 @@ export default {
align: 'left', align: 'left',
value: 'name', value: 'name',
}, },
{
text: 'Group',
align: 'left',
value: 'exerciseGroup'
},
{ {
text: 'Has Access', text: 'Has Access',
align: 'left', align: 'left',
...@@ -206,32 +230,6 @@ export default { ...@@ -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 () { groups () {
if (Authentication.isTutor) { if (Authentication.isTutor) {
return Authentication.state.user.exerciseGroups.filter( group => { return Authentication.state.user.exerciseGroups.filter( group => {
...@@ -250,13 +248,51 @@ export default { ...@@ -250,13 +248,51 @@ export default {
}, },
created () { created () {
this.getUserData() this.getUserData()
this.getStudents().then(() => { this.loading = false }) this.getStudents().then(() => {
this.loading = false
this.getStudentListItems()
})
const groups = Assignments.getGroups() const groups = Assignments.getGroups()
}, },
methods: { methods: {
...mapActions([ ...mapActions([
'getStudents' '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) { reduceArrToDict (arr, key) {
return arr.reduce((acc, curr) => { return arr.reduce((acc, curr) => {
const keyInDict = curr[key] const keyInDict = curr[key]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment