From 7719ef1bef149d537648544612aa002c95a352d6 Mon Sep 17 00:00:00 2001 From: dpschen Date: Tue, 21 Sep 2021 19:03:38 +0000 Subject: [PATCH] feat: move pagination to dedicated component (#760) Co-authored-by: Dominik Pschenitschni Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/760 Reviewed-by: konrad Co-authored-by: dpschen Co-committed-by: dpschen --- src/components/misc/pagination.vue | 125 ++++++++++++++++++++++++ src/components/tasks/mixins/taskList.js | 50 ---------- src/styles/theme/background.scss | 1 + src/styles/theme/theme.scss | 12 --- src/views/list/views/List.vue | 44 ++------- src/views/list/views/Table.vue | 40 ++------ 6 files changed, 138 insertions(+), 134 deletions(-) create mode 100644 src/components/misc/pagination.vue diff --git a/src/components/misc/pagination.vue b/src/components/misc/pagination.vue new file mode 100644 index 00000000..83d9d002 --- /dev/null +++ b/src/components/misc/pagination.vue @@ -0,0 +1,125 @@ + + + + + \ No newline at end of file diff --git a/src/components/tasks/mixins/taskList.js b/src/components/tasks/mixins/taskList.js index cd67e7ce..92e5de1f 100644 --- a/src/components/tasks/mixins/taskList.js +++ b/src/components/tasks/mixins/taskList.js @@ -12,50 +12,6 @@ const DEFAULT_PARAMS = { filter_concat: 'and', } -function createPagination(totalPages, currentPage) { - const pages = [] - for (let i = 0; i < totalPages; i++) { - - // Show ellipsis instead of all pages - if ( - i > 0 && // Always at least the first page - (i + 1) < totalPages && // And the last page - ( - // And the current with current + 1 and current - 1 - (i + 1) > currentPage + 1 || - (i + 1) < currentPage - 1 - ) - ) { - // Only add an ellipsis if the last page isn't already one - if (pages[i - 1] && !pages[i - 1].isEllipsis) { - pages.push({ - number: 0, - isEllipsis: true, - }) - } - continue - } - - pages.push({ - number: i + 1, - isEllipsis: false, - }) - } - return pages -} - -export function getRouteForPagination(page = 1, type = 'list') { - return { - name: 'list.' + type, - params: { - type: type, - }, - query: { - page: page, - }, - } -} - /** * This mixin provides a base set of methods and properties to get tasks on a list. */ @@ -84,11 +40,6 @@ export default { }, '$route.path': 'loadTasksOnSavedFilter', }, - computed: { - pages() { - return createPagination(this.taskCollectionService.totalPages, this.currentPage) - }, - }, methods: { loadTasks( page, @@ -213,6 +164,5 @@ export default { this.error(e) }) }, - getRouteForPagination, }, } \ No newline at end of file diff --git a/src/styles/theme/background.scss b/src/styles/theme/background.scss index 5a4664a5..0db72d0a 100644 --- a/src/styles/theme/background.scss +++ b/src/styles/theme/background.scss @@ -5,6 +5,7 @@ background-attachment: fixed; min-height: 100vh; + // FIXME: move to pagination component .pagination-link:not(.is-current) { background: $light-background; } diff --git a/src/styles/theme/theme.scss b/src/styles/theme/theme.scss index a4438ef8..2004f44f 100644 --- a/src/styles/theme/theme.scss +++ b/src/styles/theme/theme.scss @@ -116,18 +116,6 @@ button.table { } } -.pagination { - padding-bottom: 1rem; - - .pagination-previous, - .pagination-next { - &:not(:disabled):hover { - background: $button-background-color; - cursor: pointer; - } - } -} - .is-max-width-desktop { width: 100%; max-width: $desktop; diff --git a/src/views/list/views/List.vue b/src/views/list/views/List.vue index 334c46ea..de935ddd 100644 --- a/src/views/list/views/List.vue +++ b/src/views/list/views/List.vue @@ -121,44 +121,10 @@ - + @@ -182,6 +148,7 @@ import FilterPopup from '@/components/list/partials/filter-popup.vue' import {HAS_TASKS} from '@/store/mutation-types' import Nothing from '@/components/misc/nothing.vue' import createTask from '@/components/tasks/mixins/createTask' +import Pagination from '@/components/misc/pagination.vue' import {mapState} from 'vuex' import draggable from 'vuedraggable' @@ -214,6 +181,7 @@ export default { EditTask, AddTask, draggable, + Pagination, }, created() { this.taskService = new TaskService() diff --git a/src/views/list/views/Table.vue b/src/views/list/views/Table.vue index 3deded87..18149416 100644 --- a/src/views/list/views/Table.vue +++ b/src/views/list/views/Table.vue @@ -172,40 +172,10 @@ - + @@ -226,6 +196,7 @@ import Fancycheckbox from '../../../components/input/fancycheckbox' import Sort from '../../../components/tasks/partials/sort' import {saveListView} from '@/helpers/saveListView' import FilterPopup from '@/components/list/partials/filter-popup.vue' +import Pagination from '@/components/misc/pagination.vue' export default { name: 'Table', @@ -237,6 +208,7 @@ export default { Labels, PriorityLabel, User, + Pagination, }, mixins: [ taskList,