Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Bill Burke 2016-10-27 16:17:12 -04:00
commit 4cea1919f6
4 changed files with 86 additions and 20 deletions

View file

@ -2468,7 +2468,7 @@ module.controller('RoleSelectorModalCtrl', function($scope, realm, config, confi
})
});
module.controller('ProviderConfigCtrl', function ($modal, $scope) {
module.controller('ProviderConfigCtrl', function ($modal, $scope, ComponentUtils) {
$scope.fileNames = {};
@ -2490,18 +2490,17 @@ module.controller('ProviderConfigCtrl', function ($modal, $scope) {
})
}
$scope.newValues = [];
ComponentUtils.addLastEmptyValueToMultivaluedLists($scope.properties, $scope.config);
$scope.addValueToMultivalued = function(optionName) {
var valueToPush = $scope.newValues[optionName];
var configProperty = $scope.config[optionName];
var lastIndex = configProperty.length - 1;
var lastValue = configProperty[lastIndex];
console.log("Option=" + optionName + ", lastIndex=" + lastIndex + ", lastValue=" + lastValue);
console.log("New value to multivalued: optionName=" + optionName + ", valueToPush=" + valueToPush);
if (!$scope.config[optionName]) {
$scope.config[optionName] = [];
if (lastValue.length > 0) {
configProperty.push('');
}
$scope.config[optionName].push(valueToPush);
$scope.newValues[optionName] = "";
}
$scope.deleteValueFromMultivalued = function(optionName, index) {

View file

@ -2391,7 +2391,7 @@ module.controller('ClientRegPoliciesCtrl', function($scope, realm, clientRegistr
});
module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientRegistrationPolicyProviders, instance, Dialog, Notifications, Components, $route, $location) {
module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientRegistrationPolicyProviders, instance, Dialog, Notifications, Components, ComponentUtils, $route, $location) {
$scope.realm = realm;
$scope.instance = instance;
$scope.providerTypes = clientRegistrationPolicyProviders;
@ -2408,8 +2408,12 @@ module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientReg
function toDefaultValue(configProperty) {
if (configProperty.type === 'MultivaluedString' || configProperty.type === 'MultivaluedList') {
if (configProperty.defaultValue) {
return configProperty.defaultValue;
} else {
return [];
}
}
if (configProperty.defaultValue) {
return [ configProperty.defaultValue ];
@ -2432,6 +2436,10 @@ module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientReg
}
}
if ($scope.providerType.properties) {
ComponentUtils.addLastEmptyValueToMultivaluedLists($scope.providerType.properties, $scope.instance.config);
}
var oldCopy = angular.copy($scope.instance);
$scope.changed = false;

View file

@ -191,6 +191,48 @@ module.factory('Notifications', function($rootScope, $timeout) {
return notifications;
});
module.factory('ComponentUtils', function() {
var utils = {};
utils.addLastEmptyValueToMultivaluedLists = function(properties, config) {
for (var i=0 ; i<properties.length ; i++) {
var prop = properties[i];
if (prop.type === 'MultivaluedString') {
var configProperty = config[prop.name];
if (configProperty == null) {
configProperty = [];
config[prop.name] = configProperty;
}
if (configProperty.length == 0 || configProperty[configProperty.length - 1].length > 0) {
configProperty.push('');
}
}
}
}
utils.removeLastEmptyValue = function(componentConfig) {
for (var configPropertyName in componentConfig) {
var configVal = componentConfig[configPropertyName];
if (configVal && configVal.length > 0) {
var lastVal = configVal[configVal.length - 1];
if (lastVal === '') {
console.log('Remove empty value from config property: ' + configPropertyName);
configVal.splice(configVal.length - 1, 1);
}
}
}
}
return utils;
});
module.factory('Realm', function($resource) {
return $resource(authUrl + '/admin/realms/:id', {
id : '@realm'
@ -1657,13 +1699,32 @@ module.factory('DefaultGroups', function($resource) {
});
});
module.factory('Components', function($resource) {
module.factory('Components', function($resource, ComponentUtils) {
return $resource(authUrl + '/admin/realms/:realm/components/:componentId', {
realm : '@realm',
componentId : '@componentId'
}, {
update : {
method : 'PUT'
method : 'PUT',
transformRequest: function(componentInstance) {
if (componentInstance.config) {
ComponentUtils.removeLastEmptyValue(componentInstance.config);
}
return angular.toJson(componentInstance);
}
},
save : {
method : 'POST',
transformRequest: function(componentInstance) {
if (componentInstance.config) {
ComponentUtils.removeLastEmptyValue(componentInstance.config);
}
return angular.toJson(componentInstance);
}
}
});
});

View file

@ -54,17 +54,15 @@
<div class="col-sm-6" data-ng-if="option.type == 'MultivaluedString'">
<div class="input-group" ng-repeat="(i, currentOption) in config[option.name] track by $index">
<input class="form-control" ng-model="config[option.name][i]">
<div class="input-group-btn">
<div class="input-group-btn" data-ng-if="$index < config[option.name].length - 1">
<button class="btn btn-default" type="button" data-ng-click="deleteValueFromMultivalued(option.name, $index)"><span class="fa fa-minus"></span></button>
</div>
<div class="input-group-btn" data-ng-if="$index === config[option.name].length - 1">
<button class="btn btn-default" type="button" data-ng-click="addValueToMultivalued(option.name)"><span class="fa fa-plus"></span></button>
</div>
</div>
<div class="input-group">
<input class="form-control" ng-model="newValues[option.name]">
<div class="input-group-btn">
<button class="btn btn-default" type="button" data-ng-click="newValues[option.name].length > 0 && addValueToMultivalued(option.name)"><span class="fa fa-plus"></span></button>
</div>
</div>
</div>
<kc-tooltip>{{:: option.helpText | translate}}</kc-tooltip>