Refactor deleted items into trashbin store

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-03-07 08:54:48 +01:00
parent 87ae02246c
commit cbaa47ade3
7 changed files with 145 additions and 81 deletions

View File

@@ -175,6 +175,7 @@ export default {
async deleteCard({ commit }, card) {
await apiClient.deleteCard(card.id)
commit('deleteCard', card)
commit('moveCardToTrash', card)
},
async archiveUnarchiveCard({ commit }, card) {
let call = 'archiveCard'
@@ -201,10 +202,6 @@ export default {
await apiClient.removeLabelFromCard(data)
commit('updateCardProperty', { property: 'labels', card: data.card })
},
async cardUndoDelete({ commit }, card) {
const updatedCard = await apiClient.updateCard(card)
commit('addCard', updatedCard)
},
async updateCardDesc({ commit }, card) {
const updatedCard = await apiClient.updateCard(card)
commit('updateCardProperty', { property: 'description', card: updatedCard })

View File

@@ -29,6 +29,7 @@ import { BoardApi } from './../services/BoardApi'
import stack from './stack'
import card from './card'
import comment from './comment'
import trashbin from './trashbin'
Vue.use(Vuex)
@@ -46,6 +47,7 @@ export default new Vuex.Store({
stack,
card,
comment,
trashbin,
},
strict: debug,
state: {

View File

@@ -29,8 +29,6 @@ const apiClient = new StackApi()
export default {
state: {
stacks: [],
deletedStacks: [],
deletedCards: [],
},
getters: {
stacksByBoard: state => (id) => {
@@ -55,7 +53,6 @@ export default {
}
},
deleteStack(state, stack) {
const existingIndex = state.stacks.findIndex(_stack => _stack.id === stack.id)
if (existingIndex !== -1) {
state.stacks.splice(existingIndex, 1)
@@ -67,16 +64,6 @@ export default {
state.stacks[existingIndex].title = stack.title
}
},
setDeletedStacks(state, delStacks) {
state.deletedStacks = []
if (delStacks.length > 0) {
state.deletedStacks = delStacks
}
},
setDeletedCards(state, delCards) {
state.deletedCards = []
state.deletedCards = delCards
},
},
actions: {
orderStack({ commit }, { stack, removedIndex, addedIndex }) {
@@ -115,6 +102,7 @@ export default {
apiClient.deleteStack(stack.id)
.then((stack) => {
commit('deleteStack', stack)
commit('moveStackToTrash', stack)
})
},
updateStack({ commit }, stack) {
@@ -123,22 +111,5 @@ export default {
commit('updateStack', stack)
})
},
deletedItems({ commit }, boardId) {
apiClient.deletedStacks(boardId)
.then((deletedStacks) => {
commit('setDeletedStacks', deletedStacks)
})
apiClient.deletedCards(boardId)
.then((deletedCards) => {
commit('setDeletedCards', deletedCards)
})
},
stackUndoDelete({ commit }, stack) {
apiClient.updateStack(stack)
.then((stack) => {
commit('addStack', stack)
})
},
},
}

97
src/store/trashbin.js Normal file
View File

@@ -0,0 +1,97 @@
/*
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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 { StackApi } from '../services/StackApi'
import { CardApi } from '../services/CardApi'
const stackApi = new StackApi()
const cardApi = new CardApi()
export default {
state: {
deletedStacks: [],
deletedCards: [],
},
mutations: {
setDeletedStacks(state, delStacks) {
state.deletedStacks = []
if (delStacks.length > 0) {
state.deletedStacks = delStacks
}
},
moveStackToTrash(state, stack) {
stack.deletedAt = Math.floor(Date.now() / 1000)
state.deletedStacks.push(stack)
},
removeStackFromTrash(state, stack) {
const existingIndex = state.deletedStacks.findIndex(_stack => _stack.id === stack.id)
if (existingIndex !== -1) {
state.deletedStacks.splice(existingIndex, 1)
}
},
setDeletedCards(state, delCards) {
state.deletedCards = []
state.deletedCards = delCards
},
moveCardToTrash(state, card) {
card.deletedAt = Math.floor(Date.now() / 1000)
state.deletedCards.push(card)
},
removeCardFromTrash(state, card) {
const existingIndex = state.deletedCards.findIndex(_card => _card.id === card.id)
if (existingIndex !== -1) {
state.deletedCards.splice(existingIndex, 1)
}
},
},
actions: {
fetchDeletedItems({ commit }, boardId) {
stackApi.deletedStacks(boardId)
.then((deletedStacks) => {
commit('setDeletedStacks', deletedStacks)
})
cardApi.deletedCards(boardId)
.then((deletedCards) => {
commit('setDeletedCards', deletedCards)
})
},
stackUndoDelete({ commit }, stack) {
stackApi.updateStack(stack)
.then((stack) => {
commit('addStack', stack)
commit('removeStackFromTrash', stack)
})
},
cardUndoDelete({ commit }, card) {
cardApi.updateCard(card)
.then((card) => {
commit('removeCardFromTrash', card)
commit('addCard', card)
})
},
},
}