From 3463789805fe240e7e36bfcf326275754912ab0b Mon Sep 17 00:00:00 2001 From: Hans-Peter Herzog Date: Wed, 31 Jan 2018 16:35:53 +0100 Subject: [PATCH] TT#20511 PBXConfig: As a Customer, I want to remove PBX Groups Change-Id: Iaaab318c929ba8e1177a36b8e54e490ac34d292f --- src/api/pbx-config.js | 10 +- src/api/subscriber.js | 27 ++-- src/api/user.js | 2 +- .../pages/PbxConfiguration/CscPbxGroup.vue | 51 ++++++- .../PbxConfiguration/CscPbxGroupAddForm.vue | 131 ++++++++++++++++++ .../pages/PbxConfiguration/Groups.vue | 59 ++++++-- src/locales/en.json | 5 +- src/store/pbx-config.js | 37 ++++- 8 files changed, 286 insertions(+), 36 deletions(-) create mode 100644 src/components/pages/PbxConfiguration/CscPbxGroupAddForm.vue diff --git a/src/api/pbx-config.js b/src/api/pbx-config.js index 6c0182ac..bb5f35b8 100644 --- a/src/api/pbx-config.js +++ b/src/api/pbx-config.js @@ -2,7 +2,7 @@ import Vue from 'vue'; import { getJsonBody } from './utils'; import { getNumbers, assignNumber, assignNumbers } from './user'; -import { createSubscriber } from './subscriber'; +import { createSubscriber, deleteSubscriber } from './subscriber'; var assumedRows = 1000; @@ -88,7 +88,7 @@ export function addGroup(group) { pbx_groupmember_ids: group.seats }); }).then((subscriberId)=>{ - return assignNumbers(group.aliasNumbers, subscriberId); + assignNumbers(group.aliasNumbers, subscriberId); }).then(()=>{ resolve(); }).catch((err)=>{ @@ -97,8 +97,6 @@ export function addGroup(group) { }); } -export function deleteGroup(id) { - return new Promise((resolve, reject)=>{ - - }); +export function removeGroup(id) { + return deleteSubscriber(id); } diff --git a/src/api/subscriber.js b/src/api/subscriber.js index 861f4d80..54e311d2 100644 --- a/src/api/subscriber.js +++ b/src/api/subscriber.js @@ -198,17 +198,16 @@ export function createSubscriber(subscriber) { }); } -// export function deleteSubscriber(id) { -// return new Promise((resolve, reject)=>{ -// Vue.http.delete('/api/subscribers/', null, { -// }).then((res)=>{ -// resolve(_.last(_.split(res.headers.get('Location'), '/'))); -// }).catch((err)=>{ -// if(err.status === 422) { -// reject(new Error(err.body.message)); -// } else { -// reject(err); -// } -// }); -// }); -// } +export function deleteSubscriber(id) { + return new Promise((resolve, reject)=>{ + Vue.http.delete('/api/subscribers/' + id).then((res)=>{ + resolve(); + }).catch((err)=>{ + if(err.status === 422) { + reject(new Error(err.body.message)); + } else { + reject(err); + } + }); + }); +} diff --git a/src/api/user.js b/src/api/user.js index 7c0e11bd..4a6ecc2c 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -101,7 +101,7 @@ export function assignNumbers(numberIds, subscriberId) { reject(err); }); } else { - reject(new Error('No numberIds given')); + resolve(); } }); } diff --git a/src/components/pages/PbxConfiguration/CscPbxGroup.vue b/src/components/pages/PbxConfiguration/CscPbxGroup.vue index ff76f380..bde8c202 100644 --- a/src/components/pages/PbxConfiguration/CscPbxGroup.vue +++ b/src/components/pages/PbxConfiguration/CscPbxGroup.vue @@ -30,8 +30,13 @@ - + + Delete + + + @@ -47,7 +52,10 @@ QInput, QIcon, QSelect, - QChip + QChip, + QBtn, + QInnerLoading, + QSpinnerMat } from 'quasar-framework' export default { name: 'csc-pbx-group', @@ -55,6 +63,7 @@ 'huntPolicyOptions', 'aliasNumberOptions', 'seatOptions', + 'loading' ], data () { return {} @@ -68,9 +77,15 @@ QInput, QIcon, QSelect, - QChip + QChip, + QBtn, + QInnerLoading, + QSpinnerMat }, computed: { + id() { + return this.group.id; + }, name() { return this.group.display_name; }, @@ -103,12 +118,42 @@ }); } return seats; + }, + groupModel() { + return { + id: this.id, + name: this.name, + extension: this.extension, + huntPolicy: this.huntPolicy, + huntTimeout: this.huntTimeout, + primaryNumber: this.primaryNumber, + aliasNumbers: this.aliasNumbers, + seats: this.seats + } + }, + isLoading() { + return this.loading; + }, + cardClasses() { + var cardClasses = ['csc-pbx-group']; + if(this.isLoading) { + cardClasses.push('light-dimmed'); + } + return cardClasses; + } + }, + methods: { + remove() { + this.$emit('remove', this.groupModel); } } } diff --git a/src/components/pages/PbxConfiguration/Groups.vue b/src/components/pages/PbxConfiguration/Groups.vue index ec1c5d69..92013fa5 100644 --- a/src/components/pages/PbxConfiguration/Groups.vue +++ b/src/components/pages/PbxConfiguration/Groups.vue @@ -36,21 +36,23 @@ {{ $t('buttons.cancel') }} {{ $t('buttons.save') }} + + + {{ $t('pbxConfig.addGroup') }} - + - + @@ -76,8 +78,9 @@ QBtn, QSelect, QInnerLoading, - QSpinnerGears, - QSpinnerDots + QSpinnerDots, + QSpinnerMat, + Dialog } from 'quasar-framework' import { mapState } from 'vuex' import numberFilter from '../../../filters/number' @@ -102,8 +105,9 @@ QBtn, QSelect, QInnerLoading, - QSpinnerGears, - QSpinnerDots + QSpinnerDots, + QSpinnerMat, + Dialog }, mounted() { this.$store.dispatch('pbxConfig/listGroups'); @@ -203,6 +207,16 @@ }, addGroupError() { return this.$store.state.pbxConfig.addGroupError; + }, + removeGroupState() { + return this.$store.state.pbxConfig.removeGroupState; + }, + removeGroupIsRequesting() { + return this.removeGroupState === 'requesting' || + this.removeGroupState === 'succeeded'; + }, + removeGroupId() { + return this.$store.state.pbxConfig.removeGroupItem.id; } }, watch: { @@ -213,6 +227,11 @@ if(state === 'succeeded') { this.disableGroupForm(); } + }, + removeGroupState(state) { + if(state === 'failed') { + showGlobalError(this.removeGroupError); + } } }, methods: { @@ -236,6 +255,25 @@ }, addGroup() { this.$store.dispatch('pbxConfig/addGroup', this.groupForm); + }, + removeGroup(group) { + var store = this.$store; + var state = this; + var i18n = this.$i18n; + Dialog.create({ + title: i18n.t('pbxConfig.removeGroupTitle'), + message: i18n.t('pbxConfig.removeGroupText', { group: group.name }), + buttons: [ + 'Cancel', + { + label: i18n.t('pbxConfig.removeGroup'), + color: 'negative', + handler () { + store.dispatch('pbxConfig/removeGroup', group); + } + } + ] + }); } } } @@ -243,6 +281,9 @@