From 3b8f5a4d1009b6b3d250171e96310f433248d23b Mon Sep 17 00:00:00 2001 From: Hans-Peter Herzog Date: Tue, 10 Oct 2017 20:33:29 +0200 Subject: [PATCH] TT#23369 CallBlocking: As a Customer I want to enable/disable the functionality Change-Id: I236db3253a156a6e6e0e152113b7b1887a0d4655 --- src/api/call-blocking.js | 23 ++++++++ src/api/subscriber.js | 36 +++++++++++ .../pages/CallBlocking/Incoming.vue | 36 ++++++++++- src/store/call-blocking.js | 59 +++++++++++++++++++ src/store/index.js | 4 +- 5 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 src/api/call-blocking.js create mode 100644 src/api/subscriber.js create mode 100644 src/store/call-blocking.js diff --git a/src/api/call-blocking.js b/src/api/call-blocking.js new file mode 100644 index 00000000..b265f2a9 --- /dev/null +++ b/src/api/call-blocking.js @@ -0,0 +1,23 @@ + +import Vue from 'vue'; +import { enableBlockIn, disableBlockIn, getPreferences } from './subscriber'; + +export function enableIncomingCallBlocking(id) { + return enableBlockIn(id); +} + +export function disableIncomingCallBlocking(id) { + return disableBlockIn(id); +} + +export function getIncomingCallBlocking(id) { + return new Promise((resolve, reject)=>{ + getPreferences(id).then((result)=>{ + resolve({ + enabled: result.block_in_mode + }); + }).catch((err)=>{ + reject(err); + }); + }); +} diff --git a/src/api/subscriber.js b/src/api/subscriber.js new file mode 100644 index 00000000..8843aa44 --- /dev/null +++ b/src/api/subscriber.js @@ -0,0 +1,36 @@ + +import Vue from 'vue'; + +export function getPreferences(id) { + return new Promise((resolve, reject)=>{ + Vue.http.get('/api/subscriberpreferences/' + id).then((result)=>{ + resolve(JSON.parse(result.body)); + }).catch((err)=>{ + reject(err); + }); + }); +} + +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)=>{ + resolve(); + }).catch((err)=>{ + reject(err); + }); + }); +} + +export function setBlockInMode(id, value) { + return setPreference(id, 'block_in_mode', value); +} + +export function enableBlockIn(id) { + return setBlockInMode(id, true); +} + +export function disableBlockIn(id) { + return setBlockInMode(id, false); +} diff --git a/src/components/pages/CallBlocking/Incoming.vue b/src/components/pages/CallBlocking/Incoming.vue index f32d7099..bbf28ff6 100644 --- a/src/components/pages/CallBlocking/Incoming.vue +++ b/src/components/pages/CallBlocking/Incoming.vue @@ -1,15 +1,45 @@ diff --git a/src/store/call-blocking.js b/src/store/call-blocking.js new file mode 100644 index 00000000..ad8bbec0 --- /dev/null +++ b/src/store/call-blocking.js @@ -0,0 +1,59 @@ +'use strict'; + +import _ from 'lodash'; +import { enableIncomingCallBlocking, + disableIncomingCallBlocking, + getIncomingCallBlocking +} from '../api/call-blocking'; + + +export default { + namespaced: true, + state: { + incomingEnabled: false, + incomingList: [] + }, + getters: {}, + mutations: { + enableIncoming (state) { + state.incomingEnabled = true; + }, + disableIncoming (state) { + state.incomingEnabled = false; + }, + loadIncoming(state, options) { + state.incomingEnabled = options.enabled; + } + }, + actions: { + toggleIncoming(context, enabled) { + return new Promise((resolve, reject)=>{ + if(enabled) { + enableIncomingCallBlocking(localStorage.getItem('subscriberId')).then(()=>{ + context.commit('enableIncoming'); + resolve(); + }).catch((err)=>{ + reject(err); + }); + } else { + disableIncomingCallBlocking(localStorage.getItem('subscriberId')).then(()=>{ + context.commit('disableIncoming'); + resolve(); + }).catch((err)=>{ + reject(err); + }); + } + }); + }, + loadIncoming(context) { + return new Promise((resolve, reject)=>{ + getIncomingCallBlocking(localStorage.getItem('subscriberId')).then((result)=>{ + context.commit('loadIncoming', result); + resolve(); + }).catch((err)=>{ + reject(err); + }); + }); + } + } +}; diff --git a/src/store/index.js b/src/store/index.js index cf1c2208..37b6b059 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -6,6 +6,7 @@ import Vuex from 'vuex' import UserModule from './user' import PbxGroupsModule from './pbx-groups' +import CallBlockingModule from './call-blocking' var rtcEngineClient = null; var rtcEngineNetwork = null; @@ -15,7 +16,8 @@ Vue.use(Vuex); export const store = new Vuex.Store({ modules: { user: UserModule, - pbxGroups: PbxGroupsModule + pbxGroups: PbxGroupsModule, + callBlocking: CallBlockingModule }, state: { rtcEngineConnected: false