feat: improve useTaskList (#2582)
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/2582
This commit is contained in:
commit
d5258b7315
@ -34,7 +34,7 @@ import {computed, ref, watch} from 'vue'
|
|||||||
|
|
||||||
import Filters from '@/components/list/partials/filters.vue'
|
import Filters from '@/components/list/partials/filters.vue'
|
||||||
|
|
||||||
import {getDefaultParams} from '@/composables/taskList'
|
import {getDefaultParams} from '@/composables/useTaskList'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
@ -212,7 +212,7 @@ import EditLabels from '@/components/tasks/partials/editLabels.vue'
|
|||||||
|
|
||||||
import {dateIsValid, formatISO} from '@/helpers/time/formatDate'
|
import {dateIsValid, formatISO} from '@/helpers/time/formatDate'
|
||||||
import {objectToSnakeCase} from '@/helpers/case'
|
import {objectToSnakeCase} from '@/helpers/case'
|
||||||
import {getDefaultParams} from '@/composables/taskList'
|
import {getDefaultParams} from '@/composables/useTaskList'
|
||||||
import {camelCase} from 'camel-case'
|
import {camelCase} from 'camel-case'
|
||||||
|
|
||||||
// FIXME: merge with DEFAULT_PARAMS in taskList.js
|
// FIXME: merge with DEFAULT_PARAMS in taskList.js
|
||||||
|
@ -18,23 +18,12 @@ const SORT_BY_DEFAULT = {
|
|||||||
id: 'desc',
|
id: 'desc',
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This mixin provides a base set of methods and properties to get tasks on a list.
|
|
||||||
*/
|
|
||||||
export function useTaskList(listId, sortByDefault = SORT_BY_DEFAULT) {
|
|
||||||
const params = ref({...getDefaultParams()})
|
|
||||||
|
|
||||||
const search = ref('')
|
|
||||||
const page = ref(1)
|
|
||||||
|
|
||||||
const sortBy = ref({ ...sortByDefault })
|
|
||||||
|
|
||||||
// This makes sure an id sort order is always sorted last.
|
// This makes sure an id sort order is always sorted last.
|
||||||
// When tasks would be sorted first by id and then by whatever else was specified, the id sort takes
|
// When tasks would be sorted first by id and then by whatever else was specified, the id sort takes
|
||||||
// precedence over everything else, making any other sort columns pretty useless.
|
// precedence over everything else, making any other sort columns pretty useless.
|
||||||
function formatSortOrder(params) {
|
function formatSortOrder(sortBy, params) {
|
||||||
let hasIdFilter = false
|
let hasIdFilter = false
|
||||||
const sortKeys = Object.keys(sortBy.value)
|
const sortKeys = Object.keys(sortBy)
|
||||||
for (const s of sortKeys) {
|
for (const s of sortKeys) {
|
||||||
if (s === 'id') {
|
if (s === 'id') {
|
||||||
sortKeys.splice(s, 1)
|
sortKeys.splice(s, 1)
|
||||||
@ -46,11 +35,24 @@ export function useTaskList(listId, sortByDefault = SORT_BY_DEFAULT) {
|
|||||||
sortKeys.push('id')
|
sortKeys.push('id')
|
||||||
}
|
}
|
||||||
params.sort_by = sortKeys
|
params.sort_by = sortKeys
|
||||||
params.order_by = sortKeys.map(s => sortBy.value[s])
|
params.order_by = sortKeys.map(s => sortBy[s])
|
||||||
|
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This mixin provides a base set of methods and properties to get tasks on a list.
|
||||||
|
*/
|
||||||
|
export function useTaskList(listId, sortByDefault = SORT_BY_DEFAULT) {
|
||||||
|
const params = ref({...getDefaultParams()})
|
||||||
|
|
||||||
|
const search = ref('')
|
||||||
|
const page = ref(1)
|
||||||
|
|
||||||
|
const sortBy = ref({ ...sortByDefault })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const getAllTasksParams = computed(() => {
|
const getAllTasksParams = computed(() => {
|
||||||
let loadParams = {...params.value}
|
let loadParams = {...params.value}
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ export function useTaskList(listId, sortByDefault = SORT_BY_DEFAULT) {
|
|||||||
loadParams.s = search.value
|
loadParams.s = search.value
|
||||||
}
|
}
|
||||||
|
|
||||||
loadParams = formatSortOrder(loadParams)
|
loadParams = formatSortOrder(sortBy.value, loadParams)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{listId: listId.value},
|
{listId: listId.value},
|
@ -154,7 +154,7 @@ import Nothing from '@/components/misc/nothing.vue'
|
|||||||
import Pagination from '@/components/misc/pagination.vue'
|
import Pagination from '@/components/misc/pagination.vue'
|
||||||
import {ALPHABETICAL_SORT} from '@/components/list/partials/filters.vue'
|
import {ALPHABETICAL_SORT} from '@/components/list/partials/filters.vue'
|
||||||
|
|
||||||
import {useTaskList} from '@/composables/taskList'
|
import {useTaskList} from '@/composables/useTaskList'
|
||||||
import {RIGHTS as Rights} from '@/constants/rights'
|
import {RIGHTS as Rights} from '@/constants/rights'
|
||||||
import {calculateItemPosition} from '@/helpers/calculateItemPosition'
|
import {calculateItemPosition} from '@/helpers/calculateItemPosition'
|
||||||
import type {ITask} from '@/modelTypes/ITask'
|
import type {ITask} from '@/modelTypes/ITask'
|
||||||
|
@ -196,7 +196,7 @@ import FilterPopup from '@/components/list/partials/filter-popup.vue'
|
|||||||
import Pagination from '@/components/misc/pagination.vue'
|
import Pagination from '@/components/misc/pagination.vue'
|
||||||
import Popup from '@/components/misc/popup.vue'
|
import Popup from '@/components/misc/popup.vue'
|
||||||
|
|
||||||
import {useTaskList} from '@/composables/taskList'
|
import {useTaskList} from '@/composables/useTaskList'
|
||||||
import type {ITask} from '@/modelTypes/ITask'
|
import type {ITask} from '@/modelTypes/ITask'
|
||||||
|
|
||||||
const ACTIVE_COLUMNS_DEFAULT = {
|
const ACTIVE_COLUMNS_DEFAULT = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user