diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.js
index 1ff2f355..b91995b1 100644
--- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.js
+++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.js
@@ -39,62 +39,22 @@
function HealthMonitorDetailController(api, $routeParams) {
var ctrl = this;
- ctrl.healthmonitor = {};
- ctrl.pool = {};
- ctrl.listener = {};
- ctrl.loadbalancer = {};
-
- var healthmonitorID = $routeParams.healthmonitorId;
init();
////////////////////////////////
function init() {
- api.getHealthMonitor(healthmonitorID).success(healthMonitorSuccess);
+ api.getHealthMonitor($routeParams.healthmonitorId).success(set('healthmonitor'));
+ api.getPool($routeParams.poolId).success(set('pool'));
+ api.getListener($routeParams.listenerId).success(set('listener'));
+ api.getLoadBalancer($routeParams.loadbalancerId).success(set('loadbalancer'));
}
- function healthMonitorSuccess(response) {
- ctrl.healthmonitor = response;
-
- if (ctrl.healthmonitor.hasOwnProperty('pools') &&
- ctrl.healthmonitor.pools.length > 0) {
- getPoolDetails(ctrl.healthmonitor.pools[0].id);
- }
- }
-
- function getPoolDetails(poolId) {
- api.getPool(poolId).success(poolSuccess);
- }
-
- function poolSuccess(response) {
- ctrl.pool = response;
-
- if (ctrl.pool.hasOwnProperty('listeners') &&
- ctrl.pool.listeners.length > 0) {
- getListenerDetails(ctrl.pool.listeners[0].id);
- }
- }
-
- function getListenerDetails(listenerId) {
- api.getListener(listenerId).success(listenerSuccess);
- }
-
- function listenerSuccess(response) {
- ctrl.listener = response;
-
- if (ctrl.listener.hasOwnProperty('loadbalancers') &&
- ctrl.listener.loadbalancers.length > 0) {
- getLoadBalancerDetails(ctrl.listener.loadbalancers[0].id);
- }
- }
-
- function getLoadBalancerDetails(loadbalancerId) {
- api.getLoadBalancer(loadbalancerId).success(loadbalancerSuccess);
- }
-
- function loadbalancerSuccess(response) {
- ctrl.loadbalancer = response;
+ function set(property) {
+ return angular.bind(null, function setProp(property, value) {
+ ctrl[property] = value;
+ }, property);
}
}
diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.spec.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.spec.js
index a3345e48..202dec9c 100644
--- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.spec.js
+++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.spec.js
@@ -17,36 +17,12 @@
'use strict';
describe('LBaaS v2 Healthmonitor Detail Controller', function() {
- var controller, lbaasv2API, healthmonitor, pool, listener, loadbalancer;
+ var lbaasv2API, ctrl;
- function fakeHealthMonitorAPI() {
+ function fakeAPI() {
return {
success: function(callback) {
- callback(healthmonitor);
- }
- };
- }
-
- function fakePoolAPI() {
- return {
- success: function(callback) {
- callback(pool);
- }
- };
- }
-
- function fakeListenerAPI() {
- return {
- success: function(callback) {
- callback(listener);
- }
- };
- }
-
- function fakeLoadBalancerAPI() {
- return {
- success: function(callback) {
- callback(loadbalancer);
+ callback('foo');
}
};
}
@@ -61,60 +37,30 @@
beforeEach(inject(function($injector) {
lbaasv2API = $injector.get('horizon.app.core.openstack-service-api.lbaasv2');
- controller = $injector.get('$controller');
- spyOn(lbaasv2API, 'getHealthMonitor').and.callFake(fakeHealthMonitorAPI);
- spyOn(lbaasv2API, 'getPool').and.callFake(fakePoolAPI);
- spyOn(lbaasv2API, 'getListener').and.callFake(fakeListenerAPI);
- spyOn(lbaasv2API, 'getLoadBalancer').and.callFake(fakeLoadBalancerAPI);
+ spyOn(lbaasv2API, 'getHealthMonitor').and.callFake(fakeAPI);
+ spyOn(lbaasv2API, 'getPool').and.callFake(fakeAPI);
+ spyOn(lbaasv2API, 'getListener').and.callFake(fakeAPI);
+ spyOn(lbaasv2API, 'getLoadBalancer').and.callFake(fakeAPI);
+ var controller = $injector.get('$controller');
+ ctrl = controller('HealthMonitorDetailController', {
+ $routeParams: {
+ loadbalancerId: 'loadbalancerId',
+ listenerId: 'listenerId',
+ poolId: 'poolId',
+ healthmonitorId: 'healthmonitorId'
+ }
+ });
}));
- function createController() {
- return controller('HealthMonitorDetailController', {
- api: lbaasv2API,
- $routeParams: { healthmonitorId: 'healthmonitorId' }
- });
- }
-
it('should invoke lbaasv2 apis', function() {
- healthmonitor = { id: 'healthmonitorId', pools: [{id: 'poolId'}] };
- pool = { id: 'poolId', listeners: [{id: 'listenerId'}] };
- listener = { id: 'listenerId', loadbalancers: [{id: 'loadbalancerId'}] };
- loadbalancer = { id: 'loadbalancerId' };
- createController();
expect(lbaasv2API.getHealthMonitor).toHaveBeenCalledWith('healthmonitorId');
expect(lbaasv2API.getPool).toHaveBeenCalledWith('poolId');
expect(lbaasv2API.getListener).toHaveBeenCalledWith('listenerId');
expect(lbaasv2API.getLoadBalancer).toHaveBeenCalledWith('loadbalancerId');
- });
-
- it('should not invoke the getPool, getListener or getLoadBalancer lbaasv2 api', function() {
- healthmonitor = { id: 'healthmonitorId', pools: [] };
- createController();
- expect(lbaasv2API.getHealthMonitor).toHaveBeenCalledWith('healthmonitorId');
- expect(lbaasv2API.getPool).not.toHaveBeenCalled();
- expect(lbaasv2API.getListener).not.toHaveBeenCalled();
- expect(lbaasv2API.getLoadBalancer).not.toHaveBeenCalled();
- });
-
- it('should not invoke the getListener or getLoadBalancer lbaasv2 api', function() {
- healthmonitor = { id: 'healthmonitorId', pools: [{id: 'poolId'}] };
- pool = { id: 'poolId', listeners: [] };
- createController();
- expect(lbaasv2API.getHealthMonitor).toHaveBeenCalledWith('healthmonitorId');
- expect(lbaasv2API.getPool).toHaveBeenCalledWith('poolId');
- expect(lbaasv2API.getListener).not.toHaveBeenCalled();
- expect(lbaasv2API.getLoadBalancer).not.toHaveBeenCalled();
- });
-
- it('should not invoke getLoadBalancer lbaasv2 api', function() {
- healthmonitor = { id: 'healthmonitorId', pools: [{id: 'poolId'}] };
- pool = { id: 'poolId', listeners: [{id: 'listenerId'}] };
- listener = { id: 'listenerId', loadbalancers: [] };
- createController();
- expect(lbaasv2API.getHealthMonitor).toHaveBeenCalledWith('healthmonitorId');
- expect(lbaasv2API.getPool).toHaveBeenCalledWith('poolId');
- expect(lbaasv2API.getListener).toHaveBeenCalledWith('listenerId');
- expect(lbaasv2API.getLoadBalancer).not.toHaveBeenCalled();
+ expect(ctrl.loadbalancer).toBe('foo');
+ expect(ctrl.listener).toBe('foo');
+ expect(ctrl.pool).toBe('foo');
+ expect(ctrl.healthmonitor).toBe('foo');
});
});
diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.html b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.html
index ed2d6630..96d0533c 100644
--- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.html
+++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.html
@@ -2,9 +2,9 @@
diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js
index 70afc150..35e9de01 100644
--- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js
+++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js
@@ -54,27 +54,32 @@
];
function config($provide, $windowProvider, $routeProvider) {
- var href = '/project/ngloadbalancersv2/';
var basePath = $windowProvider.$get().STATIC_URL + 'dashboard/project/lbaasv2/';
$provide.constant('horizon.dashboard.project.lbaasv2.basePath', basePath);
+ var loadbalancers = '/project/ngloadbalancersv2';
+ var listener = loadbalancers + '/:loadbalancerId/listeners/:listenerId';
+ var pool = listener + '/pools/:poolId';
+ var member = pool + '/members/:memberId';
+ var healthmonitor = pool + '/healthmonitors/:healthmonitorId';
+
$routeProvider
- .when(href, {
+ .when(loadbalancers, {
templateUrl: basePath + 'loadbalancers/table.html'
})
- .when(href + 'detail/:loadbalancerId', {
+ .when(loadbalancers + '/:loadbalancerId', {
templateUrl: basePath + 'loadbalancers/detail.html'
})
- .when(href + 'listeners/detail/:listenerId', {
+ .when(listener, {
templateUrl: basePath + 'listeners/detail.html'
})
- .when(href + 'pools/detail/:poolId', {
+ .when(pool, {
templateUrl: basePath + 'pools/detail.html'
})
- .when(href + 'pools/:poolId/members/detail/:memberId', {
+ .when(member, {
templateUrl: basePath + 'members/detail.html'
})
- .when(href + 'healthmonitors/detail/:healthmonitorId', {
+ .when(healthmonitor, {
templateUrl: basePath + 'healthmonitors/detail.html'
});
}
diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js
index 62e08a26..a4513298 100644
--- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js
+++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js
@@ -95,45 +95,36 @@
});
it('should route URLs', function () {
- var href = '/project/ngloadbalancersv2/';
- var routes = [
- [
- href,
- {
- templateUrl: basePath + 'loadbalancers/table.html'
- }
- ],
- [
- href + 'detail/:loadbalancerId',
- {
- templateUrl: basePath + 'loadbalancers/detail.html'
- }
- ],
- [
- href + 'listeners/detail/:listenerId',
- {
- templateUrl: basePath + 'listeners/detail.html'
- }
- ],
- [
- href + 'pools/detail/:poolId',
- {
- templateUrl: basePath + 'pools/detail.html'
- }
- ],
- [
- href + 'pools/:poolId/members/detail/:memberId',
- {
- templateUrl: basePath + 'members/detail.html'
- }
- ],
- [
- href + 'healthmonitors/detail/:healthmonitorId',
- {
- templateUrl: basePath + 'healthmonitors/detail.html'
- }
- ]
- ];
+ var loadbalancers = '/project/ngloadbalancersv2';
+ var listener = loadbalancers + '/:loadbalancerId/listeners/:listenerId';
+ var pool = listener + '/pools/:poolId';
+ var member = pool + '/members/:memberId';
+ var healthmonitor = pool + '/healthmonitors/:healthmonitorId';
+ var routes = [[
+ loadbalancers, {
+ templateUrl: basePath + 'loadbalancers/table.html'
+ }
+ ], [
+ loadbalancers + '/:loadbalancerId', {
+ templateUrl: basePath + 'loadbalancers/detail.html'
+ }
+ ], [
+ listener, {
+ templateUrl: basePath + 'listeners/detail.html'
+ }
+ ], [
+ pool, {
+ templateUrl: basePath + 'pools/detail.html'
+ }
+ ], [
+ member, {
+ templateUrl: basePath + 'members/detail.html'
+ }
+ ], [
+ healthmonitor, {
+ templateUrl: basePath + 'healthmonitors/detail.html'
+ }
+ ]];
expect($routeProvider.when.calls.count()).toBe(6);
angular.forEach($routeProvider.when.calls.all(), function(call, i) {
diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.js
index 48078517..bc0f41b5 100644
--- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.js
+++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.js
@@ -39,34 +39,20 @@
function ListenerDetailController(api, $routeParams) {
var ctrl = this;
- ctrl.listener = {};
- ctrl.loadbalancer = {};
-
- var listenerID = $routeParams.listenerId;
init();
////////////////////////////////
function init() {
- api.getListener(listenerID).success(listenerSuccess);
+ api.getListener($routeParams.listenerId).success(set('listener'));
+ api.getLoadBalancer($routeParams.loadbalancerId).success(set('loadbalancer'));
}
- function listenerSuccess(response) {
- ctrl.listener = response;
-
- if (ctrl.listener.hasOwnProperty('loadbalancers') &&
- ctrl.listener.loadbalancers.length > 0) {
- getLoadBalancerDetails(ctrl.listener.loadbalancers[0].id);
- }
- }
-
- function getLoadBalancerDetails(loadbalancerId) {
- api.getLoadBalancer(loadbalancerId).success(loadbalancerSuccess);
- }
-
- function loadbalancerSuccess(response) {
- ctrl.loadbalancer = response;
+ function set(property) {
+ return angular.bind(null, function setProp(property, value) {
+ ctrl[property] = value;
+ }, property);
}
}
diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.spec.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.spec.js
index ddc56984..05ac034b 100644
--- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.spec.js
+++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.spec.js
@@ -17,12 +17,12 @@
'use strict';
describe('LBaaS v2 Listener Detail Controller', function() {
- var controller, lbaasv2API, listener;
+ var lbaasv2API, ctrl;
function fakeAPI() {
return {
success: function(callback) {
- callback(listener);
+ callback('foo');
}
};
}
@@ -37,29 +37,22 @@
beforeEach(inject(function($injector) {
lbaasv2API = $injector.get('horizon.app.core.openstack-service-api.lbaasv2');
- controller = $injector.get('$controller');
spyOn(lbaasv2API, 'getListener').and.callFake(fakeAPI);
spyOn(lbaasv2API, 'getLoadBalancer').and.callFake(fakeAPI);
+ var controller = $injector.get('$controller');
+ ctrl = controller('ListenerDetailController', {
+ $routeParams: {
+ loadbalancerId: 'loadbalancerId',
+ listenerId: 'listenerId'
+ }
+ });
}));
- function createController() {
- return controller('ListenerDetailController', {
- api: lbaasv2API,
- $routeParams: { listenerId: '1234' }
- });
- }
-
it('should invoke lbaasv2 apis', function() {
- listener = { id: '1234', loadbalancers: [{id: '5678'}] };
- createController();
- expect(lbaasv2API.getListener).toHaveBeenCalledWith('1234');
- expect(lbaasv2API.getLoadBalancer).toHaveBeenCalledWith('5678');
- });
-
- it('should not invoke getLoadBalancer lbaasv2 api', function() {
- listener = { id: '1234', loadbalancers: [] };
- createController();
- expect(lbaasv2API.getListener).toHaveBeenCalledWith('1234');
+ expect(lbaasv2API.getListener).toHaveBeenCalledWith('listenerId');
+ expect(lbaasv2API.getLoadBalancer).toHaveBeenCalledWith('loadbalancerId');
+ expect(ctrl.loadbalancer).toBe('foo');
+ expect(ctrl.listener).toBe('foo');
});
});
diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html
index b0a60537..331194ed 100644
--- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html
+++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html
@@ -2,7 +2,7 @@