MT#56987 Add possibility to select for each soundset announcement if the parent soundset has to be used or not

Change-Id: Idce2af2935832094a7d88ee62264b11da92dd6d8
mr11.4
Hugo Zigha 2 years ago
parent 87d31b2145
commit d45f67b7e8

@ -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)
})
})
}

@ -34,6 +34,7 @@
<q-checkbox
:value="soundSet.contract_default"
:label="$t('Default')"
:disable="!soundSet.customer_id"
:left-label="true"
@input="saveAsDefault"
/>
@ -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 @@
<q-checkbox
:label="$t('Default sound set for all seats and groups')"
:value="soundSet.contract_default"
:disable="!soundSet.customer_id"
@input="saveAsDefault"
/>
<csc-list-spinner
@ -126,9 +131,12 @@
:sound-file-upload-state="soundFileUploadState[soundSet.id + '-' + soundHandle.handle]"
:sound-file-upload-progress="soundFileUploadProgress[soundSet.id + '-' + soundHandle.handle]"
:sound-file-update-state="soundFileUpdateState[soundSet.id + '-' + soundHandle.handle]"
:has-parent="soundSet.parent_id"
:read-only="!soundSet.customer_id"
@play="playSoundFile"
@upload="uploadSoundFile"
@toggle-loop-play="toggleLoopPlay"
@toggle-use-parent="toggleUseParent"
/>
</div>
</template>
@ -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', {

@ -28,7 +28,7 @@
@input="selectFile"
>
<q-icon
v-if="soundFile || selectedFile"
v-if="(soundFile && soundFile.filename) || selectedFile"
name="insert_drive_file"
class="csc-pbx-sound-set-sound-icon"
size="24px"
@ -53,7 +53,7 @@
class="col-grow text-right"
>
<q-btn
v-if="!selectedFile"
v-if="!selectedFile && !readOnly"
flat
color="primary"
icon="folder"
@ -98,7 +98,23 @@
</div>
</div>
<div
v-if="soundFile && !selectedFile"
v-if="hasParent"
class="row items-center"
>
<div
class="col-auto"
>
<q-checkbox
:value="soundFileUseparent"
:disable="readOnly"
:label="$t('Use Parent')"
left-label
@input="toggleUseParent"
/>
</div>
</div>
<div
v-if="soundFile && !selectedFile && this.soundFile.filename"
class="row items-center"
>
<div
@ -107,6 +123,7 @@
<q-checkbox
:value="soundFileLoopplay"
:label="$t('Loop')"
:disable="readOnly"
left-label
@input="toggleLoopPlay"
/>
@ -115,7 +132,7 @@
class="csc-col-right col-grow"
>
<csc-audio-player
v-if="soundFileFilename"
v-if="this.soundFile && this.soundFile.filename"
:file-url="soundFileUrl"
@load="loadPlay"
/>
@ -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
})
}
}
}
}

@ -73,6 +73,7 @@
@play-sound-file="playSoundFile"
@upload-sound-file="uploadSoundFile"
@toggle-loop-play="setLoopPlay"
@toggle-use-parent="setUseParent"
/>
</csc-fade>
</csc-list>
@ -217,7 +218,8 @@ export default {
'loadSoundSetResources',
'playSoundFile',
'uploadSoundFile',
'setLoopPlay'
'setLoopPlay',
'setUseParent'
]),
loadSoundSetListPaginated (page) {
this.loadSoundSetList({

@ -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)
})
}
}
}

Loading…
Cancel
Save