TT#36018 PPBXConfig: As a Customer, I want to navigate through the list of pbx groups by using a pagination mechanism
- PBXConfig: As a Customer, I want to navigate through the list of devices by using a pagination mechanism - PBXConfig: As a Customer, I want to navigate through the list of seats by using a pagination mechanism Change-Id: I15393d01a3f50eeafcc300ef27ad2769c6f1dc1achanges/52/20752/5
parent
d3211cb5a0
commit
c3a1e3d7ad
@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
import Vue from 'vue';
|
||||||
|
import { getJsonBody } from './utils';
|
||||||
|
|
||||||
|
export const LIST_DEFAULT_PAGE = 1;
|
||||||
|
export const LIST_DEFAULT_ROWS = 25;
|
||||||
|
export const LIST_ALL_ROWS = 1000;
|
||||||
|
|
||||||
|
export function getList(options) {
|
||||||
|
return new Promise((resolve, reject)=>{
|
||||||
|
options = options || {};
|
||||||
|
options = _.merge({
|
||||||
|
all: false,
|
||||||
|
params: {
|
||||||
|
page: LIST_DEFAULT_PAGE,
|
||||||
|
rows: LIST_DEFAULT_ROWS
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
Promise.resolve().then(()=>{
|
||||||
|
if(options.all === true) {
|
||||||
|
options.params.rows = LIST_ALL_ROWS;
|
||||||
|
}
|
||||||
|
return Vue.http.get(options.path, {
|
||||||
|
params: options.params
|
||||||
|
});
|
||||||
|
}).then((res)=>{
|
||||||
|
let body = getJsonBody(res.body);
|
||||||
|
if(options.all === true && body.total_count > LIST_ALL_ROWS) {
|
||||||
|
return Vue.http.get(options.path, {
|
||||||
|
params: _.merge(options.params, {
|
||||||
|
rows: body.total_count
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Promise.resolve(res);
|
||||||
|
}
|
||||||
|
}).then((res)=>{
|
||||||
|
let body = getJsonBody(res.body);
|
||||||
|
let lastPage = Math.ceil( body.total_count / options.params.rows );
|
||||||
|
if(options.all === true) {
|
||||||
|
lastPage = 1;
|
||||||
|
}
|
||||||
|
resolve({
|
||||||
|
items: _.get(body, options.root, []),
|
||||||
|
lastPage: lastPage
|
||||||
|
});
|
||||||
|
}).catch((err)=>{
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -1,69 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
import _ from 'lodash';
|
|
||||||
import Vue from 'vue';
|
|
||||||
import { getJsonBody } from './utils'
|
|
||||||
|
|
||||||
export function getAllDevices(options) {
|
|
||||||
return new Promise((resolve, reject)=>{
|
|
||||||
let rows = _.get(options, 'rows', 25);
|
|
||||||
let page = _.get(options, 'page', 1);
|
|
||||||
Vue.http.get('/api/pbxdevices/', null, {
|
|
||||||
params: {
|
|
||||||
rows: rows,
|
|
||||||
page: page
|
|
||||||
}
|
|
||||||
}).then((result)=>{
|
|
||||||
let body = getJsonBody(result.body);
|
|
||||||
let totalCount = body.totalCount;
|
|
||||||
let lastPage = Math.ceil(totalCount / rows);
|
|
||||||
let items = _.get(body, '_embedded.ngcp:pbxdevices');
|
|
||||||
resolve({
|
|
||||||
lastPage: lastPage,
|
|
||||||
items: items
|
|
||||||
});
|
|
||||||
}).catch((err)=>{
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAllProfiles() {
|
|
||||||
return new Promise((resolve, reject)=>{
|
|
||||||
Vue.http.get('/api/pbxdeviceprofiles/').then((result)=>{
|
|
||||||
let body = getJsonBody(result.body);
|
|
||||||
resolve(_.get(body, '_embedded.ngcp:pbxdeviceprofiles'));
|
|
||||||
}).catch((err)=>{
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAllModels() {
|
|
||||||
return new Promise((resolve, reject)=>{
|
|
||||||
Vue.http.get('/api/pbxdevicemodels/').then((result)=>{
|
|
||||||
let body = getJsonBody(result.body);
|
|
||||||
resolve(_.get(body, '_embedded.ngcp:pbxdevicemodels'));
|
|
||||||
}).catch((err)=>{
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDeviceList() {
|
|
||||||
return new Promise((resolve, reject)=>{
|
|
||||||
Promise.all([
|
|
||||||
getAllDevices(),
|
|
||||||
getAllProfiles(),
|
|
||||||
getAllModels()
|
|
||||||
]).then((results)=>{
|
|
||||||
resolve({
|
|
||||||
devices: results[0],
|
|
||||||
profiles: results[1],
|
|
||||||
models: results[2]
|
|
||||||
});
|
|
||||||
}).catch((err)=>{
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in new issue