From 69ad41bb5810e83675fc393c46c9672cf3063b14 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Sun, 16 Dec 2018 23:30:09 +0100 Subject: [PATCH] Add archive board --- src/components/DeckAppNav.vue | 5 +-- src/helpers/boardToMenuItem.js | 56 +++++++++++++++++++--------------- src/main.js | 8 +++++ src/services/BoardApi.js | 27 ++++++++++++++-- src/store/main.js | 30 ++++++++++++++++-- 5 files changed, 94 insertions(+), 32 deletions(-) diff --git a/src/components/DeckAppNav.vue b/src/components/DeckAppNav.vue index 1bccc95f9..7bd82ca3e 100644 --- a/src/components/DeckAppNav.vue +++ b/src/components/DeckAppNav.vue @@ -71,7 +71,8 @@ const addButton = { const title = submitEvent.currentTarget.childNodes[0].value store.dispatch('createBoard', { title: title, - color: '#000000' + hashedColor: '#000000', + color: '000000' }) addButton.classes = [] }, @@ -99,7 +100,7 @@ export default { return { loading: this.loading, items: defaultCategories - .concat(this.$store.getters.boards.map(boardToMenuItem)) + .concat(this.$store.getters.noneArchivedBoards.map(boardToMenuItem)) .concat([this.addButton]) } } diff --git a/src/helpers/boardToMenuItem.js b/src/helpers/boardToMenuItem.js index df160a77d..3916fb545 100644 --- a/src/helpers/boardToMenuItem.js +++ b/src/helpers/boardToMenuItem.js @@ -20,32 +20,37 @@ * */ -const boardActions = [ - { - action: () => { +import store from './../store/main' + +function boardActions(board) { + return [ + { + action: () => { + }, + icon: 'icon-edit', + text: t('deck', 'Edit board') }, - icon: 'icon-edit', - text: t('deck', 'Edit board') - }, - { - action: () => { + { + action: function() { + store.dispatch('archiveBoard', board) + }, + icon: 'icon-archive', + text: t('deck', 'Archive board') }, - icon: 'icon-archive', - text: t('deck', 'Archive board') - }, - { - action: () => { + { + action: () => { + }, + icon: 'icon-delete', + text: t('deck', 'Delete board') }, - icon: 'icon-delete', - text: t('deck', 'Delete board') - }, - { - action: () => { - }, - icon: 'icon-settings', - text: t('deck', 'Board details') - } -] + { + action: () => { + }, + icon: 'icon-settings', + text: t('deck', 'Board details') + } + ] +} /** * Maps an API board to a menu item. @@ -64,7 +69,8 @@ export const boardToMenuItem = board => { params: { id: board.id } }, utils: { - actions: boardActions - } + actions: boardActions(board) + }, + board: board } } diff --git a/src/main.js b/src/main.js index a12f0efa9..49e151684 100644 --- a/src/main.js +++ b/src/main.js @@ -28,6 +28,14 @@ import { translate, translatePlural } from 'nextcloud-server/dist/l10n' import { generateFilePath } from 'nextcloud-server/dist/router' import VTooltip from 'v-tooltip' +/** + * Board model + * + * @typedef {Object} Board + * @property {String} title + * @property {boolean} archived + */ + // eslint-disable-next-line __webpack_nonce__ = btoa(OC.requestToken) // eslint-disable-next-line diff --git a/src/services/BoardApi.js b/src/services/BoardApi.js index 23434f81b..5b2785117 100644 --- a/src/services/BoardApi.js +++ b/src/services/BoardApi.js @@ -32,15 +32,36 @@ export class BoardApi { return OC.generateUrl(url) } + /** + * Updates a board. + * + * @param {Board} board + * @return Promise + */ + updateBoard(board) { + return axios.put(this.url(`/boards/${board.id}`), board) + .then( + (response) => { + return Promise.resolve(response.data) + }, + (err) => { + return Promise.reject(err) + } + ) + .catch((err) => { + return Promise.reject(err) + }) + } + /** * Creates a new board. * - * @param {{String title, String color}} boardData The board data with title and color in hex format, e.g. "#ff0000" + * @param {{String title, String color, String hashedColor}} boardData The board data to send. + * hashedColor is the color in hex format, e.g. "#ff0000" + * color is the same color without the "#" * @return Promise */ createBoard(boardData) { - boardData.color = boardData.color.substr(1) - return axios.post(this.url('/boards'), boardData) .then( (response) => { diff --git a/src/store/main.js b/src/store/main.js index aaad4ef99..9a4d0483f 100644 --- a/src/store/main.js +++ b/src/store/main.js @@ -50,10 +50,15 @@ export default new Vuex.Store({ boards: state => { return state.boards }, + noneArchivedBoards: state => { + return state.boards.filter(board => { + return board.archived === false + }) + }, filteredBoards: state => { // filters the boards depending on the active filter const boards = state.boards.filter(board => { - return state.boardFilter === BOARD_FILTERS.ALL + return (state.boardFilter === BOARD_FILTERS.ALL && board.archived === false) || (state.boardFilter === BOARD_FILTERS.ARCHIVED && board.archived === true) || (state.boardFilter === BOARD_FILTERS.SHARED && board.shared === 1) }) @@ -62,7 +67,15 @@ export default new Vuex.Store({ }, mutations: { addBoard(state, board) { - state.boards.push(board) + const indexExisting = state.boards.findIndex((b) => { + return board.id === b.id + }) + + if (indexExisting > -1) { + Vue.set(state.boards, indexExisting, board) + } else { + state.boards.push(board) + } }, toggleNav(state) { state.navShown = !state.navShown @@ -81,6 +94,19 @@ export default new Vuex.Store({ } }, actions: { + /** + * @param commit + * @param state + * @param {Board} board + */ + archiveBoard({ commit }, board) { + const boardCopy = JSON.parse(JSON.stringify(board)) + boardCopy.archived = true + apiClient.updateBoard(boardCopy) + .then((board) => { + commit('addBoard', board) + }) + }, createBoard({ commit }, boardData) { apiClient.createBoard(boardData) .then((board) => {