diff --git a/src/api/common.js b/src/api/common.js index 7ebb17dc..498fa822 100644 --- a/src/api/common.js +++ b/src/api/common.js @@ -75,3 +75,27 @@ export function get(options) { }); }); } + +export function patchReplace(options) { + return new Promise((resolve, reject)=>{ + Vue.http.patch(options.path, [{ + op: 'replace', + path: '/'+ options.fieldPath, + value: options.value + }], { + headers: { + 'Content-Type': 'application/json-patch+json', + 'Prefer': 'return=minimal' + } + }).then((result)=>{ + resolve(result); + }).catch((err)=>{ + if(err.status >= 400) { + reject(new Error(err.body.message)); + } + else { + reject(err); + } + }); + }); +} diff --git a/src/api/pbx-config.js b/src/api/pbx-config.js index 7e100d8e..7e86561b 100644 --- a/src/api/pbx-config.js +++ b/src/api/pbx-config.js @@ -6,7 +6,7 @@ import { createSubscriber, deleteSubscriber, setDisplayName, setPbxExtension, setPbxHuntPolicy, setPbxHuntTimeout, setPbxGroupMemberIds, setPbxGroupIds, getSubscribers, getSubscriber } from './subscriber'; import uuid from 'uuid'; -import { getList, get } from './common' +import { getList, get, patchReplace } from './common' var createId = uuid.v4; @@ -46,6 +46,23 @@ export function getSeats(options) { }); } +export function getAllGroupsAndSeats(options) { + return new Promise((resolve, reject)=>{ + options = options || {}; + options = _.merge(options, { + params: { + all: true, + is_pbx_pilot: 0 + } + }); + getSubscribers(options).then((res)=>{ + resolve(res); + }).catch((err)=>{ + reject(err); + }); + }); +} + export function getPilot(options) { return new Promise((resolve, reject)=>{ options = options || {}; @@ -269,13 +286,19 @@ export function updateSeatGroups(id, seatIds) { return setPbxGroupIds(id, seatIds); } -export function getDeviceFull(id) { - return getDevice(id, true); +export function getDeviceFull(id, options) { + options = options || {}; + options.join = true; + options.joinLines = true; + return getDevice(id, options); } -export function getDevice(id, join) { +export function getDevice(id, options) { return new Promise((resolve, reject)=>{ - let device; + options = options || {}; + let device = null; + let join = _.get(options, 'join', false); + let joinLines = _.get(options, 'joinLines', false); Promise.resolve().then(()=>{ return get({ path: 'api/pbxdevices/' + id @@ -286,7 +309,7 @@ export function getDevice(id, join) { let requests = [ getProfile(device.profile_id, join) ]; - if(_.isArray(device.lines) && device.lines.length > 0) { + if(joinLines === true && _.isArray(device.lines) && device.lines.length > 0) { device.lines.forEach((line)=>{ requests.push(getSubscriber(line.subscriber_id)); }); @@ -382,3 +405,12 @@ export function removeDevice(id) { }); }); } + +export function updateDeviceKeys(deviceId, keys) { + return patchReplace({ + path: 'api/pbxdevices/' + deviceId, + fieldPath: 'lines', + value: keys + }); +} + diff --git a/src/components/pages/PbxConfiguration/CscPbxDevice.vue b/src/components/pages/PbxConfiguration/CscPbxDevice.vue index 1307bb79..f320e5be 100644 --- a/src/components/pages/PbxConfiguration/CscPbxDevice.vue +++ b/src/components/pages/PbxConfiguration/CscPbxDevice.vue @@ -5,7 +5,7 @@ - + {{ device.station_name }} Model: {{ name }} MAC address: {{ device.identifier }} @@ -19,16 +19,18 @@

{{ name }}

- +
- + - + @@ -47,7 +49,9 @@ props: [ 'device', 'loading', - 'modelOptions' + 'modelOptions', + 'groupsAndSeatsOptions', + 'subscribers' ], components: { CscPbxDeviceConfig, QCard, QCardTitle, QCardMain, QCollapsible, @@ -91,6 +95,15 @@ }, remove() { this.$emit('remove', this.device); + }, + loadGroupsAndSeats(){ + this.$emit('loadGroupsAndSeats'); + }, + keysChanged(keys) { + this.$emit('deviceKeysChanged', { + device: this.device, + keys: keys + }); } } } diff --git a/src/components/pages/PbxConfiguration/CscPbxDeviceConfig.vue b/src/components/pages/PbxConfiguration/CscPbxDeviceConfig.vue index add66060..8f8fc4f2 100644 --- a/src/components/pages/PbxConfiguration/CscPbxDeviceConfig.vue +++ b/src/components/pages/PbxConfiguration/CscPbxDeviceConfig.vue @@ -4,22 +4,28 @@
-
- {{ index + 1 }} - -
- - - - - - - -
-
+
{{ index + 1 }}
+
+
+
+ Key {{ selectedKeyIndex + 1 }} +
+ + + + + + +
+
+ Close +
+
@@ -28,7 +34,7 @@ @@ -219,6 +368,27 @@ @import '../../../themes/quasar.variables'; $spotSize = 25px + .csc-pbx-device-config-key-overlay + .title + .q-icon + margin-right 8px + font-size 18px + font-weight 400 + letter-spacing normal + line-height 1.8rem + margin-bottom 32px + text-align center + + + position absolute + top 0 + left 0 + right 0 + bottom 0 + background-color rgba(250,250,250,0.95) + z-index 10 + padding 48px + .csc-pbx-device-key-details padding 50px position relative @@ -227,6 +397,8 @@ position relative .spot-modal-content position relative + .actions + padding 32px .csc-pbx-device-image position relative @@ -244,6 +416,9 @@ letter-spacing normal line-height 1.8rem + .csc-pbx-device-loader + z-index 20 + .csc-pbx-device-button-spot border-radius: 50%; width $spotSize diff --git a/src/components/pages/PbxConfiguration/CscPbxDevices.vue b/src/components/pages/PbxConfiguration/CscPbxDevices.vue index 5d56b7f4..07d215e5 100644 --- a/src/components/pages/PbxConfiguration/CscPbxDevices.vue +++ b/src/components/pages/PbxConfiguration/CscPbxDevices.vue @@ -9,7 +9,9 @@ + :modelOptions="modelOptions" :loading="isDeviceLoading(device.id)" + :groupsAndSeatsOptions="groupsAndSeatsOptions" :subscribers="getGroupOrSeatById" + @loadGroupsAndSeats="loadGroupsAndSeats()" @deviceKeysChanged="deviceKeysChanged" />
{{ $t('pbxConfig.noDevices') }} @@ -52,7 +54,11 @@ 'listCurrentPage', 'listLastPage', 'isDeviceLoading', - 'deviceRemoved' + 'deviceRemoved', + 'groupsAndSeatsOptions', + 'groupsAndSeats', + 'getGroupOrSeatById', + 'updatedDeviceKey' ]) }, methods: { @@ -81,6 +87,12 @@ } ] }); + }, + loadGroupsAndSeats() { + this.$store.dispatch('pbxConfig/getAllGroupsAndSeats'); + }, + deviceKeysChanged(data) { + this.$store.dispatch('pbxConfig/updateDeviceKeys', data); } }, watch: { @@ -90,6 +102,13 @@ name: device.station_name })); } + }, + updatedDeviceKey(data) { + if(data !== null) { + showToast(this.$t('pbxConfig.toasts.updatedDeviceKeys',{ + name: data.device.station_name + })); + } } } } diff --git a/src/locales/en.json b/src/locales/en.json index 51e5f815..96e88b1b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -292,11 +292,19 @@ "removedGroupToast": "Removed group {group}", "addedSeatToast": "Added seat {seat}", "removedSeatToast": "Removed seat {seat}", - "removedDeviceToast": "Removed device {name}" + "removedDeviceToast": "Removed device {name}", + "updatedDeviceKeys": "Updated keys of device {name}" }, "removeDevice": "Remove device", "removeDeviceTitle": "Remove device", - "removeDeviceText": "You are about to remove device {device}" + "removeDeviceText": "You are about to remove device {device}", + "keyEmptyLabel": "Unassigned", + "keyGroupLabel": "Group", + "keySeatLabel": "Seat", + "keyBothLabel": "Group/Seat", + "keyTypeShared": "Shared", + "keyTypeBLF": "Busy Lamp Field", + "keyTypePrivate": "Private" }, "communication": { "sendFax": "Send Fax", diff --git a/src/store/pbx-config/actions.js b/src/store/pbx-config/actions.js index d09d2536..a5bf1418 100644 --- a/src/store/pbx-config/actions.js +++ b/src/store/pbx-config/actions.js @@ -3,9 +3,9 @@ import _ from 'lodash'; import { assignNumbers } from '../../api/user'; import { addGroup, removeGroup, addSeat, removeSeat, setGroupName, - setGroupExtension, setGroupHuntPolicy, setGroupHuntTimeout, - updateGroupSeats, setSeatName, setSeatExtension, removeDevice, - updateSeatGroups, getGroupList, getSeatList, getDeviceList, getDeviceFull } from '../../api/pbx-config' + setGroupExtension, setGroupHuntPolicy, setGroupHuntTimeout, updateDeviceKeys, + updateGroupSeats, setSeatName, setSeatExtension, removeDevice, getAllGroupsAndSeats, + updateSeatGroups, getGroupList, getSeatList, getDeviceList, getDevice } from '../../api/pbx-config' export default { listGroups(context, options) { @@ -204,7 +204,10 @@ export default { }, loadDevice(context, deviceId) { context.commit('deviceRequesting', deviceId); - getDeviceFull(deviceId).then((device)=>{ + getDevice(deviceId, { + join: true, + joinLines: false, + }).then((device)=>{ context.commit('deviceSucceeded', device); }).catch((err)=>{ context.commit('deviceFailed', deviceId, err.message); @@ -218,5 +221,22 @@ export default { }).catch((err)=>{ context.commit('deviceFailed', device.id, err.message); }); + }, + getAllGroupsAndSeats(context) { + context.commit('groupsAndSeatsRequesting'); + getAllGroupsAndSeats().then((list)=>{ + context.commit('groupsAndSeatsSucceeded', list); + }).catch((err)=>{ + context.commit('groupsAndSeatsError', err.message); + }); + }, + updateDeviceKeys(context, data) { + context.commit('updateDeviceKeyRequesting', data.device.id); + updateDeviceKeys(data.device.id, data.keys).then(()=>{ + context.commit('updateDeviceKeySucceeded', data); + context.dispatch('loadDevice', data.device.id); + }).catch((err)=>{ + context.commit('updateDeviceKeyFailed', data.device.id, err); + }); } } diff --git a/src/store/pbx-config/getters.js b/src/store/pbx-config/getters.js index 5e423fb2..afc43ab3 100644 --- a/src/store/pbx-config/getters.js +++ b/src/store/pbx-config/getters.js @@ -2,6 +2,7 @@ import _ from 'lodash' import { RequestState } from '../common' +import { i18n } from '../../i18n'; export default { groups(state) { @@ -177,5 +178,39 @@ export default { }, deviceRemoved(state) { return state.deviceRemoved; + }, + groupsAndSeats(state) { + return state.groupsAndSeats; + }, + groupsAndSeatsOptions(state) { + let options = [ + { + icon: 'clear', + label: i18n.t('pbxConfig.keyEmptyLabel'), + value: null + } + ]; + state.groupsAndSeats.forEach((item)=>{ + options.push({ + icon: (item.is_pbx_group === true)? 'group' : 'person', + label: item.display_name, + value: item.id + }); + }); + return options; + }, + getGroupOrSeatById(state) { + return (id)=>{ + let groupOrSeat = null; + state.groupsAndSeats.forEach(($groupOrSeat)=>{ + if(id === $groupOrSeat.id) { + groupOrSeat = $groupOrSeat; + } + }); + return groupOrSeat; + }; + }, + updatedDeviceKey(state) { + return state.updatedDeviceKey; } } diff --git a/src/store/pbx-config/mutations.js b/src/store/pbx-config/mutations.js index c4199b61..49bd2cf9 100644 --- a/src/store/pbx-config/mutations.js +++ b/src/store/pbx-config/mutations.js @@ -201,5 +201,30 @@ export default { }, lastUpdatedField(state, group) { state.lastUpdatedField = group; + }, + groupsAndSeatsRequesting(state) { + state.groupsAndSeatsState = RequestState.requesting; + state.groupsAndSeats = []; + }, + groupsAndSeatsSucceeded(state, list) { + state.groupsAndSeatsState = RequestState.succeeded; + state.groupsAndSeats = list.items; + }, + groupsAndSeatsError(state, error) { + state.groupsAndSeatsState = RequestState.failed; + state.groupsAndSeatsError = error; + }, + updateDeviceKeyRequesting(state, deviceId) { + Vue.set(state.deviceStates, deviceId + "", RequestState.requesting); + state.updatedDeviceKey = null; + }, + updateDeviceKeySucceeded(state, data) { + Vue.set(state.deviceStates, data.device.id + "", RequestState.succeeded); + state.updatedDeviceKey = data; + }, + updateDeviceKeyFailed(state, deviceId, error) { + Vue.set(state.deviceStates, deviceId + "", RequestState.failed); + Vue.set(state.deviceErrors, deviceId + "", error); + state.updatedDeviceKey = null; } } diff --git a/src/store/pbx-config/state.js b/src/store/pbx-config/state.js index c8e8e9d9..d0cd5249 100644 --- a/src/store/pbx-config/state.js +++ b/src/store/pbx-config/state.js @@ -41,5 +41,9 @@ export default { updateAliasNumbersState: RequestState.initiated, updateAliasNumbersItem: null, updateGroupsAndSeatsState: RequestState.initiated, - updateGroupsAndSeatsItem: null + updateGroupsAndSeatsItem: null, + groupsAndSeats: [], + groupsAndSeatsState: RequestState.initiated, + groupsAndSeatsError: null, + updatedDeviceKey: null }