Add add board functionality

This commit is contained in:
Michael Weimann
2018-12-16 22:47:58 +01:00
parent 6a3643384c
commit 22744ee39c
3 changed files with 42 additions and 1 deletions

View File

@@ -29,6 +29,7 @@
import { AppNavigation } from 'nextcloud-vue' import { AppNavigation } from 'nextcloud-vue'
import { translate as t } from 'nextcloud-server/dist/l10n' import { translate as t } from 'nextcloud-server/dist/l10n'
import { boardToMenuItem } from './../helpers/boardToMenuItem' import { boardToMenuItem } from './../helpers/boardToMenuItem'
import store from './../store/main'
const defaultCategories = [ const defaultCategories = [
{ {
@@ -66,7 +67,13 @@ const addButton = {
text: t('deck', 'Create new board'), text: t('deck', 'Create new board'),
edit: { edit: {
text: t('deck', 'new board'), text: t('deck', 'new board'),
action: () => { action: (submitEvent) => {
const title = submitEvent.currentTarget.childNodes[0].value
store.dispatch('createBoard', {
title: title,
color: '#000000'
})
addButton.classes = []
}, },
reset: () => { reset: () => {
} }

View File

@@ -32,6 +32,29 @@ export class BoardApi {
return OC.generateUrl(url) return OC.generateUrl(url)
} }
/**
* Creates a new board.
*
* @param {{String title, String color}} boardData The board data with title and color in hex format, e.g. "#ff0000"
* @return Promise
*/
createBoard(boardData) {
boardData.color = boardData.color.substr(1)
return axios.post(this.url('/boards'), boardData)
.then(
(response) => {
return Promise.resolve(response.data)
},
(err) => {
return Promise.reject(err)
}
)
.catch((err) => {
return Promise.reject(err)
})
}
loadBoards() { loadBoards() {
return axios.get(this.url('/boards')) return axios.get(this.url('/boards'))
.then( .then(

View File

@@ -23,9 +23,11 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import { boardToMenuItem } from './../helpers/boardToMenuItem' import { boardToMenuItem } from './../helpers/boardToMenuItem'
import { BoardApi } from './../services/BoardApi'
Vue.use(Vuex) Vue.use(Vuex)
const apiClient = new BoardApi()
const debug = process.env.NODE_ENV !== 'production' const debug = process.env.NODE_ENV !== 'production'
export const BOARD_FILTERS = { export const BOARD_FILTERS = {
@@ -59,6 +61,9 @@ export default new Vuex.Store({
} }
}, },
mutations: { mutations: {
addBoard(state, board) {
state.boards.push(board)
},
toggleNav(state) { toggleNav(state) {
state.navShown = !state.navShown state.navShown = !state.navShown
}, },
@@ -76,6 +81,12 @@ export default new Vuex.Store({
} }
}, },
actions: { actions: {
createBoard({ commit }, boardData) {
apiClient.createBoard(boardData)
.then((board) => {
commit('addBoard', board)
})
},
setBoards({ commit }, boards) { setBoards({ commit }, boards) {
commit('setBoards', boards) commit('setBoards', boards)
}, },