Allows creation of resources without forcing the creation of children

Change-Id: I6e2a5b838a47842205d44ef1204c437331829728
This commit is contained in:
Gregory Thiemonge 2020-11-19 11:57:13 +01:00
parent 400c1194e0
commit 6ce037518a
12 changed files with 651 additions and 487 deletions

View File

@ -39,6 +39,7 @@
function ListenerDetailsController($scope, gettext) { function ListenerDetailsController($scope, gettext) {
var ctrl = this; var ctrl = this;
ctrl.protocolChange = protocolChange; ctrl.protocolChange = protocolChange;
ctrl.createChange = createChange;
// Error text for invalid fields // Error text for invalid fields
ctrl.portNumberError = gettext('The port must be a number between 1 and 65535.'); ctrl.portNumberError = gettext('The port must be a number between 1 and 65535.');
@ -71,6 +72,14 @@
} }
} }
function createChange() {
if ($scope.model.context.create_listener === false) {
// Disabling listener form disables pool form and monitor form
$scope.model.context.create_pool = false;
$scope.model.context.create_monitor = false;
}
}
function listenerPortExists(port) { function listenerPortExists(port) {
return $scope.model.listenerPorts.some(function(element) { return $scope.model.listenerPorts.some(function(element) {
return element === port; return element === port;

View File

@ -36,6 +36,11 @@
}; };
scope = { scope = {
model: { model: {
context: {
create_listener: true,
create_pool: true,
create_monitor: true
},
listenerPorts: [80], listenerPorts: [80],
members: [{port: ''}, {port: ''}], members: [{port: ''}, {port: ''}],
spec: { spec: {
@ -118,6 +123,18 @@
}); });
}); });
it('should update create_pool and create_monitor flags', function() {
scope.model.context.create_listener = true;
ctrl.createChange();
expect(scope.model.context.create_pool).toBe(true);
expect(scope.model.context.create_monitor).toBe(true);
scope.model.context.create_listener = false;
ctrl.createChange();
expect(scope.model.context.create_pool).toBe(false);
expect(scope.model.context.create_monitor).toBe(false);
});
}); });
}); });
})(); })();

View File

@ -1,6 +1,26 @@
<div ng-controller="ListenerDetailsController as ctrl"> <div ng-controller="ListenerDetailsController as ctrl">
<p translate>Provide the details for the listener.</p> <p translate>Provide the details for the listener.</p>
<div class="row" ng-if="model.context.resource !== 'listener' && !model.context.id">
<div class="col-xs-12 col-sm-8 col-md-6">
<div class="form-group">
<label class="control-label required" translate>Create Listener</label>
<div class="form-field">
<div class="btn-group">
<label class="btn btn-default"
ng-repeat="option in model.yesNoOptions"
ng-model="model.context.create_listener"
ng-change="ctrl.createChange()"
uib-btn-radio="option.value">{$ ::option.label $}</label>
</div>
</div>
</div>
</div>
</div>
<div ng-if="model.context.create_listener">
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-8 col-md-6"> <div class="col-xs-12 col-sm-8 col-md-6">
@ -252,5 +272,6 @@
</div> </div>
</div> </div>
</div>
</div> </div>

View File

@ -1,4 +1,5 @@
<div ng-controller="MemberDetailsController as ctrl"> <div ng-controller="MemberDetailsController as ctrl"
ng-if="model.context.create_pool || model.context.id">
<p translate>Add members to the load balancer pool.</p> <p translate>Add members to the load balancer pool.</p>
<transfer-table tr-model="ctrl.tableData" <transfer-table tr-model="ctrl.tableData"
limits="::ctrl.tableLimits" limits="::ctrl.tableLimits"

View File

@ -137,7 +137,10 @@
model.context = { model.context = {
resource: resource, resource: resource,
id: id, id: id,
submit: null submit: null,
create_listener: true,
create_pool: true,
create_monitor: true
}; };
model.certificates = []; model.certificates = [];

View File

@ -55,6 +55,16 @@
} }
}); });
ctrl.createChange = createChange;
function createChange() {
if ($scope.model.context.create_monitor) {
// Enabling pool form enables listener form and pool form
$scope.model.context.create_listener = true;
$scope.model.context.create_pool = true;
}
}
// Error text for invalid fields // Error text for invalid fields
/* eslint-disable max-len */ /* eslint-disable max-len */
ctrl.intervalError = gettext('The health check interval must be greater than or equal to the timeout.'); ctrl.intervalError = gettext('The health check interval must be greater than or equal to the timeout.');

View File

@ -73,6 +73,30 @@
to: 1 to: 1
}); });
}); });
it('should update create_pool and create_monitor flags', function() {
scope.model = {
context: {
create_listener: false,
create_pool: false,
create_monitor: true
}
};
ctrl.createChange();
expect(scope.model.context.create_listener).toBe(true);
expect(scope.model.context.create_pool).toBe(true);
scope.model = {
context: {
create_listener: false,
create_pool: false,
create_monitor: false
}
};
ctrl.createChange();
expect(scope.model.context.create_listener).toBe(false);
expect(scope.model.context.create_pool).toBe(false);
});
}); });
}); });
})(); })();

View File

@ -1,6 +1,26 @@
<div ng-controller="MonitorDetailsController as ctrl"> <div ng-controller="MonitorDetailsController as ctrl">
<p translate>Provide the details for the health monitor.</p> <p translate>Provide the details for the health monitor.</p>
<div class="row" ng-if="model.context.resource !== 'monitor' && !model.context.id">
<div class="col-xs-12 col-sm-8 col-md-6">
<div class="form-group">
<label class="control-label required" translate>Create Health Monitor</label>
<div class="form-field">
<div class="btn-group">
<label class="btn btn-default"
ng-repeat="option in model.yesNoOptions"
ng-model="model.context.create_monitor"
ng-change="ctrl.createChange()"
uib-btn-radio="option.value">{$ ::option.label $}</label>
</div>
</div>
</div>
</div>
</div>
<div ng-if="model.context.create_monitor">
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-8 col-md-6 col-lg-4"> <div class="col-xs-12 col-sm-8 col-md-6 col-lg-4">
@ -152,5 +172,6 @@
</div> </div>
</div> </div>
</div>
</div> </div>

View File

@ -38,6 +38,17 @@
function PoolDetailsController($scope, gettext) { function PoolDetailsController($scope, gettext) {
var ctrl = this; var ctrl = this;
ctrl.createChange = createChange;
function createChange() {
if ($scope.model.context.create_pool) {
// Enabling pool form enables listener form
$scope.model.context.create_listener = true;
} else {
// Disabling pool form disables monitor form
$scope.model.context.create_monitor = false;
}
}
// Error text for invalid fields // Error text for invalid fields
ctrl.tls_ciphersError = gettext('The cipher string must conform to OpenSSL syntax.'); ctrl.tls_ciphersError = gettext('The cipher string must conform to OpenSSL syntax.');

View File

@ -24,8 +24,16 @@
describe('PoolDetailsController', function() { describe('PoolDetailsController', function() {
var ctrl, scope; var ctrl, scope;
beforeEach(inject(function($controller, $rootScope) { beforeEach(inject(function($controller) {
scope = $rootScope.$new(); scope = {
model: {
context: {
create_listener: true,
create_pool: true,
create_monitor: true
}
}
};
ctrl = $controller('PoolDetailsController', { ctrl = $controller('PoolDetailsController', {
$scope: scope $scope: scope
}); });
@ -35,6 +43,18 @@
expect(ctrl.tls_ciphersError).toBeDefined(); expect(ctrl.tls_ciphersError).toBeDefined();
}); });
it('should update create_listener and create_monitor flags', function() {
scope.model.context.create_pool = true;
ctrl.createChange();
expect(scope.model.context.create_listener).toBe(true);
expect(scope.model.context.create_monitor).toBe(true);
scope.model.context.create_pool = false;
ctrl.createChange();
expect(scope.model.context.create_listener).toBe(true);
expect(scope.model.context.create_monitor).toBe(false);
});
}); });
}); });
})(); })();

View File

@ -1,6 +1,26 @@
<div ng-controller="PoolDetailsController as ctrl"> <div ng-controller="PoolDetailsController as ctrl">
<p translate>Provide the details for the pool.</p> <p translate>Provide the details for the pool.</p>
<div class="row" ng-if="model.context.resource !== 'pool' && !model.context.id">
<div class="col-xs-12 col-sm-8 col-md-6">
<div class="form-group">
<label class="control-label required" translate>Create Pool</label>
<div class="form-field">
<div class="btn-group">
<label class="btn btn-default"
ng-repeat="option in model.yesNoOptions"
ng-model="model.context.create_pool"
ng-change="ctrl.createChange()"
uib-btn-radio="option.value">{$ ::option.label $}</label>
</div>
</div>
</div>
</div>
</div>
<div ng-if="model.context.create_pool">
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-8 col-md-6"> <div class="col-xs-12 col-sm-8 col-md-6">
@ -66,7 +86,7 @@
ng-model="model.spec.pool.session_persistence.type"> ng-model="model.spec.pool.session_persistence.type">
<option value="">None</option> <option value="">None</option>
<option ng-repeat="type in model.types" <option ng-repeat="type in model.types"
ng-disabled="(model.spec.listener.protocol === 'UDP' || model.spec.listener.protocol === 'SCTP') && type !== 'SOURCE_IP'" ng-disabled="model.spec.listener.protocol === 'UDP' && type !== 'SOURCE_IP'"
value="{$ type $}"> value="{$ type $}">
{$ type $} {$ type $}
</option> </option>
@ -136,5 +156,5 @@
</div> </div>
</div> </div>
</div>
</div> </div>

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Allows the creation of single resources (i.e Load Balancer) without
enforcing the creation of children resources (Listeners, Pools, Health
monitors). A switch has been added in the children resource wizards to
avoid resource creation.