Unify mutations to modify card properties and move to async actions
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -178,7 +178,7 @@ export default {
|
|||||||
},
|
},
|
||||||
finishedEdit(card) {
|
finishedEdit(card) {
|
||||||
if (this.copiedCard.title !== card.title) {
|
if (this.copiedCard.title !== card.title) {
|
||||||
this.$store.dispatch('updateCard', this.copiedCard)
|
this.$store.dispatch('updateCardTitle', this.copiedCard)
|
||||||
}
|
}
|
||||||
this.editing = false
|
this.editing = false
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -119,12 +119,6 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateTitle(state, card) {
|
|
||||||
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
|
|
||||||
if (existingIndex !== -1) {
|
|
||||||
state.cards[existingIndex].title = card.title
|
|
||||||
}
|
|
||||||
},
|
|
||||||
assignCardToUser(state, user) {
|
assignCardToUser(state, user) {
|
||||||
const existingIndex = state.cards.findIndex(_card => _card.id === user.cardId)
|
const existingIndex = state.cards.findIndex(_card => _card.id === user.cardId)
|
||||||
if (existingIndex !== -1) {
|
if (existingIndex !== -1) {
|
||||||
@@ -140,44 +134,25 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateCardDesc(state, card) {
|
updateCardProperty(state, { card, property }) {
|
||||||
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
|
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
|
||||||
if (existingIndex !== -1) {
|
if (existingIndex !== -1) {
|
||||||
state.cards[existingIndex].description = card.description
|
Vue.set(state.cards[existingIndex], property, card[property])
|
||||||
}
|
|
||||||
},
|
|
||||||
updateCardDue(state, card) {
|
|
||||||
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
|
|
||||||
if (existingIndex !== -1) {
|
|
||||||
state.cards[existingIndex].duedate = card.duedate
|
|
||||||
}
|
|
||||||
},
|
|
||||||
updateCardLabels(state, card) {
|
|
||||||
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
|
|
||||||
if (existingIndex !== -1) {
|
|
||||||
const existingCard = state.cards.find(_card => _card.id === card.id)
|
|
||||||
existingCard.labels = card.labels
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addCard({ commit }, card) {
|
async addCard({ commit }, card) {
|
||||||
apiClient.addCard(card)
|
const createdCard = await apiClient.addCard(card)
|
||||||
.then((createdCard) => {
|
commit('addCard', createdCard)
|
||||||
commit('addCard', createdCard)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
updateCard({ commit }, card) {
|
async updateCardTitle({ commit }, card) {
|
||||||
apiClient.updateCard(card)
|
const updatedCard = await apiClient.updateCard(card)
|
||||||
.then((updatedCard) => {
|
commit('updateCardProperty', { property: 'title', card: updatedCard })
|
||||||
commit('updateTitle', updatedCard)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
moveCard({ commit }, card) {
|
async moveCard({ commit }, card) {
|
||||||
apiClient.updateCard(card)
|
const updatedCard = await apiClient.updateCard(card)
|
||||||
.then((updatedCard) => {
|
commit('deleteCard', updatedCard)
|
||||||
commit('deleteCard', updatedCard)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
async reorderCard({ commit, getters }, card) {
|
async reorderCard({ commit, getters }, card) {
|
||||||
let i = 0
|
let i = 0
|
||||||
@@ -196,66 +171,47 @@ export default {
|
|||||||
|
|
||||||
const cards = await apiClient.reorderCard(card)
|
const cards = await apiClient.reorderCard(card)
|
||||||
await commit('updateCardsReorder', Object.values(cards))
|
await commit('updateCardsReorder', Object.values(cards))
|
||||||
|
|
||||||
},
|
},
|
||||||
deleteCard({ commit }, card) {
|
async deleteCard({ commit }, card) {
|
||||||
apiClient.deleteCard(card.id)
|
await apiClient.deleteCard(card.id)
|
||||||
.then((card) => {
|
commit('deleteCard', card)
|
||||||
commit('deleteCard', card)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
archiveUnarchiveCard({ commit }, card) {
|
async archiveUnarchiveCard({ commit }, card) {
|
||||||
let call = 'archiveCard'
|
let call = 'archiveCard'
|
||||||
if (card.archived === false) {
|
if (card.archived === false) {
|
||||||
call = 'unArchiveCard'
|
call = 'unArchiveCard'
|
||||||
}
|
}
|
||||||
|
|
||||||
apiClient[call](card)
|
const updatedCard = await apiClient[call](card)
|
||||||
.then((card) => {
|
commit('deleteCard', updatedCard)
|
||||||
commit('deleteCard', card)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
assignCardToUser({ commit }, card) {
|
async assignCardToUser({ commit }, card) {
|
||||||
apiClient.assignUser(card)
|
const user = await apiClient.assignUser(card)
|
||||||
.then((user) => {
|
commit('assignCardToUser', user)
|
||||||
commit('assignCardToUser', user)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
removeUserFromCard({ commit }, card) {
|
async removeUserFromCard({ commit }, card) {
|
||||||
apiClient.removeUser(card)
|
const user = await apiClient.removeUser(card)
|
||||||
.then((user) => {
|
commit('removeUserFromCard', user)
|
||||||
commit('removeUserFromCard', user)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
addLabel({ commit }, data) {
|
async addLabel({ commit }, data) {
|
||||||
apiClient.assignLabelToCard(data)
|
await apiClient.assignLabelToCard(data)
|
||||||
.then(() => {
|
commit('updateCardProperty', { property: 'labels', card: data.card })
|
||||||
commit('updateCardLabels', data.card)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
removeLabel({ commit }, data) {
|
async removeLabel({ commit }, data) {
|
||||||
apiClient.removeLabelFromCard(data)
|
await apiClient.removeLabelFromCard(data)
|
||||||
.then(() => {
|
commit('updateCardProperty', { property: 'labels', card: data.card })
|
||||||
commit('updateCardLabels', data.card)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
cardUndoDelete({ commit }, card) {
|
async cardUndoDelete({ commit }, card) {
|
||||||
apiClient.updateCard(card)
|
const updatedCard = await apiClient.updateCard(card)
|
||||||
.then((card) => {
|
commit('addCard', updatedCard)
|
||||||
commit('addCard', card)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
updateCardDesc({ commit }, card) {
|
async updateCardDesc({ commit }, card) {
|
||||||
apiClient.updateCard(card)
|
const updatedCard = await apiClient.updateCard(card)
|
||||||
.then((updatedCard) => {
|
commit('updateCardProperty', { property: 'description', card: updatedCard })
|
||||||
commit('updateCardDesc', updatedCard)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
updateCardDue({ commit }, card) {
|
async updateCardDue({ commit }, card) {
|
||||||
apiClient.updateCard(card)
|
const updatedCard = apiClient.updateCard(card)
|
||||||
.then((card) => {
|
commit('updateCardProperty', { property: 'duedate', card: updatedCard })
|
||||||
commit('updateCardDue', card)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user