Merge "Fix ports tab at Launch Instance dialog"

This commit is contained in:
Zuul 2023-07-26 16:53:03 +00:00 committed by Gerrit Code Review
commit b4554a1951
2 changed files with 30 additions and 6 deletions

View File

@ -27,12 +27,18 @@
.controller('LaunchInstanceNetworkPortController', LaunchInstanceNetworkPortController);
LaunchInstanceNetworkPortController.$inject = [
'$scope',
'horizon.dashboard.project.workflow.launch-instance.basePath',
'launchInstanceModel',
'horizon.framework.widgets.action-list.button-tooltip.row-warning.service'
];
function LaunchInstanceNetworkPortController(basePath, launchInstanceModel, tooltipService) {
function LaunchInstanceNetworkPortController(
$scope,
basePath,
launchInstanceModel,
tooltipService
) {
var ctrl = this;
ctrl.portStatuses = {
@ -54,6 +60,20 @@
'virtio-forwarder': gettext('Virtio Forwarder')
};
ctrl.ports = [];
var portsWatcher = $scope.$watchCollection(function() {
return launchInstanceModel.ports;
}, function (newValue, oldValue, scope) {
var ctrl = scope.ctrl;
ctrl.ports = newValue;
ctrl.isPortsObjGenerated = false;
});
$scope.$on('$destroy', function() {
portsWatcher();
});
function getPortStatus(status) {
return ctrl.portStatuses[status];
}
@ -62,12 +82,11 @@
return ctrl.portAdminStates[state];
}
var portsArr = launchInstanceModel.ports;
ctrl.portsObj = {};
ctrl.isPortsObjGenerated = false;
function getNameOrID(id) {
ctrl.portsObj = ctrl.getPortsObj(portsArr);
ctrl.portsObj = ctrl.getPortsObj(ctrl.ports);
var port = ctrl.portsObj[id];
return ctrl.nameOrID(port);
}

View File

@ -23,10 +23,15 @@
beforeEach(module('horizon.dashboard.project.workflow.launch-instance'));
describe('LaunchInstanceNetworkPortController', function() {
var ctrl;
var ctrl, scope;
var port = {name: 'test_name', id: 'test_id'};
beforeEach(inject(function($controller) {
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
// Track calls to $watchCollection
spyOn(scope, '$watchCollection').and.callThrough();
var model = {
newInstanceSpec: {
ports: ['port-a']
@ -35,7 +40,7 @@
};
ctrl = $controller('LaunchInstanceNetworkPortController',
{ launchInstanceModel: model });
{ $scope:scope, launchInstanceModel: model });
}));
it('has correct ports statuses', function() {