diff --git a/src/api/call-forward.js b/src/api/call-forward.js new file mode 100644 index 00000000..19dd2e98 --- /dev/null +++ b/src/api/call-forward.js @@ -0,0 +1,84 @@ + +import Vue from 'vue'; +import { getJsonBody } from './utils' + +let rowCountAssumption = 1000; + +export function getMappings(id) { + return new Promise((resolve, reject) => { + Vue.http.get('/api/cfmappings/' + id).then(result => { + let jsonBody = getJsonBody(result.body); + delete jsonBody._links; + delete jsonBody.cfs; + resolve(getJsonBody(result.body)); + }).catch(err => { + reject(err); + }); + }); +} + +export function getSourcesets(id) { + return new Promise((resolve, reject) => { + Promise.resolve().then(() => { + return Vue.http.get('/api/cfsourcesets/', + { params: { subscriber_id: id, page: 1, rows: rowCountAssumption } }) + }).then(result => { + let totalCount = getJsonBody(result.body).total_count; + if (totalCount > rowCountAssumption) { + return Vue.http.get('/api/cfsourcesets/', + { params: { subscriber_id: id, page: 1, + rows: totalCount } }) + } else { + return Promise.resolve(result); + } + }).then(result => { + resolve(getJsonBody(result.body)._embedded['ngcp:cfsourcesets']); + }).catch(err => { + reject(err); + }); + }); +} + +export function getTimesets(id) { + return new Promise((resolve, reject) => { + Promise.resolve().then(() => { + return Vue.http.get('/api/cftimesets/', + { params: { subscriber_id: id, page: 1, rows: rowCountAssumption } }) + }).then(result => { + let totalCount = getJsonBody(result.body).total_count; + if (totalCount > rowCountAssumption) { + return Vue.http.get('/api/cftimesets/', + { params: { subscriber_id: id, page: 1, + rows: totalCount } }) + } else { + return Promise.resolve(result); + } + }).then(result => { + resolve(getJsonBody(result.body)._embedded['ngcp:cftimesets']); + }).catch(err => { + reject(err); + }); + }); +} + +export function getDestinationsets(id) { + return new Promise((resolve, reject) => { + Promise.resolve().then(() => { + return Vue.http.get('/api/cfdestinationsets/', + { params: { subscriber_id: id, page: 1, rows: rowCountAssumption } }) + }).then(result => { + let totalCount = getJsonBody(result.body).total_count; + if (totalCount > rowCountAssumption) { + return Vue.http.get('/api/cfdestinationsets/', + { params: { subscriber_id: id, page: 1, + rows: totalCount } }) + } else { + return Promise.resolve(result); + } + }).then(result => { + resolve(getJsonBody(result.body)._embedded['ngcp:cfdestinationsets']); + }).catch(err => { + reject(err); + }); + }); +} diff --git a/src/api/conversations.js b/src/api/conversations.js index 3a240cee..55269030 100644 --- a/src/api/conversations.js +++ b/src/api/conversations.js @@ -6,15 +6,16 @@ import { getJsonBody } from './utils' export function getConversations(id, page, rows) { let params = { subscriber_id: id, page: page, rows: rows }; return new Promise((resolve, reject) => { - Vue.http.get('/api/conversations/', { params: params }).then((result)=>{ - let jsonBody = getJsonBody(result.body); - if (_.has(jsonBody, "_embedded.ngcp:conversations")) { - resolve(jsonBody._embedded['ngcp:conversations']); - } else { - reject(new Error('No items returned for this page.')) - }; - }).catch((err)=>{ - reject(err); - }); + Vue.http.get('/api/conversations/', { params: params }) + .then(result => { + let jsonBody = getJsonBody(result.body); + if (_.has(jsonBody, "_embedded.ngcp:conversations")) { + resolve(jsonBody._embedded['ngcp:conversations']); + } else { + reject(new Error('No items returned for this page.')) + }; + }).catch(err => { + reject(err); + }); }); } diff --git a/src/components/pages/CallForward/Always.vue b/src/components/pages/CallForward/Always.vue index 0e3234b4..fabc2636 100644 --- a/src/components/pages/CallForward/Always.vue +++ b/src/components/pages/CallForward/Always.vue @@ -6,7 +6,8 @@ import CscPage from '../../CscPage' export default { data () { - return {} + return { + } }, components: { CscPage diff --git a/src/store/call-forward.js b/src/store/call-forward.js new file mode 100644 index 00000000..a77d7a60 --- /dev/null +++ b/src/store/call-forward.js @@ -0,0 +1,72 @@ + +'use strict'; + +import _ from 'lodash'; +import { getSourcesets, getDestinationsets, getTimesets, + getMappings } from '../api/call-forward'; + +export default { + namespaced: true, + state: { + mappings: null, + sourcesets: null, + timesets: null, + destinationsets: null + }, + mutations: { + loadMappings(state, result) { + state.mappings = result; + }, + loadSourcesets(state, result) { + state.sourcesets = result; + }, + loadTimesets(state, result) { + state.timesets = result; + }, + loadDestinationsets(state, result) { + state.destinationsets = result; + } + }, + actions: { + loadMappings(context) { + return new Promise((resolve, reject) => { + getMappings(localStorage.getItem('subscriberId')) + .then(result => { + context.commit('loadMappings', result); + }).catch(err => { + reject(err); + }); + }); + }, + loadSourcesets(context) { + return new Promise((resolve, reject) => { + getSourcesets(localStorage.getItem('subscriberId')) + .then(result => { + context.commit('loadSourcesets', result); + }).catch(err => { + reject(err); + }); + }); + }, + loadTimesets(context) { + return new Promise((resolve, reject) => { + getTimesets(localStorage.getItem('subscriberId')) + .then(result => { + context.commit('loadTimesets', result); + }).catch(err => { + reject(err); + }); + }); + }, + loadDestinationsets(context) { + return new Promise((resolve, reject) => { + getDestinationsets(localStorage.getItem('subscriberId')) + .then(result => { + context.commit('loadDestinationsets', result); + }).catch(err => { + reject(err); + }); + }); + } + } +}; diff --git a/src/store/index.js b/src/store/index.js index 3290402e..9f342f15 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,24 +3,26 @@ import Vue from 'vue' import Vuex from 'vuex' -import UserModule from './user' -import PbxGroupsModule from './pbx-groups' import CallBlockingModule from './call-blocking' -import ReminderModule from './reminder' +import CallForwardModule from './call-forward' import CallModule from './call' import ConversationsModule from './conversations' import LayoutModule from './layout' +import PbxGroupsModule from './pbx-groups' +import ReminderModule from './reminder' +import UserModule from './user' Vue.use(Vuex); export const store = new Vuex.Store({ modules: { - user: UserModule, - pbxGroups: PbxGroupsModule, callBlocking: CallBlockingModule, - reminder: ReminderModule, + callForward: CallForwardModule, call: CallModule, conversations: ConversationsModule, - layout: LayoutModule + layout: LayoutModule, + pbxGroups: PbxGroupsModule, + reminder: ReminderModule, + user: UserModule } }); diff --git a/t/api/call-forward.js b/t/api/call-forward.js new file mode 100644 index 00000000..b52d0f8d --- /dev/null +++ b/t/api/call-forward.js @@ -0,0 +1,232 @@ + +'use strict'; + +import Vue from 'vue'; +import VueResource from 'vue-resource'; +import { getMappings, getSourcesets, getTimesets, + getDestinationsets } from '../../src/api/call-forward'; +import { assert } from 'chai'; + +Vue.use(VueResource); + +describe('CallForward', function(){ + + const subscriberId = 123; + + it('should get all call forward mappings', function(done){ + + let data = { + "cfb": [{ + "destinationset": "quickset_cfb", + "destinationset_id": 3, + "sourceset": null, + "sourceset_id": null, + "timeset": null, + "timeset_id": null + }], + "cfna": [{ + "destinationset": "quickset_cfna", + "destinationset_id": 5, + "sourceset": null, + "sourceset_id": null, + "timeset": null, + "timeset_id": null + }], + "cfs": [], + "cft": [], + "cft_ringtimeout": null, + "cfu": [{ + "destinationset": "quickset_cfu", + "destinationset_id": 1, + "sourceset": null, + "sourceset_id": null, + "timeset": null, + "timeset_id": null + }], + "id": 233 + }; + + Vue.http.interceptors = []; + Vue.http.interceptors.unshift((request, next)=>{ + next(request.respondWith(JSON.stringify(data), { + status: 200 + })); + }); + getMappings(subscriberId).then((result)=>{ + assert.deepEqual(result, data); + done(); + }).catch((err)=>{ + done(err); + }); + }); + + it('should get all call forward sourcesets', function(done){ + + let innerData = [{ + "_links": { + "collection": { + "href": "/api/cfsourcesets/" + }, + "curies": { + "href": "http://purl.org/sipwise/ngcp-api/#rel-{rel}", + "name": "ngcp", + "templated": true + }, + "ngcp:subscribers": { + "href": "/api/subscribers/233" + }, + "profile": { + "href": "http://purl.org/sipwise/ngcp-api/" + }, + "self": { + "href": "/api/cfsourcesets/3" + } + }, + "id": 3, + "mode": "whitelist", + "name": "sffsdg", + "sources": [{ + "source": "3423" + }], + "subscriber_id": 233 + }]; + let data = { + "_embedded": { + "ngcp:cfsourcesets": innerData + }, + "total_count": 10 + }; + + Vue.http.interceptors = []; + Vue.http.interceptors.unshift((request, next)=>{ + next(request.respondWith(JSON.stringify(data), { + status: 200 + })); + }); + getSourcesets(subscriberId).then((result)=>{ + assert.deepEqual(result, innerData); + done(); + }).catch((err)=>{ + done(err); + }); + }); + + it('should get all call forward timesets', function(done){ + + let innerData = [{ + "_links": { + "collection": { + "href": "/api/cftimesets/" + }, + "curies": { + "href": "http://purl.org/sipwise/ngcp-api/#rel-{rel}", + "name": "ngcp", + "templated": true + }, + "ngcp:cftimesets": { + "href": "/api/cftimesets/1" + }, + "ngcp:journal": { + "href": "/api/cftimesets/1/journal/" + }, + "ngcp:subscribers": { + "href": "/api/subscribers/233" + }, + "profile": { + "href": "http://purl.org/sipwise/ngcp-api/" + }, + "self": { + "href": "/api/cftimesets/1" + } + }, + "id": 1, + "name": "efsgfseg", + "subscriber_id": 233, + "times": [{ + "hour": null, + "mday": null, + "minute": null, + "month": null, + "wday": "2-3", + "year": null + }] + }]; + let data = { + "_embedded": { + "ngcp:cftimesets": innerData + }, + "total_count": 10 + }; + + Vue.http.interceptors = []; + Vue.http.interceptors.unshift((request, next)=>{ + next(request.respondWith(JSON.stringify(data), { + status: 200 + })); + }); + getTimesets(subscriberId).then((result)=>{ + assert.deepEqual(result, innerData); + done(); + }).catch((err)=>{ + done(err); + }); + }); + + it('should get all call forward destinationsets', function(done){ + + let innerData = [{ + "_links": { + "collection": { + "href": "/api/cfdestinationsets/" + }, + "curies": { + "href": "http://purl.org/sipwise/ngcp-api/#rel-{rel}", + "name": "ngcp", + "templated": true + }, + "ngcp:journal": { + "href": "/api/cfdestinationsets/1/journal/" + }, + "ngcp:subscribers": { + "href": "/api/subscribers/233" + }, + "profile": { + "href": "http://purl.org/sipwise/ngcp-api/" + }, + "self": { + "href": "/api/cfdestinationsets/1" + } + }, + "destinations": [{ + "announcement_id": null, + "destination": "sip:24234234@192.168.178.23", + "priority": 1, + "simple_destination": "24234234", + "timeout": 300 + }], + "id": 1, + "name": "quickset_cfu", + "subscriber_id": 233 + }]; + let data = { + "_embedded": { + "ngcp:cfdestinationsets": innerData + }, + "total_count": 10 + }; + + Vue.http.interceptors = []; + Vue.http.interceptors.unshift((request, next)=>{ + next(request.respondWith(JSON.stringify(data), { + status: 200 + })); + }); + getDestinationsets(subscriberId).then((result)=>{ + assert.deepEqual(result, innerData); + done(); + }).catch((err)=>{ + done(err); + }); + }); + +}); diff --git a/t/store/call-forward.js b/t/store/call-forward.js new file mode 100644 index 00000000..e69de29b