Skip to content
Snippets Groups Projects
Commit 66398c2c authored by Marcus Eibrink-Lunzenauer's avatar Marcus Eibrink-Lunzenauer
Browse files

Re-enable sorting of task groups.

parent b3f6bde7
No related branches found
No related tags found
No related merge requests found
Pipeline #17510 failed
...@@ -2,38 +2,47 @@ ...@@ -2,38 +2,47 @@
<div class="cw-dashboard-students-wrapper"> <div class="cw-dashboard-students-wrapper">
<table class="default" v-if="taskGroups.length"> <table class="default" v-if="taskGroups.length">
<thead> <thead>
<tr> <tr class="sortable">
<th>{{ $gettext('Status') }}</th> <th>
<th>{{ $gettext('Titel') }}</th> {{ $gettext('Status') }}
<th>{{ $gettext('Bearbeitungszeit') }}</th> </th>
<th :class="getSortClass('task-group-title')" @click="sort('task-group-title')">
{{ $gettext('Titel') }}
</th>
<th :class="getSortClass('end-date')" @click="sort('end-date')">
{{ $gettext('Bearbeitungszeit') }}
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(taskGroup, index) in taskGroups"> <tr v-for="(taskGroup, index) in sortedTaskGroups" :key="index">
<td> <td>
<StudipIcon <StudipIcon
:shape="status(taskGroup).shape" :shape="status(taskGroup).shape"
:role="status(taskGroup).role" :role="status(taskGroup).role"
:title="status(taskGroup).description" :title="status(taskGroup).description"
aria-hidden="true" aria-hidden="true"
/> />
<span class="sr-only">{{ status(taskGroup).description }}</span> <span class="sr-only">{{ status(taskGroup).description }}</span>
</td> </td>
<td> <td>
<router-link :to="{ name: 'task-groups-show', params: { id: taskGroup.id } }">{{ taskGroup.attributes.title }}</router-link> <router-link :to="{ name: 'task-groups-show', params: { id: taskGroup.id } }">{{
</td> taskGroup.attributes.title
<td> }}</router-link>
<StudipDate :date="new Date(taskGroup.attributes['start-date'])" /><StudipDate :date="new Date(taskGroup.attributes['end-date'])" /> </td>
</td> <td>
</tr> <StudipDate :date="new Date(taskGroup.attributes['start-date'])" /><StudipDate
:date="new Date(taskGroup.attributes['end-date'])"
/>
</td>
</tr>
</tbody> </tbody>
</table> </table>
<CompanionBox v-else-if="!tasksLoading" <CompanionBox v-else-if="!tasksLoading" :msgCompanion="$gettext('Es wurden noch keine Aufgaben verteilt.')">
:msgCompanion="$gettext('Es wurden noch keine Aufgaben verteilt.')">
<template #companionActions> <template #companionActions>
<button @click="setShowTasksDistributeDialog(true)" type="button" class="button"> <button @click="setShowTasksDistributeDialog(true)" type="button" class="button">
{{ $gettext("Aufgabe verteilen") }} {{ $gettext('Aufgabe verteilen') }}
</button> </button>
</template> </template>
</CompanionBox> </CompanionBox>
...@@ -59,6 +68,10 @@ export default { ...@@ -59,6 +68,10 @@ export default {
StudipDate, StudipDate,
StudipIcon, StudipIcon,
}, },
data: () => ({
sortBy: 'end-date',
sortASC: false,
}),
computed: { computed: {
...mapGetters({ ...mapGetters({
context: 'context', context: 'context',
...@@ -66,10 +79,19 @@ export default { ...@@ -66,10 +79,19 @@ export default {
taskGroupsByCid: 'tasks/taskGroupsByCid', taskGroupsByCid: 'tasks/taskGroupsByCid',
tasksLoading: 'courseware-tasks/isLoading', tasksLoading: 'courseware-tasks/isLoading',
}), }),
sortedTaskGroups() {
const sorters = {
'task-group-title': (taskGroup) => taskGroup.attributes.title,
'end-date': (taskGroup) => new Date(taskGroup.attributes['end-date']),
};
return _.chain(this.taskGroups)
.sortBy([sorters[this.sortBy]])
.thru((sorted) => (this.sortAsc ? sorted : _.reverse(sorted)))
.value();
},
taskGroups() { taskGroups() {
return _.sortBy(this.taskGroupsByCid(this.context.id), [ return this.taskGroupsByCid(this.context.id);
(taskGroup) => -new Date(taskGroup.attributes['end-date']),
]);
}, },
}, },
methods: { methods: {
...@@ -77,7 +99,12 @@ export default { ...@@ -77,7 +99,12 @@ export default {
loadAllTasks: 'courseware-tasks/loadAll', loadAllTasks: 'courseware-tasks/loadAll',
setShowTasksDistributeDialog: 'tasks/setShowTasksDistributeDialog', setShowTasksDistributeDialog: 'tasks/setShowTasksDistributeDialog',
}), }),
status: getStatus, getSortClass(col) {
if (col === this.sortBy) {
return this.sortASC ? 'sortasc' : 'sortdesc';
}
return '';
},
reloadTasks() { reloadTasks() {
this.loadAllTasks({ this.loadAllTasks({
options: { options: {
...@@ -86,6 +113,23 @@ export default { ...@@ -86,6 +113,23 @@ export default {
}, },
}); });
}, },
sort(sortBy) {
if (this.sortBy === sortBy) {
this.sortASC = !this.sortASC;
} else {
this.sortBy = sortBy;
}
},
status: getStatus,
}, },
}; };
</script> </script>
<style scoped>
th {
cursor: pointer;
}
th:first-child {
cursor: not-allowed;
}
</style>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment