chore: don't resolve when returning from promise & improve list store module
This commit is contained in:
parent
3b940cb56c
commit
a776e1d2f3
16 changed files with 130 additions and 150 deletions
|
@ -106,7 +106,7 @@ export default {
|
||||||
window.API_URL = urlToCheck.toString()
|
window.API_URL = urlToCheck.toString()
|
||||||
return this.$store.dispatch('config/update')
|
return this.$store.dispatch('config/update')
|
||||||
}
|
}
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
// Check if it has a port and if not check if it is reachable at https
|
// Check if it has a port and if not check if it is reachable at https
|
||||||
|
@ -115,7 +115,7 @@ export default {
|
||||||
window.API_URL = urlToCheck.toString()
|
window.API_URL = urlToCheck.toString()
|
||||||
return this.$store.dispatch('config/update')
|
return this.$store.dispatch('config/update')
|
||||||
}
|
}
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
// Check if it is reachable at /api/v1 and https
|
// Check if it is reachable at /api/v1 and https
|
||||||
|
@ -128,7 +128,7 @@ export default {
|
||||||
window.API_URL = urlToCheck.toString()
|
window.API_URL = urlToCheck.toString()
|
||||||
return this.$store.dispatch('config/update')
|
return this.$store.dispatch('config/update')
|
||||||
}
|
}
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
// Check if it is reachable at port API_DEFAULT_PORT and https
|
// Check if it is reachable at port API_DEFAULT_PORT and https
|
||||||
|
@ -138,7 +138,7 @@ export default {
|
||||||
window.API_URL = urlToCheck.toString()
|
window.API_URL = urlToCheck.toString()
|
||||||
return this.$store.dispatch('config/update')
|
return this.$store.dispatch('config/update')
|
||||||
}
|
}
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
// Check if it is reachable at :API_DEFAULT_PORT and /api/v1 and https
|
// Check if it is reachable at :API_DEFAULT_PORT and /api/v1 and https
|
||||||
|
@ -151,7 +151,7 @@ export default {
|
||||||
window.API_URL = urlToCheck.toString()
|
window.API_URL = urlToCheck.toString()
|
||||||
return this.$store.dispatch('config/update')
|
return this.$store.dispatch('config/update')
|
||||||
}
|
}
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
// Check if it is reachable at port API_DEFAULT_PORT and http
|
// Check if it is reachable at port API_DEFAULT_PORT and http
|
||||||
|
@ -161,7 +161,7 @@ export default {
|
||||||
window.API_URL = urlToCheck.toString()
|
window.API_URL = urlToCheck.toString()
|
||||||
return this.$store.dispatch('config/update')
|
return this.$store.dispatch('config/update')
|
||||||
}
|
}
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
// Check if it is reachable at :API_DEFAULT_PORT and /api/v1 and http
|
// Check if it is reachable at :API_DEFAULT_PORT and /api/v1 and http
|
||||||
|
@ -174,7 +174,7 @@ export default {
|
||||||
window.API_URL = urlToCheck.toString()
|
window.API_URL = urlToCheck.toString()
|
||||||
return this.$store.dispatch('config/update')
|
return this.$store.dispatch('config/update')
|
||||||
}
|
}
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// Still not found, url is still invalid
|
// Still not found, url is still invalid
|
||||||
|
|
|
@ -50,7 +50,7 @@ export const refreshToken = (persist: boolean): Promise<AxiosResponse> => {
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then(r => {
|
||||||
saveToken(r.data.token, persist)
|
saveToken(r.data.token, persist)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
throw new Error('Error renewing token: ', { cause: e })
|
throw new Error('Error renewing token: ', { cause: e })
|
||||||
|
|
|
@ -27,14 +27,13 @@ const setI18nLanguage = lang => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadLanguageAsync = lang => {
|
export const loadLanguageAsync = lang => {
|
||||||
// If the same language
|
if (
|
||||||
if (i18n.locale === lang) {
|
// If the same language
|
||||||
return Promise.resolve(setI18nLanguage(lang))
|
i18n.locale === lang ||
|
||||||
}
|
// If the language was already loaded
|
||||||
|
loadedLanguages.includes(lang)
|
||||||
// If the language was already loaded
|
) {
|
||||||
if (loadedLanguages.includes(lang)) {
|
return setI18nLanguage(lang)
|
||||||
return Promise.resolve(setI18nLanguage(lang))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the language hasn't been loaded yet
|
// If the language hasn't been loaded yet
|
||||||
|
|
|
@ -295,7 +295,7 @@ export default class AbstractService {
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const result = this.modelGetFactory(response.data)
|
const result = this.modelGetFactory(response.data)
|
||||||
result.maxRight = Number(response.headers['x-max-right'])
|
result.maxRight = Number(response.headers['x-max-right'])
|
||||||
return Promise.resolve(result)
|
return result
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -338,14 +338,12 @@ export default class AbstractService {
|
||||||
this.totalPages = Number(response.headers['x-pagination-total-pages'])
|
this.totalPages = Number(response.headers['x-pagination-total-pages'])
|
||||||
|
|
||||||
if (Array.isArray(response.data)) {
|
if (Array.isArray(response.data)) {
|
||||||
return Promise.resolve(response.data.map(entry => {
|
return response.data.map(entry => this.modelGetAllFactory(entry))
|
||||||
return this.modelGetAllFactory(entry)
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
if (response.data === null) {
|
if (response.data === null) {
|
||||||
return Promise.resolve([])
|
return []
|
||||||
}
|
}
|
||||||
return Promise.resolve(this.modelGetAllFactory(response.data))
|
return this.modelGetAllFactory(response.data)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -371,7 +369,7 @@ export default class AbstractService {
|
||||||
if (typeof model.maxRight !== 'undefined') {
|
if (typeof model.maxRight !== 'undefined') {
|
||||||
result.maxRight = model.maxRight
|
result.maxRight = model.maxRight
|
||||||
}
|
}
|
||||||
return Promise.resolve(result)
|
return result
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -394,7 +392,7 @@ export default class AbstractService {
|
||||||
if (typeof model.maxRight !== 'undefined') {
|
if (typeof model.maxRight !== 'undefined') {
|
||||||
result.maxRight = model.maxRight
|
result.maxRight = model.maxRight
|
||||||
}
|
}
|
||||||
return Promise.resolve(result)
|
return result
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -420,7 +418,7 @@ export default class AbstractService {
|
||||||
* @param model
|
* @param model
|
||||||
* @returns {Q.Promise<any>}
|
* @returns {Q.Promise<any>}
|
||||||
*/
|
*/
|
||||||
delete(model) {
|
async delete(model) {
|
||||||
if (this.paths.delete === '') {
|
if (this.paths.delete === '') {
|
||||||
throw new Error('This model is not able to delete data.')
|
throw new Error('This model is not able to delete data.')
|
||||||
}
|
}
|
||||||
|
@ -428,13 +426,12 @@ export default class AbstractService {
|
||||||
const cancel = this.setLoading()
|
const cancel = this.setLoading()
|
||||||
const finalUrl = this.getReplacedRoute(this.paths.delete, model)
|
const finalUrl = this.getReplacedRoute(this.paths.delete, model)
|
||||||
|
|
||||||
return this.http.delete(finalUrl, model)
|
try {
|
||||||
.then(response => {
|
const {data} = await this.http.delete(finalUrl, model)
|
||||||
return Promise.resolve(response.data)
|
return data
|
||||||
})
|
} finally {
|
||||||
.finally(() => {
|
cancel()
|
||||||
cancel()
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -485,9 +482,7 @@ export default class AbstractService {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => this.modelCreateFactory(response.data))
|
||||||
return Promise.resolve(this.modelCreateFactory(response.data))
|
|
||||||
})
|
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.uploadProgress = 0
|
this.uploadProgress = 0
|
||||||
cancel()
|
cancel()
|
||||||
|
|
|
@ -37,9 +37,9 @@ export default class AttachmentService extends AbstractService {
|
||||||
return AbstractService.prototype.getBlobUrl.call(this, '/tasks/' + model.taskId + '/attachments/' + model.id)
|
return AbstractService.prototype.getBlobUrl.call(this, '/tasks/' + model.taskId + '/attachments/' + model.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
download(model) {
|
async download(model) {
|
||||||
this.getBlobUrl(model)
|
const url = await this.getBlobUrl(model)
|
||||||
.then(url => downloadBlob(url, model.file.name))
|
return downloadBlob(url, model.file.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,7 @@ export default class ListService extends AbstractService {
|
||||||
|
|
||||||
background(list) {
|
background(list) {
|
||||||
if (list.background === null) {
|
if (list.background === null) {
|
||||||
return Promise.resolve('')
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.http({
|
return this.http({
|
||||||
|
|
|
@ -19,7 +19,7 @@ export default class PasswordResetService extends AbstractService {
|
||||||
const cancel = this.setLoading()
|
const cancel = this.setLoading()
|
||||||
return this.http.post(this.paths.reset, model)
|
return this.http.post(this.paths.reset, model)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return Promise.resolve(this.modelFactory(response.data))
|
return this.modelFactory(response.data)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -30,7 +30,7 @@ export default class PasswordResetService extends AbstractService {
|
||||||
const cancel = this.setLoading()
|
const cancel = this.setLoading()
|
||||||
return this.http.post(this.paths.requestReset, model)
|
return this.http.post(this.paths.requestReset, model)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return Promise.resolve(this.modelFactory(response.data))
|
return this.modelFactory(response.data)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
cancel()
|
cancel()
|
||||||
|
|
|
@ -26,13 +26,12 @@ export default class TotpService extends AbstractService {
|
||||||
return this.post(`${this.urlPrefix}/disable`, model)
|
return this.post(`${this.urlPrefix}/disable`, model)
|
||||||
}
|
}
|
||||||
|
|
||||||
qrcode() {
|
async qrcode() {
|
||||||
return this.http({
|
const response = await this.http({
|
||||||
url: `${this.urlPrefix}/qrcode`,
|
url: `${this.urlPrefix}/qrcode`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
}).then(response => {
|
|
||||||
return Promise.resolve(new Blob([response.data]))
|
|
||||||
})
|
})
|
||||||
|
return new Blob([response.data])
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -101,17 +101,17 @@ export default {
|
||||||
|
|
||||||
// Tell others the user is autheticated
|
// Tell others the user is autheticated
|
||||||
ctx.dispatch('checkAuth')
|
ctx.dispatch('checkAuth')
|
||||||
return Promise.resolve()
|
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
if (e.response) {
|
if (
|
||||||
if (e.response.data.code === 1017 && !credentials.totpPasscode) {
|
e.response &&
|
||||||
ctx.commit('needsTotpPasscode', true)
|
e.response.data.code === 1017 &&
|
||||||
return Promise.reject(e)
|
!credentials.totpPasscode
|
||||||
}
|
) {
|
||||||
|
ctx.commit('needsTotpPasscode', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
ctx.commit(LOADING, false, {root: true})
|
ctx.commit(LOADING, false, {root: true})
|
||||||
|
@ -134,7 +134,7 @@ export default {
|
||||||
ctx.commit(ERROR_MESSAGE, e.response.data.message, {root: true})
|
ctx.commit(ERROR_MESSAGE, e.response.data.message, {root: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
ctx.commit(LOADING, false, {root: true})
|
ctx.commit(LOADING, false, {root: true})
|
||||||
|
@ -157,7 +157,6 @@ export default {
|
||||||
|
|
||||||
// Tell others the user is autheticated
|
// Tell others the user is autheticated
|
||||||
ctx.dispatch('checkAuth')
|
ctx.dispatch('checkAuth')
|
||||||
return Promise.resolve()
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
ctx.commit(LOADING, false, {root: true})
|
ctx.commit(LOADING, false, {root: true})
|
||||||
|
@ -180,7 +179,7 @@ export default {
|
||||||
// This function can be called from multiple places at the same time and shortly after one another.
|
// This function can be called from multiple places at the same time and shortly after one another.
|
||||||
// To prevent hitting the api too frequently or race conditions, we check at most once per minute.
|
// To prevent hitting the api too frequently or race conditions, we check at most once per minute.
|
||||||
if (ctx.state.lastUserInfoRefresh !== null && ctx.state.lastUserInfoRefresh > (new Date()).setMinutes((new Date()).getMinutes() + 1)) {
|
if (ctx.state.lastUserInfoRefresh !== null && ctx.state.lastUserInfoRefresh > (new Date()).setMinutes((new Date()).getMinutes() + 1)) {
|
||||||
return Promise.resolve()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const jwt = getToken()
|
const jwt = getToken()
|
||||||
|
@ -190,14 +189,13 @@ export default {
|
||||||
.split('.')[1]
|
.split('.')[1]
|
||||||
.replace('-', '+')
|
.replace('-', '+')
|
||||||
.replace('_', '/')
|
.replace('_', '/')
|
||||||
const info = new UserModel(JSON.parse(window.atob(base64)))
|
const info = new UserModel(JSON.parse(atob(base64)))
|
||||||
const ts = Math.round((new Date()).getTime() / 1000)
|
const ts = Math.round((new Date()).getTime() / 1000)
|
||||||
authenticated = info.exp >= ts
|
authenticated = info.exp >= ts
|
||||||
ctx.commit('info', info)
|
ctx.commit('info', info)
|
||||||
|
|
||||||
if (authenticated) {
|
if (authenticated) {
|
||||||
ctx.dispatch('refreshUserInfo')
|
ctx.dispatch('refreshUserInfo')
|
||||||
ctx.commit('authenticated', authenticated)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,8 +204,6 @@ export default {
|
||||||
ctx.commit('info', null)
|
ctx.commit('info', null)
|
||||||
ctx.dispatch('config/redirectToProviderIfNothingElseIsEnabled', null, {root: true})
|
ctx.dispatch('config/redirectToProviderIfNothingElseIsEnabled', null, {root: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve()
|
|
||||||
},
|
},
|
||||||
refreshUserInfo(ctx) {
|
refreshUserInfo(ctx) {
|
||||||
const jwt = getToken()
|
const jwt = getToken()
|
||||||
|
|
|
@ -66,7 +66,7 @@ export default {
|
||||||
return HTTP.get('info')
|
return HTTP.get('info')
|
||||||
.then(r => {
|
.then(r => {
|
||||||
ctx.commit(CONFIG, r.data)
|
ctx.commit(CONFIG, r.data)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
redirectToProviderIfNothingElseIsEnabled(ctx) {
|
redirectToProviderIfNothingElseIsEnabled(ctx) {
|
||||||
|
|
|
@ -227,19 +227,19 @@ export default {
|
||||||
.finally(() => cancel())
|
.finally(() => cancel())
|
||||||
},
|
},
|
||||||
|
|
||||||
loadNextTasksForBucket(ctx, {listId, ps = {}, bucketId}) {
|
async loadNextTasksForBucket(ctx, {listId, ps = {}, bucketId}) {
|
||||||
const bucketIndex = findIndexById(ctx.state.buckets, bucketId)
|
const bucketIndex = findIndexById(ctx.state.buckets, bucketId)
|
||||||
|
|
||||||
const isLoading = ctx.state.bucketLoading[bucketIndex] ?? false
|
const isLoading = ctx.state.bucketLoading[bucketIndex] ?? false
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return Promise.resolve()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = (ctx.state.taskPagesPerBucket[bucketIndex] ?? 1) + 1
|
const page = (ctx.state.taskPagesPerBucket[bucketIndex] ?? 1) + 1
|
||||||
|
|
||||||
const alreadyLoaded = ctx.state.allTasksLoadedForBucket[bucketIndex] ?? false
|
const alreadyLoaded = ctx.state.allTasksLoadedForBucket[bucketIndex] ?? false
|
||||||
if (alreadyLoaded) {
|
if (alreadyLoaded) {
|
||||||
return Promise.resolve()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const cancel = setLoading(ctx, 'kanban')
|
const cancel = setLoading(ctx, 'kanban')
|
||||||
|
@ -334,7 +334,7 @@ export default {
|
||||||
// restore original state
|
// restore original state
|
||||||
ctx.commit('setBucketByIndex', {bucketIndex, bucket: oldBucket})
|
ctx.commit('setBucketByIndex', {bucketIndex, bucket: oldBucket})
|
||||||
|
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.finally(() => cancel())
|
.finally(() => cancel())
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import LabelService from '@/services/label'
|
import LabelService from '@/services/label'
|
||||||
import {setLoading} from '@/store/helper'
|
import {setLoading} from '@/store/helper'
|
||||||
|
import { success } from '@/message'
|
||||||
|
import {i18n} from '@/i18n'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the labels by id if found
|
* Returns the labels by id if found
|
||||||
|
@ -28,6 +30,18 @@ function getLabelsByIds(state, ids) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const labelService = new LabelService()
|
||||||
|
|
||||||
|
const getAllLabels = async (page = 1) => {
|
||||||
|
const labels = await labelService.getAll({}, {}, page)
|
||||||
|
if (page < labelService.totalPages) {
|
||||||
|
const nextLabels = await getAllLabels(page + 1)
|
||||||
|
return labels.concat(nextLabels)
|
||||||
|
} else {
|
||||||
|
return labels
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
@ -60,71 +74,59 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
loadAllLabels(ctx, {forceLoad} = {}) {
|
async loadAllLabels(ctx, {forceLoad} = {}) {
|
||||||
if (ctx.state.loaded && !forceLoad) {
|
if (ctx.state.loaded && !forceLoad) {
|
||||||
return Promise.resolve()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const cancel = setLoading(ctx, 'labels')
|
const cancel = setLoading(ctx, 'labels')
|
||||||
const labelService = new LabelService()
|
|
||||||
|
|
||||||
const getAllLabels = (page = 1) => {
|
try {
|
||||||
return labelService.getAll({}, {}, page)
|
const labels = await getAllLabels()
|
||||||
.then(labels => {
|
ctx.commit('setLabels', labels)
|
||||||
if (page < labelService.totalPages) {
|
ctx.commit('setLoaded', true)
|
||||||
return getAllLabels(page + 1)
|
return labels
|
||||||
.then(nextLabels => {
|
} finally {
|
||||||
return labels.concat(nextLabels)
|
cancel()
|
||||||
})
|
|
||||||
} else {
|
|
||||||
return labels
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(e => {
|
|
||||||
return Promise.reject(e)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return getAllLabels()
|
|
||||||
.then(r => {
|
|
||||||
ctx.commit('setLabels', r)
|
|
||||||
ctx.commit('setLoaded', true)
|
|
||||||
return Promise.resolve(r)
|
|
||||||
})
|
|
||||||
.finally(() => cancel())
|
|
||||||
},
|
},
|
||||||
deleteLabel(ctx, label) {
|
async deleteLabel(ctx, label) {
|
||||||
const cancel = setLoading(ctx, 'labels')
|
const cancel = setLoading(ctx, 'labels')
|
||||||
const labelService = new LabelService()
|
const labelService = new LabelService()
|
||||||
|
|
||||||
return labelService.delete(label)
|
try {
|
||||||
.then(r => {
|
const result = await labelService.delete(label)
|
||||||
ctx.commit('removeLabelById', label)
|
ctx.commit('removeLabelById', label)
|
||||||
return Promise.resolve(r)
|
success({message: i18n.global.t('label.deleteSuccess')})
|
||||||
})
|
return result
|
||||||
.finally(() => cancel())
|
} finally {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
updateLabel(ctx, label) {
|
async updateLabel(ctx, label) {
|
||||||
const cancel = setLoading(ctx, 'labels')
|
const cancel = setLoading(ctx, 'labels')
|
||||||
const labelService = new LabelService()
|
const labelService = new LabelService()
|
||||||
|
|
||||||
return labelService.update(label)
|
try {
|
||||||
.then(r => {
|
const newLabel = await labelService.update(label)
|
||||||
ctx.commit('setLabel', r)
|
ctx.commit('setLabel', newLabel)
|
||||||
return Promise.resolve(r)
|
success({message: i18n.global.t('label.edit.success')})
|
||||||
})
|
return newLabel
|
||||||
.finally(() => cancel())
|
} finally {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
createLabel(ctx, label) {
|
async createLabel(ctx, label) {
|
||||||
const cancel = setLoading(ctx, 'labels')
|
const cancel = setLoading(ctx, 'labels')
|
||||||
const labelService = new LabelService()
|
const labelService = new LabelService()
|
||||||
|
|
||||||
return labelService.create(label)
|
try {
|
||||||
.then(r => {
|
const newLabel = await labelService.create(label)
|
||||||
ctx.commit('setLabel', r)
|
ctx.commit('setLabel', newLabel)
|
||||||
return Promise.resolve(r)
|
return newLabel
|
||||||
})
|
} finally {
|
||||||
.finally(() => cancel())
|
cancel()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ export default {
|
||||||
r.namespaceId = list.namespaceId
|
r.namespaceId = list.namespaceId
|
||||||
ctx.commit('namespaces/addListToNamespace', r, {root: true})
|
ctx.commit('namespaces/addListToNamespace', r, {root: true})
|
||||||
ctx.commit('setList', r)
|
ctx.commit('setList', r)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
})
|
})
|
||||||
.finally(() => cancel())
|
.finally(() => cancel())
|
||||||
},
|
},
|
||||||
|
@ -77,7 +77,7 @@ export default {
|
||||||
}
|
}
|
||||||
ctx.dispatch('namespaces/loadNamespacesIfFavoritesDontExist', null, {root: true})
|
ctx.dispatch('namespaces/loadNamespacesIfFavoritesDontExist', null, {root: true})
|
||||||
ctx.dispatch('namespaces/removeFavoritesNamespaceIfEmpty', null, {root: true})
|
ctx.dispatch('namespaces/removeFavoritesNamespaceIfEmpty', null, {root: true})
|
||||||
return Promise.resolve(newList)
|
return newList
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
// Reset the list state to the initial one to avoid confusion for the user
|
// Reset the list state to the initial one to avoid confusion for the user
|
||||||
|
@ -85,7 +85,7 @@ export default {
|
||||||
...list,
|
...list,
|
||||||
isFavorite: !list.isFavorite,
|
isFavorite: !list.isFavorite,
|
||||||
})
|
})
|
||||||
return Promise.reject(e)
|
throw e
|
||||||
})
|
})
|
||||||
.finally(() => cancel())
|
.finally(() => cancel())
|
||||||
},
|
},
|
||||||
|
|
|
@ -113,7 +113,7 @@ export default {
|
||||||
|
|
||||||
ctx.commit('lists/setLists', lists, {root: true})
|
ctx.commit('lists/setLists', lists, {root: true})
|
||||||
|
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -128,7 +128,6 @@ export default {
|
||||||
removeFavoritesNamespaceIfEmpty(ctx) {
|
removeFavoritesNamespaceIfEmpty(ctx) {
|
||||||
if (ctx.state.namespaces[0].id === -2 && ctx.state.namespaces[0].lists.length === 0) {
|
if (ctx.state.namespaces[0].id === -2 && ctx.state.namespaces[0].lists.length === 0) {
|
||||||
ctx.state.namespaces.splice(0, 1)
|
ctx.state.namespaces.splice(0, 1)
|
||||||
return Promise.resolve()
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteNamespace(ctx, namespace) {
|
deleteNamespace(ctx, namespace) {
|
||||||
|
@ -138,7 +137,7 @@ export default {
|
||||||
return namespaceService.delete(namespace)
|
return namespaceService.delete(namespace)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
ctx.commit('removeNamespaceById', namespace.id)
|
ctx.commit('removeNamespaceById', namespace.id)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
})
|
})
|
||||||
.finally(() => cancel())
|
.finally(() => cancel())
|
||||||
},
|
},
|
||||||
|
@ -149,7 +148,7 @@ export default {
|
||||||
return namespaceService.create(namespace)
|
return namespaceService.create(namespace)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
ctx.commit('addNamespace', r)
|
ctx.commit('addNamespace', r)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
})
|
})
|
||||||
.finally(() => cancel())
|
.finally(() => cancel())
|
||||||
},
|
},
|
||||||
|
|
|
@ -43,23 +43,23 @@ function addLabelToTask(task, label) {
|
||||||
return labelTaskService.create(labelTask)
|
return labelTaskService.create(labelTask)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
task.labels.push(label)
|
task.labels.push(label)
|
||||||
return Promise.resolve(result)
|
return result
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function findAssignees(parsedTaskAssignees) {
|
async function findAssignees(parsedTaskAssignees) {
|
||||||
if (parsedTaskAssignees.length <= 0) {
|
if (parsedTaskAssignees.length <= 0) {
|
||||||
return Promise.resolve([])
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
const userService = new UserService()
|
const userService = new UserService()
|
||||||
const assignees = parsedTaskAssignees.map(a =>
|
const assignees = parsedTaskAssignees.map(async a => {
|
||||||
userService.getAll({}, {s: a})
|
const users = await userService.getAll({}, {s: a})
|
||||||
.then(users => validateUsername(users, a)),
|
return validateUsername(users, a)
|
||||||
|
})
|
||||||
)
|
|
||||||
|
|
||||||
return Promise.all(assignees).filter((item) => Boolean(item))
|
const validatedUsers = await Promise.all(assignees)
|
||||||
|
return validatedUsers.filter((item) => Boolean(item))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ export default {
|
||||||
// Usually this means the kanban board hasn't been accessed until now.
|
// Usually this means the kanban board hasn't been accessed until now.
|
||||||
// Vuex seems to have its difficulties with that, so we just log the error and fail silently.
|
// Vuex seems to have its difficulties with that, so we just log the error and fail silently.
|
||||||
console.debug('Could not add assignee to task in kanban, task not found', t)
|
console.debug('Could not add assignee to task in kanban, task not found', t)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
}
|
}
|
||||||
// FIXME: direct store manipulation (task)
|
// FIXME: direct store manipulation (task)
|
||||||
t.task.assignees.push(user)
|
t.task.assignees.push(user)
|
||||||
|
@ -157,7 +157,7 @@ export default {
|
||||||
// Usually this means the kanban board hasn't been accessed until now.
|
// Usually this means the kanban board hasn't been accessed until now.
|
||||||
// Vuex seems to have its difficulties with that, so we just log the error and fail silently.
|
// Vuex seems to have its difficulties with that, so we just log the error and fail silently.
|
||||||
console.debug('Could not remove assignee from task in kanban, task not found', t)
|
console.debug('Could not remove assignee from task in kanban, task not found', t)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const a in t.task.assignees) {
|
for (const a in t.task.assignees) {
|
||||||
|
@ -186,7 +186,7 @@ export default {
|
||||||
// Usually this means the kanban board hasn't been accessed until now.
|
// Usually this means the kanban board hasn't been accessed until now.
|
||||||
// Vuex seems to have its difficulties with that, so we just log the error and fail silently.
|
// Vuex seems to have its difficulties with that, so we just log the error and fail silently.
|
||||||
console.debug('Could not add label to task in kanban, task not found', t)
|
console.debug('Could not add label to task in kanban, task not found', t)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
}
|
}
|
||||||
// FIXME: direct store manipulation (task)
|
// FIXME: direct store manipulation (task)
|
||||||
t.task.labels.push(label)
|
t.task.labels.push(label)
|
||||||
|
@ -208,7 +208,7 @@ export default {
|
||||||
// Usually this means the kanban board hasn't been accessed until now.
|
// Usually this means the kanban board hasn't been accessed until now.
|
||||||
// Vuex seems to have its difficulties with that, so we just log the error and fail silently.
|
// Vuex seems to have its difficulties with that, so we just log the error and fail silently.
|
||||||
console.debug('Could not remove label from task in kanban, task not found', t)
|
console.debug('Could not remove label from task in kanban, task not found', t)
|
||||||
return Promise.resolve(r)
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the label from the list
|
// Remove the label from the list
|
||||||
|
@ -234,22 +234,21 @@ export default {
|
||||||
|
|
||||||
const {labels} = rootState.labels
|
const {labels} = rootState.labels
|
||||||
|
|
||||||
const labelAddsToWaitFor = parsedLabels.map(labelTitle => new Promise((resolve) => {
|
const labelAddsToWaitFor = parsedLabels.map(async labelTitle => {
|
||||||
let label = validateLabel(labels, labelTitle)
|
let label = validateLabel(labels, labelTitle)
|
||||||
if (typeof label !== 'undefined') {
|
if (typeof label !== 'undefined') {
|
||||||
return resolve(label)
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
// label not found, create it
|
// label not found, create it
|
||||||
const labelModel = new LabelModel({title: labelTitle})
|
const labelModel = new LabelModel({title: labelTitle})
|
||||||
return dispatch('labels/createLabel', labelModel).then(() => resolve(label))
|
await dispatch('labels/createLabel', labelModel)
|
||||||
|
addLabelToTask(task, label)
|
||||||
})
|
})
|
||||||
.then((label) => addLabelToTask(task, label))
|
|
||||||
.catch(e => Promise.reject(e)),
|
|
||||||
)
|
|
||||||
|
|
||||||
// This waits until all labels are created and added to the task
|
// This waits until all labels are created and added to the task
|
||||||
return Promise.all(labelAddsToWaitFor).then(() => task)
|
await Promise.all(labelAddsToWaitFor)
|
||||||
|
return task
|
||||||
},
|
},
|
||||||
|
|
||||||
findListId({ rootGetters }, { list, listId }) {
|
findListId({ rootGetters }, { list, listId }) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.loadLabels()
|
this.$store.dispatch('labels/loadAllLabels')
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.setTitle(this.$t('label.title'))
|
this.setTitle(this.$t('label.title'))
|
||||||
|
@ -131,20 +131,11 @@ export default {
|
||||||
loading: state => state[LOADING] && state[LOADING_MODULE] === 'labels',
|
loading: state => state[LOADING] && state[LOADING_MODULE] === 'labels',
|
||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
loadLabels() {
|
|
||||||
this.$store.dispatch('labels/loadAllLabels')
|
|
||||||
},
|
|
||||||
deleteLabel(label) {
|
deleteLabel(label) {
|
||||||
this.$store.dispatch('labels/deleteLabel', label)
|
return this.$store.dispatch('labels/deleteLabel', label)
|
||||||
.then(() => {
|
|
||||||
this.$message.success({message: this.$t('label.deleteSuccess')})
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
editLabelSubmit() {
|
editLabelSubmit() {
|
||||||
this.$store.dispatch('labels/updateLabel', this.labelEditLabel)
|
return this.$store.dispatch('labels/updateLabel', this.labelEditLabel)
|
||||||
.then(() => {
|
|
||||||
this.$message.success({message: this.$t('label.edit.success')})
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
editLabel(label) {
|
editLabel(label) {
|
||||||
if (label.createdBy.id !== this.userInfo.id) {
|
if (label.createdBy.id !== this.userInfo.id) {
|
||||||
|
|
Loading…
Reference in a new issue