State refactoring, adds a sidebar example, extends the breadcrumb navigation, introduces an API class
This commit is contained in:
@@ -22,22 +22,74 @@
|
||||
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import boards from './modules/boards'
|
||||
import nav from './modules/nav'
|
||||
import sidebar from './modules/sidebar'
|
||||
import { boardToMenuItem } from './../helpers/boardToMenuItem'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production'
|
||||
|
||||
export const BOARD_FILTERS = {
|
||||
ALL: '',
|
||||
ARCHIVED: 'archived',
|
||||
SHARED: 'shared'
|
||||
}
|
||||
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
boards,
|
||||
nav,
|
||||
sidebar
|
||||
},
|
||||
modules: {},
|
||||
strict: debug,
|
||||
state: {},
|
||||
mutations: {},
|
||||
actions: {}
|
||||
state: {
|
||||
navShown: true,
|
||||
sidebarShown: false,
|
||||
currentBoard: null,
|
||||
boards: [],
|
||||
boardFilter: BOARD_FILTERS.ALL
|
||||
},
|
||||
getters: {
|
||||
boards: state => {
|
||||
return state.boards
|
||||
},
|
||||
filteredBoards: state => {
|
||||
// filters the boards depending on the active filter
|
||||
const boards = state.boards.filter(board => {
|
||||
return state.boardFilter === BOARD_FILTERS.ALL
|
||||
|| (state.boardFilter === BOARD_FILTERS.ARCHIVED && board.archived === true)
|
||||
|| (state.boardFilter === BOARD_FILTERS.SHARED && board.shared === 1)
|
||||
})
|
||||
return boards.map(boardToMenuItem)
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
toggleNav(state) {
|
||||
state.navShown = !state.navShown
|
||||
},
|
||||
toggleSidebar(state) {
|
||||
state.sidebarShown = !state.sidebarShown
|
||||
},
|
||||
setBoards(state, boards) {
|
||||
state.boards = boards
|
||||
},
|
||||
setBoardFilter(state, filter) {
|
||||
state.boardFilter = filter
|
||||
},
|
||||
setCurrentBoard(state, board) {
|
||||
state.currentBoard = board
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setBoards({ commit }, boards) {
|
||||
commit('setBoards', boards)
|
||||
},
|
||||
setBoardFilter({ commmit }, filter) {
|
||||
commmit('setBoardFilter', filter)
|
||||
},
|
||||
toggleNav({ commit }) {
|
||||
commit('toggleNav')
|
||||
},
|
||||
toggleSidebar({ commit }) {
|
||||
commit('toggleSidebar')
|
||||
},
|
||||
setCurrentBoard({ commit }, board) {
|
||||
commit('setCurrentBoard', board)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* @copyright Copyright (c) 2018 Michael Weimann <mail@michael-weimann.eu>
|
||||
*
|
||||
* @author Michael Weimann <mail@michael-weimann.eu>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import axios from 'nextcloud-axios'
|
||||
|
||||
const boardActions = [
|
||||
{
|
||||
action: () => {
|
||||
},
|
||||
icon: 'icon-edit',
|
||||
text: t('deck', 'Edit board')
|
||||
},
|
||||
{
|
||||
action: () => {
|
||||
},
|
||||
icon: 'icon-archive',
|
||||
text: t('deck', 'Archive board')
|
||||
},
|
||||
{
|
||||
action: () => {
|
||||
},
|
||||
icon: 'icon-delete',
|
||||
text: t('deck', 'Delete board')
|
||||
},
|
||||
{
|
||||
action: () => {
|
||||
},
|
||||
icon: 'icon-settings',
|
||||
text: t('deck', 'Board details')
|
||||
}
|
||||
]
|
||||
|
||||
export const BOARD_FILTERS = {
|
||||
ALL: '',
|
||||
ARCHIVED: 'archived',
|
||||
SHARED: 'shared'
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an API board to a menu item.
|
||||
* @param board
|
||||
* @returns {{id: *, classes: Array, bullet: string, text: *, router: {name: string, params: {id: *}}, utils: {actions: *[]}}}
|
||||
*/
|
||||
export const mapBoardToItem = board => {
|
||||
return {
|
||||
id: board.id,
|
||||
classes: [],
|
||||
bullet: `#${board.color}`,
|
||||
text: board.title,
|
||||
owner: board.owner,
|
||||
router: {
|
||||
name: 'board',
|
||||
params: { id: board.id }
|
||||
},
|
||||
utils: {
|
||||
actions: boardActions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const state = {
|
||||
boards: [],
|
||||
loading: false,
|
||||
filter: ''
|
||||
}
|
||||
|
||||
const getters = {
|
||||
filteredBoards: 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 boards.map(mapBoardToItem)
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
toggle({ commit }) {
|
||||
commit('toggle')
|
||||
},
|
||||
loadBoards({ commit }) {
|
||||
axios.get('/apps/deck/boards')
|
||||
.then((response) => {
|
||||
commit('setBoards', response.data)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
toggle(state) {
|
||||
state.hidden = !state.hidden
|
||||
},
|
||||
setBoards(state, boards) {
|
||||
state.boards = boards
|
||||
},
|
||||
setFilter(state, filter) {
|
||||
state.filter = filter
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* @copyright Copyright (c) 2018 Michael Weimann <mail@michael-weimann.eu>
|
||||
*
|
||||
* @author Michael Weimann <mail@michael-weimann.eu>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import { translate as t } from 'nextcloud-server/dist/l10n'
|
||||
import { mapBoardToItem } from './boards'
|
||||
import store from '../main'
|
||||
|
||||
let defaultCategories = [
|
||||
{
|
||||
id: 'deck-boards',
|
||||
classes: [],
|
||||
icon: 'icon-deck',
|
||||
text: t('deck', 'All boards'),
|
||||
router: {
|
||||
name: 'boards'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'deck-boards-archived',
|
||||
classes: [],
|
||||
icon: 'icon-archive',
|
||||
text: t('deck', 'Archived boards'),
|
||||
router: {
|
||||
name: 'boards.archived'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'deck-boards-shared',
|
||||
classes: [],
|
||||
icon: 'icon-shared',
|
||||
text: t('deck', 'Shared boards'),
|
||||
router: {
|
||||
name: 'boards.shared'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
const state = {
|
||||
hidden: false,
|
||||
loading: false,
|
||||
addButton: {
|
||||
icon: 'icon-add',
|
||||
classes: [],
|
||||
text: t('deck', 'Create new board'),
|
||||
edit: {
|
||||
text: t('deck', 'new board'),
|
||||
action: () => {
|
||||
},
|
||||
reset: () => {
|
||||
}
|
||||
},
|
||||
action: () => {
|
||||
store.dispatch('nav/startAddBoard')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getters = {
|
||||
menu: (state, getters, rootState) => {
|
||||
return {
|
||||
loading: state.loading,
|
||||
items: defaultCategories
|
||||
.concat(rootState.boards.boards.map(mapBoardToItem))
|
||||
.concat([state.addButton])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
toggle({ commit }) {
|
||||
commit('toggle')
|
||||
},
|
||||
startAddBoard({ commit }) {
|
||||
commit('startAddBoard')
|
||||
}
|
||||
}
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
toggle(state) {
|
||||
state.hidden = !state.hidden
|
||||
},
|
||||
startAddBoard(state) {
|
||||
state.addButton.classes.push('editing')
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* @copyright Copyright (c) 2018 Michael Weimann <mail@michael-weimann.eu>
|
||||
*
|
||||
* @author Michael Weimann <mail@michael-weimann.eu>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// initial state
|
||||
const state = {
|
||||
hidden: true,
|
||||
component: 'Sidebar'
|
||||
}
|
||||
|
||||
// getters
|
||||
const getters = {}
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
toggle({ commit }) {
|
||||
commit('toggle')
|
||||
}
|
||||
}
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
toggle(state) {
|
||||
state.hidden = !state.hidden
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
Reference in New Issue
Block a user