From d45f67b7e8e3bf7ce51008795aa738fa1e69fda2 Mon Sep 17 00:00:00 2001 From: Hugo Zigha Date: Fri, 31 Mar 2023 17:37:21 +0200 Subject: [PATCH] MT#56987 Add possibility to select for each soundset announcement if the parent soundset has to be used or not Change-Id: Idce2af2935832094a7d88ee62264b11da92dd6d8 --- src/api/pbx-soundsets.js | 100 +++++++++++++----- .../pages/PbxConfiguration/CscPbxSoundSet.vue | 14 ++- .../PbxConfiguration/CscPbxSoundSetSound.vue | 57 +++++++++- src/pages/CscPagePbxSoundSets.vue | 4 +- src/store/pbx-soundsets.js | 11 +- 5 files changed, 153 insertions(+), 33 deletions(-) diff --git a/src/api/pbx-soundsets.js b/src/api/pbx-soundsets.js index 1536d744..4486a493 100644 --- a/src/api/pbx-soundsets.js +++ b/src/api/pbx-soundsets.js @@ -3,7 +3,8 @@ import { getList, patchReplaceFull, getAsBlob, - get + get, + post } from './common' import { PBX_CONFIG_ORDER_BY, @@ -183,33 +184,66 @@ export function getSoundFile (options) { export function uploadSoundFile (options) { return new Promise((resolve, reject) => { const formData = new FormData() - formData.append('json', JSON.stringify({ - loopplay: true, - filename: options.soundFileData.name, - set_id: options.soundSetId, - handle: options.soundHandle - })) - formData.append('soundfile', options.soundFileData) - Vue.http.post('api/soundfiles/', formData, { - before (request) { - options.initialized(request) - }, - progress (progressEvent) { - if (progressEvent.lengthComputable) { - options.progressed(Math.ceil((progressEvent.loaded / progressEvent.total) * 100)) + + if (options.soundFileData) { + formData.append('json', JSON.stringify({ + loopplay: options.soundFileData !== null, + set_id: options.soundSetId, + handle: options.soundHandle, + filename: options.soundFileData.name + })) + formData.append('soundfile', options.soundFileData) + Vue.http.post('api/soundfiles/', formData, { + before (request) { + options.initialized(request) + }, + progress (progressEvent) { + if (progressEvent.lengthComputable) { + options.progressed(Math.ceil((progressEvent.loaded / progressEvent.total) * 100)) + } } - } - }).then((res) => { - const fileId = _.last(res.headers.get('location').split(/\//)) - return Promise.all([ - get({ path: 'api/soundfiles/' + fileId }), - getSoundFile({ id: fileId }) - ]) - }).then((res) => { - resolve({ - soundFile: res[0], - soundFileUrl: res[1] + }).then((res) => { + const fileId = _.last(res.headers.get('location').split(/\//)) + return Promise.all([ + get({ path: 'api/soundfiles/' + fileId }), + getSoundFile({ id: fileId }) + ]) + }).then((res) => { + resolve({ + soundFile: res[0], + soundFileUrl: res[1] + }) + }).catch((err) => { + reject(err) + }) + } else { + post({ + resource: 'soundfiles', + body: { + loopplay: false, + set_id: options.soundSetId, + handle: options.soundHandle, + use_parent: false + } + }).then(async (id) => { + const res = await getSoundFileById({ id }) + resolve({ + soundFile: res, + soundFileUrl: null + }) + }).catch((err) => { + reject(err) }) + } + }) +} + +export function getSoundFileById (options) { + return new Promise((resolve, reject) => { + get({ + path: 'api/soundfiles/' + options.id + }).then((soundfile) => { + resolve(soundfile) }).catch((err) => { reject(err) }) @@ -229,3 +263,17 @@ export function setLoopPlay (options) { }) }) } + +export function setUseParent (options) { + return new Promise((resolve, reject) => { + patchReplaceFull({ + path: 'api/soundfiles/' + options.soundFileId, + fieldPath: 'use_parent', + value: options.useParent + }).then((soundFile) => { + resolve(soundFile) + }).catch((err) => { + reject(err) + }) + }) +} diff --git a/src/components/pages/PbxConfiguration/CscPbxSoundSet.vue b/src/components/pages/PbxConfiguration/CscPbxSoundSet.vue index 5468240f..c261d212 100644 --- a/src/components/pages/PbxConfiguration/CscPbxSoundSet.vue +++ b/src/components/pages/PbxConfiguration/CscPbxSoundSet.vue @@ -34,6 +34,7 @@ @@ -47,6 +48,7 @@ v-model="changes.name" :error="$v.changes.name.$error" :label="$t('Name')" + :disable="!soundSet.customer_id" @input="$v.changes.name.$touch" @keyup.enter="save" > @@ -67,6 +69,7 @@ v-model="changes.description" :error="$v.changes.description.$error" :label="$t('Description')" + :disable="!soundSet.customer_id" @input="$v.changes.description.$touch" @keyup.enter="save" > @@ -89,6 +92,7 @@ v-if="(changes.parent_id && parent) || !changes.parent_id" emit-value map-options + :disable="!soundSet.customer_id" :options="getParentOptions" :label="$t('Parent')" > @@ -107,6 +111,7 @@ @@ -303,7 +311,8 @@ export default { name: this.soundSet.name, description: this.soundSet.description, contract_default: this.soundSet.contract_default, - parent_id: this.soundSet.parent_id + parent_id: this.soundSet.parent_id, + customer_id: this.soundSet.customer_id } }, resetName () { @@ -328,6 +337,9 @@ export default { toggleLoopPlay (options) { this.$emit('toggle-loop-play', options) }, + toggleUseParent (options) { + this.$emit('toggle-use-parent', options) + }, save () { if (this.hasNameChanged) { this.$emit('save-name', { diff --git a/src/components/pages/PbxConfiguration/CscPbxSoundSetSound.vue b/src/components/pages/PbxConfiguration/CscPbxSoundSetSound.vue index e40618e2..91b12429 100644 --- a/src/components/pages/PbxConfiguration/CscPbxSoundSetSound.vue +++ b/src/components/pages/PbxConfiguration/CscPbxSoundSetSound.vue @@ -28,7 +28,7 @@ @input="selectFile" >
+
+ +
+
+
@@ -115,7 +132,7 @@ class="csc-col-right col-grow" > @@ -170,6 +187,14 @@ export default { soundFileUpdateState: { type: String, default: null + }, + hasParent: { + type: Number, + default: null + }, + readOnly: { + type: Boolean, + default: false } }, data () { @@ -188,6 +213,8 @@ export default { soundFileFilename () { if (this.soundFile && this.soundFile.filename) { return this.soundFile.filename + } else if (this.soundFile && !this.soundFile.filename) { + return this.$t('(empty)') } return '' }, @@ -197,6 +224,12 @@ export default { } return null }, + soundFileUseparent () { + if (this.soundFile) { + return this.soundFile.use_parent + } + return true + }, itemClasses () { const classes = ['csc-pbx-sound-set-sound', 'row', 'items-center'] if (this.odd) { @@ -251,6 +284,22 @@ export default { soundFileId: this.soundFile.id, loopPlay: !this.soundFileLoopplay }) + }, + toggleUseParent () { + if (!this.soundFile) { + this.$emit('upload', { + soundHandle: this.soundHandle.handle, + soundFileData: null, + useParent: false + }) + } else { + this.$emit('toggle-use-parent', { + soundSetId: this.soundFile.set_id, + soundHandle: this.soundFile.handle, + soundFileId: this.soundFile.id, + useParent: !this.soundFileUseparent + }) + } } } } diff --git a/src/pages/CscPagePbxSoundSets.vue b/src/pages/CscPagePbxSoundSets.vue index af9b3182..d8c25604 100644 --- a/src/pages/CscPagePbxSoundSets.vue +++ b/src/pages/CscPagePbxSoundSets.vue @@ -73,6 +73,7 @@ @play-sound-file="playSoundFile" @upload-sound-file="uploadSoundFile" @toggle-loop-play="setLoopPlay" + @toggle-use-parent="setUseParent" /> @@ -217,7 +218,8 @@ export default { 'loadSoundSetResources', 'playSoundFile', 'uploadSoundFile', - 'setLoopPlay' + 'setLoopPlay', + 'setUseParent' ]), loadSoundSetListPaginated (page) { this.loadSoundSetList({ diff --git a/src/store/pbx-soundsets.js b/src/store/pbx-soundsets.js index d27a8279..75a1cefb 100644 --- a/src/store/pbx-soundsets.js +++ b/src/store/pbx-soundsets.js @@ -17,7 +17,7 @@ import { getAllSoundFilesBySoundSetId, getSoundFile, uploadSoundFile, - setLoopPlay, unsetAsDefault + setLoopPlay, unsetAsDefault, setUseParent } from '../api/pbx-soundsets' import _ from 'lodash' import { @@ -524,6 +524,15 @@ export default { console.debug(err) context.commit('soundFileUpdateFailed', options) }) + }, + setUseParent (context, options) { + context.commit('soundFileUpdateRequesting', options) + setUseParent(options).then((soundFile) => { + context.commit('soundFileUpdateSucceeded', soundFile) + }).catch((err) => { + console.debug(err) + context.commit('soundFileUpdateFailed', options) + }) } } }