Merge "Eliminate unnecessary event handling code"

This commit is contained in:
Jenkins 2017-05-17 00:58:39 +00:00 committed by Gerrit Code Review
commit e9648b7e9d
9 changed files with 67 additions and 100 deletions

View File

@ -28,11 +28,18 @@
function createPortService($uibModal, basePath) { function createPortService($uibModal, basePath) {
var service = { var service = {
modal: modal createPort: createPort
}; };
return service; return service;
function modal(node) { /**
* @description Launch a modal dialog that will guide the user
* in creating a new port
*
* @param {object} node - Node to which the port will be associated
* @return {promise} Object describing the created port
*/
function createPort(node) {
var options = { var options = {
controller: 'CreatePortController as ctrl', controller: 'CreatePortController as ctrl',
backdrop: 'static', backdrop: 'static',

View File

@ -28,10 +28,10 @@
function editNodeService($uibModal, basePath) { function editNodeService($uibModal, basePath) {
var service = { var service = {
modal: modal editNode: editNode
}; };
function modal(node) { function editNode(node) {
var options = { var options = {
controller: 'EditNodeController as ctrl', controller: 'EditNodeController as ctrl',
backdrop: 'static', backdrop: 'static',
@ -42,7 +42,7 @@
}, },
templateUrl: basePath + '/base-node/base-node.html' templateUrl: basePath + '/base-node/base-node.html'
}; };
return $uibModal.open(options); return $uibModal.open(options).result;
} }
return service; return service;

View File

@ -28,10 +28,17 @@
function editPortService($uibModal, basePath) { function editPortService($uibModal, basePath) {
var service = { var service = {
modal: modal editPort: editPort
}; };
function modal(port, node) { /**
* @description: Edit a specified port
*
* @param {object} port - Port to be edited
* @param {object} node - Node to which the port is attached
* @return {promise} Promise containing the updated port
*/
function editPort(port, node) {
var options = { var options = {
controller: 'EditPortController as ctrl', controller: 'EditPortController as ctrl',
backdrop: 'static', backdrop: 'static',

View File

@ -31,6 +31,12 @@
enrollNode: enrollNode enrollNode: enrollNode
}; };
/**
* @description Launch a modal dialog that will guide the user
* in enrolling a new node
*
* @return {promise} Object describing the enrolled node
*/
function enrollNode() { function enrollNode() {
var options = { var options = {
controller: 'EnrollNodeController as ctrl', controller: 'EnrollNodeController as ctrl',

View File

@ -45,7 +45,6 @@
'horizon.app.core.openstack-service-api.ironic', 'horizon.app.core.openstack-service-api.ironic',
'horizon.dashboard.admin.ironic.events', 'horizon.dashboard.admin.ironic.events',
'horizon.framework.widgets.modal.deleteModalService', 'horizon.framework.widgets.modal.deleteModalService',
'horizon.dashboard.admin.ironic.create-port.service',
'horizon.dashboard.admin.ironic.clean-node.service', 'horizon.dashboard.admin.ironic.clean-node.service',
'$q', '$q',
'$rootScope' '$rootScope'
@ -54,12 +53,10 @@
function actions(ironic, function actions(ironic,
ironicEvents, ironicEvents,
deleteModalService, deleteModalService,
createPortService,
cleanNodeService, cleanNodeService,
$q, $q,
$rootScope) { $rootScope) {
var service = { var service = {
createPort: createPort,
deleteNode: deleteNode, deleteNode: deleteNode,
deletePort: deletePort, deletePort: deletePort,
setPowerState: setPowerState, setPowerState: setPowerState,
@ -178,10 +175,6 @@
} }
} }
function createPort(node) {
return createPortService.modal(node);
}
function deletePort(ports) { function deletePort(ports) {
var context = { var context = {
labels: { labels: {

View File

@ -24,14 +24,13 @@
IronicNodeDetailsController.$inject = [ IronicNodeDetailsController.$inject = [
'$scope', '$scope',
'$rootScope',
'$location', '$location',
'horizon.framework.widgets.toast.service', 'horizon.framework.widgets.toast.service',
'horizon.app.core.openstack-service-api.ironic', 'horizon.app.core.openstack-service-api.ironic',
'horizon.dashboard.admin.ironic.events',
'horizon.dashboard.admin.ironic.actions', 'horizon.dashboard.admin.ironic.actions',
'horizon.dashboard.admin.ironic.basePath', 'horizon.dashboard.admin.ironic.basePath',
'horizon.dashboard.admin.ironic.edit-node.service', 'horizon.dashboard.admin.ironic.edit-node.service',
'horizon.dashboard.admin.ironic.create-port.service',
'horizon.dashboard.admin.ironic.edit-port.service', 'horizon.dashboard.admin.ironic.edit-port.service',
'horizon.dashboard.admin.ironic.maintenance.service', 'horizon.dashboard.admin.ironic.maintenance.service',
'horizon.dashboard.admin.ironic.node-state-transition.service', 'horizon.dashboard.admin.ironic.node-state-transition.service',
@ -39,14 +38,13 @@
]; ];
function IronicNodeDetailsController($scope, function IronicNodeDetailsController($scope,
$rootScope,
$location, $location,
toastService, toastService,
ironic, ironic,
ironicEvents,
actions, actions,
basePath, basePath,
editNodeService, editNodeService,
createPortService,
editPortService, editPortService,
maintenanceService, maintenanceService,
nodeStateTransitionService, nodeStateTransitionService,
@ -94,31 +92,6 @@
$scope.isDefined = angular.isDefined; $scope.isDefined = angular.isDefined;
var editNodeHandler =
$rootScope.$on(ironicEvents.EDIT_NODE_SUCCESS,
function() {
init();
});
var createPortHandler =
$rootScope.$on(ironicEvents.CREATE_PORT_SUCCESS,
function() {
init();
});
var deletePortHandler =
$rootScope.$on(ironicEvents.DELETE_PORT_SUCCESS,
function() {
init();
$scope.$broadcast('hzTable:clearSelected');
});
$scope.$on('$destroy', function() {
editNodeHandler();
createPortHandler();
deletePortHandler();
});
init(); init();
/** /**
@ -240,7 +213,9 @@
* @return {void} * @return {void}
*/ */
function editNode() { function editNode() {
editNodeService.modal(ctrl.node); editNodeService.editNode(ctrl.node).then(function() {
ctrl.refresh();
});
} }
/** /**
@ -251,7 +226,9 @@
* @return {void} * @return {void}
*/ */
function createPort() { function createPort() {
ctrl.actions.createPort(ctrl.node); createPortService.createPort(ctrl.node).then(function() {
ctrl.refresh();
});
} }
/** /**
@ -261,7 +238,7 @@
* @return {void} * @return {void}
*/ */
function editPort(port) { function editPort(port) {
editPortService.modal(port, ctrl.node).then(function() { editPortService.editPort(port, ctrl.node).then(function() {
ctrl.refresh(); ctrl.refresh();
}); });
} }
@ -274,7 +251,9 @@
* @return {void} * @return {void}
*/ */
function deletePort(ports) { function deletePort(ports) {
actions.deletePort(ports); actions.deletePort(ports).then(function() {
ctrl.refresh();
});
} }
/** /**

View File

@ -55,12 +55,6 @@
callback="ctrl.toggleConsoleMode"> callback="ctrl.toggleConsoleMode">
{$ ctrl.node.console_enabled ? 'Disable console' : 'Enable console' | translate $} {$ ctrl.node.console_enabled ? 'Disable console' : 'Enable console' | translate $}
</action> </action>
<action button-type="menu-item"
disabled="isDefined(ctrl.nodeValidationMap.console)
&& ctrl.nodeValidationMap.console.result===false"
callback="ctrl.toggleConsoleMode">
{$ ctrl.node.console_enabled ? 'Disable console' : 'Enable console' | translate $}
</action>
</menu> </menu>
</action-list> </action-list>
</div> </div>

View File

@ -22,29 +22,25 @@
.controller('IronicNodeListController', IronicNodeListController); .controller('IronicNodeListController', IronicNodeListController);
IronicNodeListController.$inject = [ IronicNodeListController.$inject = [
'$scope',
'$rootScope',
'$q', '$q',
'horizon.framework.widgets.toast.service', 'horizon.framework.widgets.toast.service',
'horizon.app.core.openstack-service-api.ironic', 'horizon.app.core.openstack-service-api.ironic',
'horizon.dashboard.admin.ironic.events',
'horizon.dashboard.admin.ironic.actions', 'horizon.dashboard.admin.ironic.actions',
'horizon.dashboard.admin.ironic.maintenance.service', 'horizon.dashboard.admin.ironic.maintenance.service',
'horizon.dashboard.admin.ironic.enroll-node.service', 'horizon.dashboard.admin.ironic.enroll-node.service',
'horizon.dashboard.admin.ironic.edit-node.service', 'horizon.dashboard.admin.ironic.edit-node.service',
'horizon.dashboard.admin.ironic.create-port.service',
'horizon.dashboard.admin.ironic.node-state-transition.service' 'horizon.dashboard.admin.ironic.node-state-transition.service'
]; ];
function IronicNodeListController($scope, function IronicNodeListController($q,
$rootScope,
$q,
toastService, toastService,
ironic, ironic,
ironicEvents,
actions, actions,
maintenanceService, maintenanceService,
enrollNodeService, enrollNodeService,
editNodeService, editNodeService,
createPortService,
nodeStateTransitionService) { nodeStateTransitionService) {
var ctrl = this; var ctrl = this;
@ -55,6 +51,8 @@
ctrl.enrollNode = enrollNode; ctrl.enrollNode = enrollNode;
ctrl.editNode = editNode; ctrl.editNode = editNode;
ctrl.deleteNode = deleteNode;
ctrl.createPort = createPort;
ctrl.refresh = refresh; ctrl.refresh = refresh;
ctrl.getNodeStateTransitions = getNodeStateTransitions; ctrl.getNodeStateTransitions = getNodeStateTransitions;
@ -95,41 +93,6 @@
} }
]; ];
// Listen for the creation of new nodes, and update the node list
var enrollNodeHandler =
$rootScope.$on(ironicEvents.ENROLL_NODE_SUCCESS,
function() {
init();
});
var deleteNodeHandler = $rootScope.$on(ironicEvents.DELETE_NODE_SUCCESS,
function() {
init();
});
var editNodeHandler = $rootScope.$on(ironicEvents.EDIT_NODE_SUCCESS,
function() {
init();
});
var createPortHandler = $rootScope.$on(ironicEvents.CREATE_PORT_SUCCESS,
function() {
init();
});
var deletePortHandler = $rootScope.$on(ironicEvents.DELETE_PORT_SUCCESS,
function() {
init();
});
$scope.$on('destroy', function() {
enrollNodeHandler();
deleteNodeHandler();
editNodeHandler();
createPortHandler();
deletePortHandler();
});
init(); init();
// RETRIVE NODES AND PORTS // RETRIVE NODES AND PORTS
@ -162,11 +125,29 @@
} }
function enrollNode() { function enrollNode() {
enrollNodeService.enrollNode(); enrollNodeService.enrollNode().then(function() {
ctrl.refresh();
});
} }
function editNode(node) { function editNode(node) {
editNodeService.modal(node); editNodeService.editNode(node).then(function() {
ctrl.refresh();
});
}
function deleteNode(nodes) {
actions.deleteNode(nodes).then(
function() {
ctrl.refresh();
}
);
}
function createPort(node) {
createPortService.createPort(node).then(function() {
ctrl.refresh();
});
} }
function refresh() { function refresh() {

View File

@ -29,7 +29,7 @@
<action-list uib-dropdown class="pull-right"> <action-list uib-dropdown class="pull-right">
<action button-type="split-button" <action button-type="split-button"
action-classes="'btn btn-default btn-sm'" action-classes="'btn btn-default btn-sm'"
callback="table.actions.deleteNode" callback="table.deleteNode"
item="tCtrl.selected" item="tCtrl.selected"
disabled="tCtrl.selected.length === 0"> disabled="tCtrl.selected.length === 0">
<span class="fa fa-trash"></span> <span class="fa fa-trash"></span>
@ -165,14 +165,14 @@
{$ ::'Maintenance off' | translate $} {$ ::'Maintenance off' | translate $}
</action> </action>
<action button-type="menu-item" <action button-type="menu-item"
callback="table.actions.deleteNode" callback="table.deleteNode"
disabled="!(node.provision_state === 'available' || node.provision_state === 'nostate' || node.provision_state === 'manageable' || node.provision_state === 'enroll')" disabled="!(node.provision_state === 'available' || node.provision_state === 'nostate' || node.provision_state === 'manageable' || node.provision_state === 'enroll')"
item="[node]"> item="[node]">
<span class="fa fa-trash"></span> <span class="fa fa-trash"></span>
{$ ::'Delete node' | translate $} {$ ::'Delete node' | translate $}
</action> </action>
<action button-type="menu-item" <action button-type="menu-item"
callback="table.actions.createPort" callback="table.createPort"
item="node"> item="node">
{$ ::'Create port' | translate $} {$ ::'Create port' | translate $}
</action> </action>