diff --git a/src/api/call-blocking.js b/src/api/call-blocking.js index b265f2a9..b130bed1 100644 --- a/src/api/call-blocking.js +++ b/src/api/call-blocking.js @@ -1,6 +1,7 @@ import Vue from 'vue'; -import { enableBlockIn, disableBlockIn, getPreferences } from './subscriber'; +import { enableBlockIn, disableBlockIn, + getPreferences, addToBlockInList } from './subscriber'; export function enableIncomingCallBlocking(id) { return enableBlockIn(id); @@ -14,10 +15,25 @@ export function getIncomingCallBlocking(id) { return new Promise((resolve, reject)=>{ getPreferences(id).then((result)=>{ resolve({ - enabled: result.block_in_mode + enabled: result.block_in_mode, + list: result.block_in_list }); }).catch((err)=>{ reject(err); }); }); } + +export function addNumberToIncomingList(id, number) { + return new Promise((resolve, reject)=>{ + if(_.isEmpty(number)) { + reject(new Error('Number may not be empty')); + } else { + addToBlockInList(id, number).then(()=>{ + resolve(); + }).catch((err)=>{ + reject(err); + }); + } + }); +} diff --git a/src/api/subscriber.js b/src/api/subscriber.js index 8843aa44..082b00c0 100644 --- a/src/api/subscriber.js +++ b/src/api/subscriber.js @@ -1,4 +1,5 @@ +import _ from 'lodash'; import Vue from 'vue'; export function getPreferences(id) { @@ -13,9 +14,14 @@ export function getPreferences(id) { export function setPreference(id, field, value) { return new Promise((resolve, reject)=>{ - var pref = {}; - pref[field] = value; - Vue.http.put('/api/subscriberpreferences/' + id, pref).then((result)=>{ + Promise.resolve().then(()=>{ + return getPreferences(id); + }).then((result)=>{ + var prefs = _.cloneDeep(result); + delete prefs._links; + prefs[field] = value; + return Vue.http.put('/api/subscriberpreferences/' + id, prefs); + }).then(()=>{ resolve(); }).catch((err)=>{ reject(err); @@ -23,6 +29,42 @@ export function setPreference(id, field, value) { }); } +export function prependItemToArrayPreference(id, field, value) { + return new Promise((resolve, reject)=>{ + Promise.resolve().then(()=>{ + return getPreferences(id); + }).then((result)=>{ + var prefs = _.cloneDeep(result); + delete prefs._links; + prefs[field] = _.get(prefs, field, []); + prefs[field] = [value].concat(prefs[field]); + return Vue.http.put('/api/subscriberpreferences/' + id, prefs); + }).then(()=>{ + resolve(); + }).catch((err)=>{ + reject(err); + }); + }); +} + +export function appendItemToArrayPreference(id, field, value) { + return new Promise((resolve, reject)=>{ + Promise.resolve().then(()=>{ + return getPreferences(id); + }).then((result)=>{ + var prefs = _.cloneDeep(result); + delete prefs._links; + prefs[field] = _.get(prefs, field, []); + prefs[field].push(value); + return Vue.http.put('/api/subscriberpreferences/' + id, prefs); + }).then(()=>{ + resolve(); + }).catch((err)=>{ + reject(); + }); + }); +} + export function setBlockInMode(id, value) { return setPreference(id, 'block_in_mode', value); } @@ -34,3 +76,7 @@ export function enableBlockIn(id) { export function disableBlockIn(id) { return setBlockInMode(id, false); } + +export function addToBlockInList(id, number) { + return prependItemToArrayPreference(id, 'block_in_list', number); +} diff --git a/src/components/layouts/Default.vue b/src/components/layouts/Default.vue index d8c6a89c..17eb19e3 100644 --- a/src/components/layouts/Default.vue +++ b/src/components/layouts/Default.vue @@ -231,15 +231,13 @@ } .q-card { - margin: 0; + margin:15px; + margin-left: 0px; } .q-card.page { padding: 15px; - } - - .q-card.pbx-group { - margin-bottom: 15px; + margin: 0; } .page-action-button { diff --git a/src/components/pages/CallBlocking/Incoming.vue b/src/components/pages/CallBlocking/Incoming.vue index bbf28ff6..8209c2f6 100644 --- a/src/components/pages/CallBlocking/Incoming.vue +++ b/src/components/pages/CallBlocking/Incoming.vue @@ -1,18 +1,43 @@ diff --git a/src/store/call-blocking.js b/src/store/call-blocking.js index ad8bbec0..4e725fca 100644 --- a/src/store/call-blocking.js +++ b/src/store/call-blocking.js @@ -3,7 +3,8 @@ import _ from 'lodash'; import { enableIncomingCallBlocking, disableIncomingCallBlocking, - getIncomingCallBlocking + getIncomingCallBlocking, + addNumberToIncomingList } from '../api/call-blocking'; @@ -23,6 +24,7 @@ export default { }, loadIncoming(state, options) { state.incomingEnabled = options.enabled; + state.incomingList = options.list; } }, actions: { @@ -54,6 +56,17 @@ export default { reject(err); }); }); + }, + addNumber(context, number) { + return new Promise((resolve, reject)=>{ + addNumberToIncomingList(localStorage.getItem('subscriberId'), number).then(()=>{ + return context.dispatch('loadIncoming'); + }).then(()=>{ + resolve(); + }).catch((err)=>{ + reject(err); + }); + }); } } }; diff --git a/t/store/call-blocking.js b/t/store/call-blocking.js new file mode 100644 index 00000000..ecb3e5f9 --- /dev/null +++ b/t/store/call-blocking.js @@ -0,0 +1,32 @@ +'use strict'; + +import CallBlockingModule from '../../src/store/call-blocking'; +import { assert } from 'chai'; + +describe('CallBlockingModule', ()=>{ + + it('should enable/disable incoming call blocking', ()=>{ + var state = {}; + CallBlockingModule.mutations.enableIncoming(state); + assert.equal(state.incomingEnabled, true); + CallBlockingModule.mutations.disableIncoming(state); + assert.equal(state.incomingEnabled, false); + }); + + it('should load incoming call blocking data', ()=>{ + var state = {}; + var list = [ + '+4312345678', + '+4387654321' + ]; + CallBlockingModule.mutations.loadIncoming(state, { + enabled: true, + list: [ + '+4312345678', + '+4387654321' + ] + }); + assert.equal(state.incomingEnabled, true); + assert.deepEqual(state.incomingList, list); + }); +});