TT#95600 Improve api methods

Change-Id: If3223cadc11c034591fa539401aeff84f9a1ea0d
mr9.1.1
Hans-Peter Herzog 5 years ago
parent 6f52bb20b0
commit e24a029a7e

@ -4,7 +4,7 @@ import Vue from 'vue'
import { i18n } from 'src/boot/i18n' import { i18n } from 'src/boot/i18n'
import { getJsonBody } from './utils' import { getJsonBody } from './utils'
import { normalizeDestination } from '../filters/number-format' import { normalizeDestination } from '../filters/number-format'
import { LIST_ALL_ROWS, patchReplaceFull, get, getList } from './common' import { LIST_ALL_ROWS, patchReplaceFull, get, getList, del } from './common'
export function getMappings (id) { export function getMappings (id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -613,36 +613,157 @@ export function convertTimesetToWeekdays (options) {
} }
} }
export function loadTimesetTimes (options) { function convertToTimes (times) {
return new Promise((resolve, reject) => { return times.reduce((timesConverted, time) => {
Promise.resolve().then(() => { const hourParts = time.hour.split('-')
return getTimesets(options.subscriberId) let minuteParts = null
}).then((timesets) => { if (time.minute !== null && time.minute !== '') {
const times = convertTimesetToWeekdays({ timesets: timesets, timesetName: options.timeset }) minuteParts = time.minute.split('-')
return times }
}).then((times) => { if (hourParts.length === 1 && minuteParts === null) {
resolve(times) timesConverted.push({
}).catch((err) => { from: normalizeTimePart(hourParts[0]) + ':00',
reject(err) to: normalizeTimePart(hourParts[0]) + ':00',
}) weekday: parseInt(time.wday)
})
} else if (hourParts.length === 1 && minuteParts !== null && minuteParts.length === 1) {
timesConverted.push({
from: normalizeTimePart(hourParts[0]) + ':' + normalizeTimePart(minuteParts[0]),
to: normalizeTimePart(hourParts[0]) + ':' + normalizeTimePart(minuteParts[0]),
weekday: parseInt(time.wday)
})
} else if (hourParts.length === 1 && minuteParts !== null && minuteParts.length === 2) {
timesConverted.push({
from: normalizeTimePart(hourParts[0]) + ':' + normalizeTimePart(minuteParts[0]),
to: normalizeTimePart(hourParts[0]) + ':' + normalizeTimePart(minuteParts[1]),
weekday: parseInt(time.wday)
})
} else if (hourParts.length === 2 && minuteParts === null) {
timesConverted.push({
from: normalizeTimePart(hourParts[0]) + ':00',
to: normalizeTimePart(hourParts[1]) + ':00',
weekday: parseInt(time.wday)
})
} else if (hourParts.length === 2 && minuteParts !== null && minuteParts.length === 1) {
timesConverted.push({
from: normalizeTimePart(hourParts[0]) + ':' + normalizeTimePart(minuteParts[0]),
to: normalizeTimePart(hourParts[1]) + ':' + normalizeTimePart(minuteParts[0]),
weekday: parseInt(time.wday)
})
} else if (hourParts.length === 2 && minuteParts !== null && minuteParts.length === 2) {
timesConverted.push({
from: normalizeTimePart(hourParts[0]) + ':' + normalizeTimePart(minuteParts[0]),
to: normalizeTimePart(hourParts[1]) + ':' + normalizeTimePart(minuteParts[1]),
weekday: parseInt(time.wday)
})
} else if (hourParts.length === 2 && minuteParts !== null && minuteParts.length === 2) {
timesConverted.push({
from: normalizeTimePart(hourParts[0]) + ':' + normalizeTimePart(minuteParts[0]),
to: normalizeTimePart(hourParts[1]) + ':' + normalizeTimePart(minuteParts[1]),
weekday: parseInt(time.wday)
}) })
}
return timesConverted
}, [])
} }
export function deleteTimeFromTimeset (options) { function normalizeTimePart (part) {
const headers = { if (part.length === 1) {
'Content-Type': 'application/json-patch+json' return '0' + part
} else {
return part
} }
return new Promise((resolve, reject) => { }
Vue.http.patch('api/cftimesets/' + options.timesetId, [{
op: 'replace', export async function loadTimesetTimes (options) {
path: '/times', const timesets = await getTimesets(options.subscriberId)
value: options.times const filteredTimesets = timesets.filter(timeset => timeset.name === options.timeset)
}], { headers: headers }).then((result) => { if (filteredTimesets.length === 1) {
resolve(result) return {
}).catch((err) => { times: convertToTimes(filteredTimesets[0].times),
reject(err) timesetIsCompatible: true,
timesetExists: filteredTimesets.length === 1,
timesetHasReverse: false,
timesetHasDuplicate: filteredTimesets.length > 1,
timesetId: filteredTimesets[0].id
}
} else {
return {
times: [],
timesetIsCompatible: true,
timesetExists: false,
timesetHasReverse: false,
timesetHasDuplicate: false,
timesetId: null
}
}
}
export async function appendTimeToTimeset (options) {
const timeset = await get({
resource: 'cftimesets',
resourceId: options.timesetId
})
const times = _.cloneDeep(timeset.times)
times.push(options.time)
const updatedTimeset = await patchReplaceFull({
resource: 'cftimesets',
resourceId: options.timesetId,
fieldPath: 'times',
value: times
}) })
return {
times: convertToTimes(updatedTimeset.times),
timesetIsCompatible: true,
timesetExists: true,
timesetHasReverse: false,
timesetHasDuplicate: false,
timesetId: updatedTimeset.id
}
}
/**
* Removes a specific time from a given timeset
* @param options
* @param options.timesetId
* @param options.timeId
* @returns {Promise<void>}
*/
export async function deleteTimeFromTimeset (options) {
const timeset = await get({
resource: 'cftimesets',
resourceId: options.timesetId
})
const updatedTimes = timeset.times.filter((time, index) => index !== options.timeId)
if (updatedTimes.length === 0) {
await del({
resource: 'cftimesets',
resourceId: options.timesetId
}) })
return {
times: null,
timesetIsCompatible: true,
timesetExists: false,
timesetHasReverse: false,
timesetHasDuplicate: false,
timesetId: null
}
} else {
const updatedTimeset = await patchReplaceFull({
resource: 'cftimesets',
resourceId: options.timesetId,
fieldPath: 'times',
value: updatedTimes
})
return {
times: convertToTimes(updatedTimeset.times),
timesetIsCompatible: true,
timesetExists: true,
timesetHasReverse: false,
timesetHasDuplicate: false,
timesetId: updatedTimeset.id
}
}
} }
export function deleteTimesetById (id) { export function deleteTimesetById (id) {
@ -767,22 +888,6 @@ export function getTimesByTimesetId (id) {
}) })
} }
export function appendTimeToTimeset (options) {
return new Promise((resolve, reject) => {
const convertedTime = convertAddTime({ time: options.time[0], weekday: options.weekday })
Promise.resolve().then(() => {
return getTimesByTimesetId(options.id)
}).then((times) => {
const concatTimes = times.concat(convertedTime)
return addTimeToTimeset({ id: options.id, times: concatTimes })
}).then(() => {
resolve()
}).catch((err) => {
reject(err)
})
})
}
export function getSourcesetById (id) { export function getSourcesetById (id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
Vue.http.get('api/cfsourcesets/' + id).then((res) => { Vue.http.get('api/cfsourcesets/' + id).then((res) => {

@ -27,8 +27,7 @@ export class ApiResponseError extends Error {
} }
} }
export function getList (options) { export async function getList (options) {
return new Promise((resolve, reject) => {
options = options || {} options = options || {}
options = _.merge({ options = _.merge({
all: false, all: false,
@ -38,28 +37,33 @@ export function getList (options) {
}, },
headers: GET_HEADERS headers: GET_HEADERS
}, options) }, options)
Promise.resolve().then(() => {
if (options.all === true) { if (options.all === true) {
options.params.rows = LIST_ALL_ROWS options.params.rows = LIST_ALL_ROWS
} }
return Vue.http.get(options.path, { if (options.resource !== undefined) {
options.path = 'api/' + options.resource
options.root = '_embedded.ngcp:' + options.resource
}
const firstRes = await Vue.http.get(options.path, {
params: options.params, params: options.params,
headers: options.headers headers: options.headers
}) })
}).then((res) => { let secondRes = null
const body = getJsonBody(res.body) const firstResBody = getJsonBody(firstRes.body)
if (options.all === true && body.total_count > LIST_ALL_ROWS) { if (options.all === true && firstResBody.total_count > LIST_ALL_ROWS) {
return Vue.http.get(options.path, { secondRes = await Vue.http.get(options.path, {
params: _.merge(options.params, { params: _.merge(options.params, {
rows: body.total_count rows: firstResBody.total_count
}), }),
headers: options.headers headers: options.headers
}) })
} else {
return Promise.resolve(res)
} }
}).then((res) => { let res = firstRes
const body = getJsonBody(res.body) let body = firstResBody
if (secondRes !== null) {
res = secondRes
body = getJsonBody(res.body)
}
const totalCount = _.get(body, 'total_count', 0) const totalCount = _.get(body, 'total_count', 0)
let lastPage = Math.ceil(totalCount / options.params.rows) let lastPage = Math.ceil(totalCount / options.params.rows)
if (options.all === true) { if (options.all === true) {
@ -72,18 +76,13 @@ export function getList (options) {
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
items[i] = normalizeEntity(items[i]) items[i] = normalizeEntity(items[i])
} }
resolve({ return {
items: items, items: items,
lastPage: lastPage lastPage: lastPage
}) }
}).catch((err) => {
reject(err)
})
})
} }
export function get (options) { export async function get (options) {
return new Promise((resolve, reject) => {
options = options || {} options = options || {}
options = _.merge({ options = _.merge({
headers: GET_HEADERS headers: GET_HEADERS
@ -95,28 +94,31 @@ export function get (options) {
if (options.blob === true) { if (options.blob === true) {
requestOptions.responseType = 'blob' requestOptions.responseType = 'blob'
} }
return Vue.http.get(options.path, requestOptions).then((result) => { let path = options.path
if (options.resource !== undefined && options.resourceId !== undefined) {
path = 'api/' + options.resource + '/' + options.resourceId
}
try {
const res = await Vue.http.get(path, requestOptions)
let body = null let body = null
if (options.blob === true) { if (options.blob === true) {
body = URL.createObjectURL(result.body) body = URL.createObjectURL(res.body)
} else { } else {
body = normalizeEntity(getJsonBody(result.body)) body = normalizeEntity(getJsonBody(res.body))
} }
resolve(body) return body
}).catch((err) => { } catch (err) {
const code = _.get(err, 'body.code', null) const code = _.get(err, 'body.code', null)
const message = _.get(err, 'body.message', null) const message = _.get(err, 'body.message', null)
if (code !== null && message !== null) { if (code !== null && message !== null) {
reject(new ApiResponseError(err.body.code, err.body.message)) throw new ApiResponseError(err.body.code, err.body.message)
} else { } else {
reject(err) throw err
}
} }
})
})
} }
export function patch (operation, options) { export async function patch (operation, options) {
return new Promise((resolve, reject) => {
options = options || {} options = options || {}
options = _.merge({ options = _.merge({
headers: PATCH_HEADERS headers: PATCH_HEADERS
@ -128,20 +130,23 @@ export function patch (operation, options) {
if (options.value !== undefined) { if (options.value !== undefined) {
body.value = options.value body.value = options.value
} }
Vue.http.patch(options.path, [body], { let path = options.path
if (options.resource !== undefined && options.resourceId !== undefined) {
path = 'api/' + options.resource + '/' + options.resourceId
}
try {
return await Vue.http.patch(path, [body], {
headers: options.headers headers: options.headers
}).then((result) => { })
resolve(result) } catch (err) {
}).catch((err) => {
const code = _.get(err, 'body.code', null) const code = _.get(err, 'body.code', null)
const message = _.get(err, 'body.message', null) const message = _.get(err, 'body.message', null)
if (code !== null && message !== null) { if (code !== null && message !== null) {
reject(new ApiResponseError(err.body.code, err.body.message)) throw new ApiResponseError(err.body.code, err.body.message)
} else { } else {
reject(err) throw err
}
} }
})
})
} }
export function patchReplace (options) { export function patchReplace (options) {
@ -156,20 +161,15 @@ export function patchRemove (options) {
return patch('remove', options) return patch('remove', options)
} }
export function patchFull (operation, options) { export async function patchFull (operation, options) {
return new Promise((resolve, reject) => {
options = options || {} options = options || {}
options = _.merge(options, { options = _.merge(options, {
headers: { headers: {
Prefer: 'return=representation' Prefer: 'return=representation'
} }
}) })
patch(operation, options).then((result) => { const res = await patch(operation, options)
resolve(getJsonBody(result.body)) return normalizeEntity(getJsonBody(res.body))
}).catch((err) => {
reject(err)
})
})
} }
export function patchReplaceFull (options) { export function patchReplaceFull (options) {
@ -184,6 +184,32 @@ export function patchRemoveFull (options) {
return patchFull('remove', options) return patchFull('remove', options)
} }
export async function del (options) {
options = options || {}
options = _.merge({
headers: GET_HEADERS
}, options)
const requestOptions = {
headers: options.headers,
params: options.params
}
let path = options.path
if (options.resource !== undefined && options.resourceId !== undefined) {
path = 'api/' + options.resource + '/' + options.resourceId
}
try {
await Vue.http.delete(path, requestOptions)
} catch (err) {
const code = _.get(err, 'body.code', null)
const message = _.get(err, 'body.message', null)
if (code !== null && message !== null) {
throw new ApiResponseError(err.body.code, err.body.message)
} else {
throw err
}
}
}
export function getFieldList (options) { export function getFieldList (options) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
options = options || {} options = options || {}

@ -6,7 +6,8 @@ import NumberFormatFilter, {
} from 'src/filters/number-format' } from 'src/filters/number-format'
import DateFilter, { import DateFilter, {
smartTime, smartTime,
time time,
weekday
} from 'src/filters/date' } from 'src/filters/date'
import { import {
startCase startCase
@ -28,4 +29,5 @@ export default () => {
Vue.filter('groupName', displayName) Vue.filter('groupName', displayName)
Vue.filter('displayName', displayName) Vue.filter('displayName', displayName)
Vue.filter('time', time) Vue.filter('time', time)
Vue.filter('weekday', weekday)
} }

@ -11,6 +11,7 @@
options-dense options-dense
emit-value emit-value
map-options map-options
dense
:options="selectOptions" :options="selectOptions"
/> />
</div> </div>
@ -19,6 +20,7 @@
> >
<csc-input-time <csc-input-time
v-model="timeFrom" v-model="timeFrom"
dense
/> />
</div> </div>
<div <div
@ -26,6 +28,7 @@
> >
<csc-input-time <csc-input-time
v-model="timeTo" v-model="timeTo"
dense
class="col-2" class="col-2"
/> />
</div> </div>

@ -1,7 +1,7 @@
<template> <template>
<q-item> <q-item>
<q-item-section> <q-item-section>
{{ weekday }}, {{ from | time }} - {{ to | time }} {{ time.weekday | weekday }}, {{ time.from }} - {{ time.to }}
</q-item-section> </q-item-section>
<q-item-section <q-item-section
side side
@ -12,7 +12,7 @@
color="negative" color="negative"
icon="delete" icon="delete"
:label="$t('buttons.remove')" :label="$t('buttons.remove')"
@click="deleteTime(index)" @click="deleteTime"
/> />
</csc-more-menu> </csc-more-menu>
</q-item-section> </q-item-section>
@ -23,9 +23,6 @@
import { import {
mapGetters mapGetters
} from 'vuex' } from 'vuex'
import {
date
} from 'quasar'
import CscMoreMenu from 'components/CscMoreMenu' import CscMoreMenu from 'components/CscMoreMenu'
import CscPopupMenuItem from 'components/CscPopupMenuItem' import CscPopupMenuItem from 'components/CscPopupMenuItem'
@ -36,10 +33,6 @@ export default {
time: { time: {
type: Object, type: Object,
default: null default: null
},
index: {
type: Number,
default: null
} }
}, },
data () { data () {
@ -49,48 +42,12 @@ export default {
computed: { computed: {
...mapGetters('callForward', { ...mapGetters('callForward', {
timesLength: 'getTimesetTimesLength' timesLength: 'getTimesetTimesLength'
}),
weekday () {
return this.time.weekday
},
from () {
return date.buildDate({
hours: this.time.from.split(':')[0],
minutes: this.time.from.split(':')[1]
})
},
to () {
return date.buildDate({
hours: this.time.to.split(':')[0],
minutes: this.time.to.split(':')[1]
}) })
}
}, },
methods: { methods: {
deleteTime (index) { deleteTime () {
if (this.timesLength <= 1) { this.$emit('delete-time')
this.$emit('delete-last-time', index)
} else {
this.$emit('delete-time', {
index: index,
removedDay: this.weekday
})
}
} }
} }
} }
</script> </script>
<style lang="stylus" rel="stylesheet/stylus">
.q-item-side.csc-call-forward-time-btn-container
margin-left 0
.q-btn.csc-call-forward-time-btn
.q-icon
margin-right 0
.csc-time
.q-if-disabled::before
background-image none
background-color currentColor
</style>

@ -11,8 +11,7 @@
:class="'csc-item-' + ((index % 2 === 0)?'odd':'even')" :class="'csc-item-' + ((index % 2 === 0)?'odd':'even')"
:time="time" :time="time"
:index="index" :index="index"
@delete-time="deleteTime" @delete-time="deleteTime(index)"
@delete-last-time="deleteLastTime"
/> />
</q-list> </q-list>
<div <div
@ -79,11 +78,8 @@ export default {
enableAddForm () { enableAddForm () {
this.$emit('enable-add-form') this.$emit('enable-add-form')
}, },
deleteTime (data) { deleteTime (index) {
this.$emit('delete-time', data) this.$emit('delete-time', index)
},
deleteLastTime (data) {
this.$emit('delete-last-time', data)
} }
} }
} }

@ -5,17 +5,7 @@
:sourcesets="sourcesets" :sourcesets="sourcesets"
:destinations="destinations" :destinations="destinations"
:timeset-name="timesetName" :timeset-name="timesetName"
:loading="loadDestinationState === 'requesting' || :loading="timesetLoading"
addSourcesetState === 'requesting' ||
updateOwnPhoneToggleState === 'requesting' ||
addDestinationState === 'requesting' ||
removeDestinationState === 'requesting' ||
changeDestinationState === 'requesting' ||
addTimeState === 'requesting' ||
resetTimeState === 'requesting' ||
removeTimeState === 'requesting' ||
addSourceState === 'requesting' ||
removeSourceState === 'requesting'"
> >
<div <div
v-if="showSections" v-if="showSections"
@ -30,7 +20,6 @@
:timeset-times-loaded="timesetTimesLoaded" :timeset-times-loaded="timesetTimesLoaded"
@enable-add-form="enableTimesAddForm" @enable-add-form="enableTimesAddForm"
@delete-time="deleteTimeDialog" @delete-time="deleteTimeDialog"
@delete-last-time="deleteLastTimeDialog"
/> />
</div> </div>
<div <div
@ -45,10 +34,10 @@
/> />
</div> </div>
<div <div
v-if="timesetHasDuplicate || v-if="!timesetLoading && (timesetHasDuplicate ||
!timesetIsCompatible || !timesetIsCompatible ||
timesetHasReverse || timesetHasReverse ||
showDefinedAlert" showDefinedAlert)"
class="row justify-center q-pa-md q-pt-xl" class="row justify-center q-pa-md q-pt-xl"
> >
<div <div
@ -204,6 +193,19 @@ export default {
'addSourcesetError', 'addSourcesetError',
'timesetTimesLoaded' 'timesetTimesLoaded'
]), ]),
timesetLoading () {
return this.loadDestinationState === 'requesting' ||
this.addSourcesetState === 'requesting' ||
this.updateOwnPhoneToggleState === 'requesting' ||
this.addDestinationState === 'requesting' ||
this.removeDestinationState === 'requesting' ||
this.changeDestinationState === 'requesting' ||
this.addTimeState === 'requesting' ||
this.resetTimeState === 'requesting' ||
this.removeTimeState === 'requesting' ||
this.addSourceState === 'requesting' ||
this.removeSourceState === 'requesting'
},
labelReset () { labelReset () {
return this.$t('pages.callForward.times.resetTimeset', { return this.$t('pages.callForward.times.resetTimeset', {
timeset: this.timesetName timeset: this.timesetName
@ -325,8 +327,7 @@ export default {
enableTimesAddForm () { enableTimesAddForm () {
this.$store.commit('callForward/setActiveTimeForm', true) this.$store.commit('callForward/setActiveTimeForm', true)
}, },
deleteTimeDialog (data) { deleteTimeDialog (index) {
this.deleteTimeData = data
this.$q.dialog({ this.$q.dialog({
title: this.$t('pages.callForward.times.removeDialogTitle'), title: this.$t('pages.callForward.times.removeDialogTitle'),
message: this.deleteTimeMessage, message: this.deleteTimeMessage,
@ -334,26 +335,13 @@ export default {
cancel: true, cancel: true,
persistent: true persistent: true
}).onOk(data => { }).onOk(data => {
this.deleteTime() this.deleteTime(index)
}) })
}, },
deleteTime () { deleteTime (index) {
this.$store.dispatch('callForward/deleteTimeFromTimeset', this.deleteTimeData) this.$store.dispatch('callForward/deleteTimeFromTimeset', {
this.deleteTimeData = null index: index
},
deleteLastTimeDialog () {
this.$q.dialog({
title: this.$t('pages.callForward.times.removeDialogTitle'),
message: this.$t('pages.callForward.times.removeLastDialogText'),
color: 'negative',
cancel: true,
persistent: true
}).onOk(data => {
this.deleteLastTime()
}) })
},
deleteLastTime () {
this.$store.dispatch('callForward/deleteTimesetById')
} }
} }
} }

@ -6,7 +6,7 @@ import { i18n } from 'src/boot/i18n'
const { formatDate } = date const { formatDate } = date
export default function (value) { export default function (value) {
var timeStamp = new Date(value) const timeStamp = new Date(value)
return `${formatDate(timeStamp, 'MMMM D, YYYY')} at ${formatDate(timeStamp, 'h:mm a')}` return `${formatDate(timeStamp, 'MMMM D, YYYY')} at ${formatDate(timeStamp, 'h:mm a')}`
} }
@ -49,3 +49,23 @@ export function smartTime ($date) {
return momentDate.format('LLL') return momentDate.format('LLL')
} }
} }
export const WeekdayMap = {
sunday: 1,
monday: 2,
tuesday: 3,
wednesday: 4,
thursday: 5,
friday: 6,
saturday: 7
}
export function weekday (weekdayNumber) {
let weekdayString = ''
Object.keys(WeekdayMap).forEach((weekday) => {
if (WeekdayMap[weekday] === weekdayNumber) {
weekdayString = i18n.t('pages.callForward.times.' + weekday)
}
})
return weekdayString
}

@ -135,7 +135,7 @@ export default {
i18n.t('pages.callForward.times.resetErrorMessage') i18n.t('pages.callForward.times.resetErrorMessage')
}, },
showDefinedAlert (state) { showDefinedAlert (state) {
return !state.timesetExists && !state.activeTimeForm && state.addTimeState !== 'succeeded' return !state.timesetExists && !state.activeTimeForm
}, },
destinationsLoaded (state) { destinationsLoaded (state) {
return state.destinations.length > 0 return state.destinations.length > 0
@ -347,7 +347,7 @@ export default {
state.removeTimeState = RequestState.requesting state.removeTimeState = RequestState.requesting
state.removeTimeError = null state.removeTimeError = null
}, },
removeTimeSucceeded (state) { removeTimeSucceeded (state, updatedTimeset) {
state.removeTimeState = RequestState.succeeded state.removeTimeState = RequestState.succeeded
state.removeTimeError = null state.removeTimeError = null
}, },
@ -687,26 +687,38 @@ export default {
context.commit('loadTimesSucceeded', result) context.commit('loadTimesSucceeded', result)
}) })
}, },
deleteTimeFromTimeset (context, options) { async appendTimeToTimeset (context, options) {
try {
context.commit('addTimeRequesting')
const fromParts = options.time[0].from.split(':')
const toParts = options.time[0].to.split(':')
const updatedTimes = await appendTimeToTimeset({
timesetId: context.getters.getTimesetId,
time: {
minute: fromParts[1] + '-' + toParts[1],
hour: fromParts[0] + '-' + toParts[0],
wday: options.weekday
}
})
context.commit('addTimeSucceeded')
context.commit('loadTimesSucceeded', updatedTimes)
} catch (err) {
console.log(err)
context.commit('addTimeFailed', err.message)
}
},
async deleteTimeFromTimeset (context, options) {
context.commit('removeTimeRequesting') context.commit('removeTimeRequesting')
const clonedTimes = _.cloneDeep(context.getters.getTimesetTimes) try {
const indexInt = parseInt(options.index) const updatedTimes = await deleteTimeFromTimeset({
clonedTimes.splice(indexInt, 1)
clonedTimes.forEach((time) => {
delete time.weekday
delete time.from
delete time.to
})
deleteTimeFromTimeset({
subscriberId: context.getters.subscriberId,
timesetId: context.getters.getTimesetId, timesetId: context.getters.getTimesetId,
times: clonedTimes timeId: options.index
}).then(() => { })
context.commit('setLastRemovedDay', options.removedDay)
context.commit('removeTimeSucceeded') context.commit('removeTimeSucceeded')
}).catch((err) => { context.commit('loadTimesSucceeded', updatedTimes)
} catch (err) {
context.commit('removeTimeFailed', err.message) context.commit('removeTimeFailed', err.message)
}) }
}, },
deleteTimesetById (context) { deleteTimesetById (context) {
context.commit('removeTimeRequesting') context.commit('removeTimeRequesting')
@ -743,18 +755,6 @@ export default {
context.commit('addTimeFailed', err.message) context.commit('addTimeFailed', err.message)
}) })
}, },
appendTimeToTimeset (context, options) {
context.commit('addTimeRequesting')
appendTimeToTimeset({
time: options.time,
weekday: options.weekday,
id: context.getters.getTimesetId
}).then(() => {
context.commit('addTimeSucceeded')
}).catch((err) => {
context.commit('addTimeFailed', err.message)
})
},
loadDestinations (context, options) { loadDestinations (context, options) {
context.commit('loadDestinationRequesting') context.commit('loadDestinationRequesting')
loadDestinations({ loadDestinations({

Loading…
Cancel
Save