From 5ea20e1268c6e13187257b9ddb0c8d56bf0cd622 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Tue, 4 Dec 2018 00:10:58 +0100 Subject: [PATCH] Implements board filters --- src/components/{Main.vue => Boards.vue} | 15 +++++++++++++-- src/router.js | 23 +++++++++++++++++++---- src/store/modules/nav.js | 24 ++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 8 deletions(-) rename src/components/{Main.vue => Boards.vue} (84%) diff --git a/src/components/Main.vue b/src/components/Boards.vue similarity index 84% rename from src/components/Main.vue rename to src/components/Boards.vue index a50d96fe2..68f8fe9c9 100644 --- a/src/components/Main.vue +++ b/src/components/Boards.vue @@ -22,13 +22,24 @@ diff --git a/src/router.js b/src/router.js index 0b0847a20..811e02f90 100644 --- a/src/router.js +++ b/src/router.js @@ -23,8 +23,9 @@ import Vue from 'vue' import Router from 'vue-router' import { generateUrl } from 'nextcloud-server/dist/router' +import { BOARD_FILTERS } from './store/modules/nav' -const Main = () => import('./components/Main') +const Boards = () => import('./components/Boards') Vue.use(Router) @@ -35,17 +36,31 @@ export default new Router({ { path: '/', name: 'main', - component: Main + component: Boards }, { path: '/boards', name: 'boards', - component: Main + component: Boards, + props: { + navFilter: BOARD_FILTERS.ALL + } }, { path: '/boards/archived', name: 'boards.archived', - component: Main + component: Boards, + props: { + navFilter: BOARD_FILTERS.ARCHIVED + } + }, + { + path: '/boards/shared', + name: 'boards.shared', + component: Boards, + props: { + navFilter: BOARD_FILTERS.SHARED + } } ] }) diff --git a/src/store/modules/nav.js b/src/store/modules/nav.js index e86b1790e..723e99216 100644 --- a/src/store/modules/nav.js +++ b/src/store/modules/nav.js @@ -20,6 +20,8 @@ * */ +// eslint + import { translate as t } from 'nextcloud-server/dist/l10n' import axios from 'nextcloud-axios' @@ -112,16 +114,31 @@ const addButton = { const state = { hidden: false, boards: [], - loading: false + loading: false, + filter: '' +} + +export const BOARD_FILTERS = { + ALL: '', + ARCHIVED: 'archived', + SHARED: 'shared' } // getters const getters = { menu: state => { + + // filters the boards depending on the active filter + const boards = state.boards.filter(board => { + return state.filter === BOARD_FILTERS.ALL + || (state.filter === BOARD_FILTERS.ARCHIVED && board.archived === true) + || (state.filter === BOARD_FILTERS.SHARED && board.shared === 1) + }) + return { loading: state.loading, items: defaultCategories - .concat(state.boards.map(mapBoardToItem)) + .concat(boards.map(mapBoardToItem)) .concat([addButton]) } } @@ -147,6 +164,9 @@ const mutations = { }, setBoards(state, boards) { state.boards = boards + }, + setFilter(state, filter) { + state.filter = filter } }