Moves boards into their own state

This commit is contained in:
Michael Weimann
2018-12-11 15:42:25 +01:00
parent 643d70e6f0
commit 6b2873ab28
7 changed files with 142 additions and 97 deletions

View File

@@ -1,5 +1,5 @@
/*
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
* @copyright Copyright (c) 2018 Michael Weimann <mail@michael-weimann.eu>
*
* @author Michael Weimann <mail@michael-weimann.eu>
*
@@ -20,32 +20,8 @@
*
*/
// eslint
import { translate as t } from 'nextcloud-server/dist/l10n'
import axios from 'nextcloud-axios'
/**
* Maps an API board to a menu item.
* @param board
* @returns {{id: *, classes: Array, bullet: string, text: *, router: {name: string, params: {id: *}}, utils: {actions: *[]}}}
*/
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
}
}
}
import { mapBoardToItem } from './boards'
let defaultCategories = [
{
@@ -77,33 +53,6 @@ let defaultCategories = [
}
]
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')
}
]
const addButton = {
icon: 'icon-add',
text: t('deck', 'Create new board'),
@@ -111,53 +60,25 @@ const addButton = {
}
}
// initial state
const state = {
hidden: false,
boards: [],
loading: false,
filter: ''
loading: false
}
export const BOARD_FILTERS = {
ALL: '',
ARCHIVED: 'archived',
SHARED: 'shared'
}
// getters
const getters = {
menu: state => {
menu: (state, getters, rootState) => {
return {
loading: state.loading,
items: defaultCategories
.concat(state.boards.map(mapBoardToItem))
.concat(rootState.boards.boards.map(mapBoardToItem))
.concat([addButton])
}
},
boards: 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)
}
}
// actions
const actions = {
toggle({ commit }) {
commit('toggle')
},
loadBoards({ commit }) {
axios.get('/apps/deck/boards')
.then((response) => {
commit('setBoards', response.data)
})
}
}
@@ -165,12 +86,6 @@ const actions = {
const mutations = {
toggle(state) {
state.hidden = !state.hidden
},
setBoards(state, boards) {
state.boards = boards
},
setFilter(state, filter) {
state.filter = filter
}
}