Tasks sorting implementation.

Signed-off-by: Vadim Nicolai <contact@vadimnicolai.com>
This commit is contained in:
Vadim Nicolai 2018-12-11 08:32:03 +02:00 committed by Raimund Schlüßler
parent ca9584bb41
commit 3adceada8c
No known key found for this signature in database
GPG key ID: 036FA7EB1A599178
7 changed files with 113 additions and 15 deletions

3
package-lock.json generated
View file

@ -6142,8 +6142,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",

View file

@ -3,6 +3,7 @@ Nextcloud - Tasks
@author Raimund Schlüßler
@copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
@copyright 2018 Vadim Nicolai <contact@vadimnicolai.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -107,7 +108,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
</form>
</div>
<ol v-if="!task.hideSubtasks" :calendarID="task.calendar.uri">
<TaskBodyComponent v-for="subtask in task.subTasks"
<TaskBodyComponent v-for="subtask in sort([...task.subTasks], sortOrder, sortDirection)"
:key="subtask.uid"
:task="subtask"
class="subtask"
@ -119,9 +120,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
</template>
<script>
import { overdue, valid } from '../store/storeHelper'
import { overdue, valid, sort } from '../store/storeHelper'
import ClickOutside from 'vue-click-outside'
import { mapActions } from 'vuex'
import { mapGetters, mapActions } from 'vuex'
import focus from '../directives/focus'
export default {
@ -158,6 +159,10 @@ export default {
}
},
computed: {
...mapGetters({
sortOrder: 'sortOrder',
sortDirection: 'sortDirection'
}),
/**
* Returns the path of the task
*
@ -207,6 +212,7 @@ export default {
'toggleCompleted',
'toggleStarred'
]),
sort,
/**
* Checks if a date is overdue
*/

View file

@ -3,6 +3,7 @@ Nextcloud - Tasks
@author Raimund Schlüßler
@copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
@copyright 2018 Vadim Nicolai <contact@vadimnicolai.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -43,7 +44,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
collectionId="uncompleted"
type="list"
>
<Task v-for="task in uncompletedRootTasks(calendar.tasks)"
<Task v-for="task in sort(uncompletedRootTasks(calendar.tasks), sortOrder, sortDirection)"
:key="task.id"
:task="task"
/>
@ -58,7 +59,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
collectionId="completed"
type="list"
>
<Task v-for="task in completedRootTasks(calendar.tasks)"
<Task v-for="task in sort(completedRootTasks(calendar.tasks), sortOrder, sortDirection)"
:key="task.id"
:task="task"
/>
@ -72,6 +73,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<script>
import { mapGetters } from 'vuex'
import { sort } from '../../store/storeHelper'
import SortorderDropdown from '../SortorderDropdown'
import LoadCompletedButton from '../LoadCompletedButton'
import Task from '../Task'
@ -124,10 +126,13 @@ export default {
completedCount: 'getCalendarCountCompleted',
calendar: 'getCalendarByRoute',
uncompletedRootTasks: 'findUncompletedRootTasks',
completedRootTasks: 'findCompletedRootTasks'
completedRootTasks: 'findCompletedRootTasks',
sortOrder: 'sortOrder',
sortDirection: 'sortDirection'
})
},
methods: {
sort,
toggleHidden: function() {
this.showHidden = +!this.showHidden
},

View file

@ -3,6 +3,7 @@ Nextcloud - Tasks
@author Raimund Schlüßler
@copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
@copyright 2018 Vadim Nicolai <contact@vadimnicolai.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -49,7 +50,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
class="tasks"
type="list"
>
<TaskBody v-for="task in uncompletedRootTasks(calendar.tasks)"
<TaskBody v-for="task in sort(uncompletedRootTasks(calendar.tasks), sortOrder, sortDirection)"
:key="task.id"
:task="task"
/>
@ -63,6 +64,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<script>
import { mapGetters } from 'vuex'
import { sort } from '../../store/storeHelper'
import SortorderDropdown from '../SortorderDropdown'
import LoadCompletedButton from '../LoadCompletedButton'
import TaskBody from '../Task'
@ -117,10 +119,13 @@ export default {
uncompletedRootTasks: 'findUncompletedRootTasks',
calendar: 'getDefaultCalendar',
calendars: 'getSortedCalendars',
calendarCount: 'getCalendarCountByCollectionId'
calendarCount: 'getCalendarCountByCollectionId',
sortOrder: 'sortOrder',
sortDirection: 'sortDirection'
})
},
methods: {
sort,
clearNewTask: function(event) {
event.target.blur()
this.newTaskName = ''

View file

@ -3,6 +3,7 @@ Nextcloud - Tasks
@author Raimund Schlüßler
@copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
@copyright 2018 Vadim Nicolai <contact@vadimnicolai.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -32,7 +33,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
listID=""
type="list"
>
<TaskBody v-for="task in uncompletedRootTasks(tasks)"
<TaskBody v-for="task in sort(uncompletedRootTasks(tasks), sortOrder, sortDirection)"
:key="task.id"
:task="task"
/>
@ -45,6 +46,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<script>
import { mapGetters } from 'vuex'
import { sort } from '../../store/storeHelper'
import SortorderDropdown from '../SortorderDropdown'
import TaskBody from '../Task'
@ -75,10 +77,13 @@ export default {
computed: {
...mapGetters({
tasks: 'getAllTasks',
uncompletedRootTasks: 'findUncompletedRootTasks'
})
uncompletedRootTasks: 'findUncompletedRootTasks',
sortOrder: 'sortOrder',
sortDirection: 'sortDirection'
}),
},
methods: {
sort,
dayHasEntry: function(days) {
return days
}

View file

@ -3,6 +3,7 @@
*
* @author Raimund Schlüßler
* @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
* @copyright 2018 Vadim Nicolai <contact@vadimnicolai.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -30,7 +31,10 @@ const state = {
settings: {}
}
const getters = {}
const getters = {
sortOrder: (state) => state.settings.sortOrder,
sortDirection: (state) => state.settings.sortDirection,
}
const mutations = {
setSettings(state, payload) {

View file

@ -3,6 +3,7 @@
*
* @author Raimund Schlüßler
* @copyright 2017 Raimund Schlüßler <raimund.schluessler@mailbox.org>
* @copyright 2018 Vadim Nicolai <contact@vadimnicolai.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -110,9 +111,82 @@ function isParentInList(task, tasks) {
})
}
/**
* Sorts tasks in specified order type
*
* @param {Array} tasks The tasks to search in
* @param {String} sortOrder The sorting order type
* @param {Boolean} sortDirection The sorting direction
* @returns {Array}
*/
function sort(tasks, sortOrder, sortDirection) {
switch (sortOrder) {
case 'alphabetically': {
const sortedTasks = sortAlphabetically(tasks)
if (sortDirection) return sortedTasks
return sortedTasks.reverse()
}
case 'priority': {
const sortedTasks = tasks.sort((taskA, taskB) => taskA.priority - taskB.priority)
if (sortDirection) return sortedTasks
return sortedTasks.reverse()
}
case 'due': {
const sortedTasks = sortByDate(tasks, 'due')
if (sortDirection) return sortedTasks
return sortedTasks.reverse()
}
case 'start': {
const sortedTasks = sortByDate(tasks, 'start')
if (sortDirection) return sortedTasks
return sortedTasks.reverse()
}
default:
return tasks
}
}
/**
* Sorts tasks alphabetically in ascending order
*
* @param {Array} tasks The tasks to be sorted
* @returns {Array}
*/
function sortAlphabetically(tasks) {
return tasks.sort((taskA, taskB) =>
taskA.summary.toLowerCase().localeCompare(taskB.summary.toLowerCase())
)
}
/**
* Sorts tasks by date in ascending order
*
* @param {Array} tasks The tasks to be sorted
* @param {String} date The date sort type
* @returns {Array}
*/
function sortByDate(tasks, date) {
return tasks.sort((taskA, taskB) => {
if (taskA[date] === null && taskB[date] !== null) {
return -1
}
if (taskA[date] !== null && taskB[date] === null) {
return 1
}
if (taskA[date] === null && taskB[date] === null) {
return 0
}
return moment(taskA[date]).format('YYYYMMDDHHmm') - moment(taskB[date]).format('YYYYMMDDHHmm')
})
}
export {
isTaskInList,
valid,
overdue,
isParentInList
isParentInList,
sort,
}