Dynamic display of auth modules (authChoice only)

environments/ppa-mbqj77/deployments/1
Xavier Guimard 10 years ago
parent bba44321fc
commit e5f744654b
  1. 2
      lemonldap-ng-manager/site/static/forms/authChoice.html
  2. 2
      lemonldap-ng-manager/site/static/forms/authChoiceContainer.html
  3. 45
      lemonldap-ng-manager/site/static/js/filterFunctions.js
  4. 109
      lemonldap-ng-manager/site/static/js/manager.js

@ -13,7 +13,7 @@
<tr ng-repeat="i in [[0,'authentication'],[1,'userDB'],[2,'passwordDB']]"> <tr ng-repeat="i in [[0,'authentication'],[1,'userDB'],[2,'passwordDB']]">
<td trspan="{{i[1]}}"</td> <td trspan="{{i[1]}}"</td>
<td> <td>
<select id="selectform" class="form-control" ng-model="currentNode.data[i[0]]"> <select id="selectform" class="form-control" ng-model="currentNode.data[i[0]]" ng-change="execFilters(_findScopeByKey('authParams'))">
<option ng-repeat="item in _findContainer().select[i[0]]" ng-selected="item.k==currentNode.data[i[0]]" value="{{item.k}}">{{item.v}}</option> <option ng-repeat="item in _findContainer().select[i[0]]" ng-selected="item.k==currentNode.data[i[0]]" value="{{item.k}}">{{item.v}}</option>
</select> </select>
</td> </td>

@ -17,7 +17,7 @@
<input ng-model="c.title"> <input ng-model="c.title">
</td> </td>
<td ng-repeat="i in [0,1,2]"> <td ng-repeat="i in [0,1,2]">
<select class="form-control" ng-model="c.data[i]"> <select class="form-control" ng-model="c.data[i]" ng-change="execFilters(_findScopeByKey('authParams'))">
<option ng-repeat="item in currentNode.select[i]" ng-selected="item.k==c.data[i]" value="{{item.k}}">{{item.v}}</option> <option ng-repeat="item in currentNode.select[i]" ng-selected="item.k==c.data[i]" value="{{item.k}}">{{item.v}}</option>
</select> </select>
</td> </td>

@ -1,5 +1,5 @@
var filterFunctions = { var filterFunctions = {
'authParams': function($scope, $q, node) { 'authParams': function(scope, $q, node) {
/* Here, `node` is the root node (authParams) and `n` points to its /* Here, `node` is the root node (authParams) and `n` points to its
* conditional subnodes. This subnodes have the property `show` that can * conditional subnodes. This subnodes have the property `show` that can
* be set to true or false depending on what has to be displayed * be set to true or false depending on what has to be displayed
@ -8,29 +8,56 @@ var filterFunctions = {
/* 1. be sure to have all datas in main nodes */ /* 1. be sure to have all datas in main nodes */
var wait = []; var wait = [];
node.nodes.forEach(function(n) { node.nodes.forEach(function(n) {
wait.push($scope.getKey(n)); wait.push(scope.getKey(n));
}); });
/* 2. then do the job */ /* 2. then do the job */
$q.all(wait).then(function() { $q.all(wait).then(function() {
/* 2.1. Get all modules needed */ /* 2.1. Get all modules needed */
var all = false; var all = false;
var nToShow = []; var nToShow = [];
var p = function(s) {
var tmp = s.toLowerCase();
if (tmp == 'ad') {
tmp = 'ldap';
}
if (tmp == 'openidconnect') {
tmp = 'oidc';
}
nToShow.push(tmp + 'Params');
}
if (node.nodes[0].data.match(/^(Choice|Multi)/)) { if (node.nodes[0].data.match(/^(Choice|Multi)/)) {
for (var i = 1; i < 3; i++) { for (var i = 1; i < 3; i++) {
node.nodes[i].data = node.nodes[0].data; node.nodes[i].data = node.nodes[0].data;
} }
all = true; //all = true;
} }
node.nodes.forEach(function(n) { node.nodes.forEach(function(n) {
var tmp = n.data.toLowerCase(); p(n.data);
if (tmp == 'ad') { });
tmp = 'ldap'; /* Get choice or multi sub modules */
node.nodes_cond.forEach(function(n) {
if (node.nodes[0].data == 'Choice' && n.id == 'choiceParams') {
var nd = n._nodes ? n._nodes : n.nodes;
if (!nd[1].cnodes) {
nd = nd[1]._nodes ? nd[1]._nodes : nd[1].nodes;
nd.forEach(function(m) {
m.data.forEach(function(s) {
p(s);
});
});
}
} }
if (tmp == 'openidconnect') { else if (node.nodes[0].data == 'Multi' && n.id == 'multiParams') {
tmp = 'oidc'; var nd = n._nodes ? n._nodes : n.nodes;
var sep = nd[2].data || ';';
var reg = new RegExp('(?:^|' + sep + ')(\w+)');
var s = nd[0].data + sep + nd[1].data;
while ((result = reg.exec(s)) !== null) {
p(result);
}
} }
nToShow.push(tmp + 'Params');
}); });
console.log(nToShow);
/* 2.2 Display modules */ /* 2.2 Display modules */
node.nodes_cond.forEach(function(n) { node.nodes_cond.forEach(function(n) {
if (!all && nToShow.indexOf(n.id) == -1) { if (!all && nToShow.indexOf(n.id) == -1) {

@ -108,14 +108,14 @@
if (!button.action) button.action = button.title; if (!button.action) button.action = button.title;
//try { //try {
switch (typeof button.action) { switch (typeof button.action) {
case 'function': case 'function':
button.action($scope.currentNode, $scope); button.action($scope.currentNode, $scope);
break; break;
case 'string': case 'string':
$scope[button.action](); $scope[button.action]();
break; break;
default: default:
console.log(typeof button.action); console.log(typeof button.action);
}; };
//} catch (e) { //} catch (e) {
// alert("Error: " + e.message); // alert("Error: " + e.message);
@ -173,7 +173,8 @@
$scope.waiting = false; $scope.waiting = false;
$scope.data.pop(); $scope.data.pop();
}) })
}, function() { },
function() {
console.log('Saving canceled'); console.log('Saving canceled');
}); });
$scope.showM = false; $scope.showM = false;
@ -196,16 +197,27 @@
$scope.cancel = function() { $scope.cancel = function() {
$scope.currentNode.data = null; $scope.currentNode.data = null;
$scope.getKey($scope.currentNode); $scope.getKey($scope.currentNode);
} };
var id = 1; var id = 1;
$scope._findContainer = function() { $scope._findContainer = function() {
return $scope._findScopeContainer().$modelValue;
};
$scope._findScopeContainer = function() {
var cs = $scope.currentScope; var cs = $scope.currentScope;
while (!cs.$modelValue.type.match(/Container$/)) { while (!cs.$modelValue.type.match(/Container$/)) {
cs = cs.$parentNodeScope; cs = cs.$parentNodeScope;
} }
return cs.$modelValue; return cs;
};
$scope._findScopeByKey = function(k) {
var cs = $scope.currentScope;
while (! (cs.$modelValue.title === k)) {
cs = cs.$parentNodeScope;
}
return cs;
} }
/* Add rules entry */ /* Add rules entry */
@ -240,9 +252,10 @@
node.nodes.push({ node.nodes.push({
"id": node.id + '/n' + (id++), "id": node.id + '/n' + (id++),
"title": "1-key", "title": "1-key",
"data": ['LDAP','LDAP','Null'], "data": ['Null', 'Null', 'Null'],
"type": "authChoice" "type": "authChoice"
}); });
$scope.execFilters($scope._findScopeByKey('authParams'));
}; };
/* Add hash entry */ /* Add hash entry */
@ -315,26 +328,22 @@
$scope.addSamlIDP = function() { $scope.addSamlIDP = function() {
var name = window.prompt($translator.translate('samlPartnerName')); var name = window.prompt($translator.translate('samlPartnerName'));
if (name) if (name) $scope.addTemplateNode(name, 'samlIDPMetaDataNode');
$scope.addTemplateNode(name, 'samlIDPMetaDataNode');
}; };
$scope.addSamlSP = function() { $scope.addSamlSP = function() {
var name = window.prompt($translator.translate('samlPartnerName')); var name = window.prompt($translator.translate('samlPartnerName'));
if (name) if (name) $scope.addTemplateNode(name, 'samlSPMetaDataNode');
$scope.addTemplateNode(name, 'samlSPMetaDataNode');
}; };
$scope.addOidcOp = function() { $scope.addOidcOp = function() {
var name = window.prompt($translator.translate('oidcOPName')); var name = window.prompt($translator.translate('oidcOPName'));
if (name) if (name) $scope.addTemplateNode(name, 'oidcOPMetaDataNode');
$scope.addTemplateNode(name, 'oidcOPMetaDataNode');
}; };
$scope.addOidcRp = function() { $scope.addOidcRp = function() {
var name = window.prompt($translator.translate('oidcRPName')); var name = window.prompt($translator.translate('oidcRPName'));
if (name) if (name) $scope.addTemplateNode(name, 'oidcRPMetaDataNode');
$scope.addTemplateNode(name, 'oidcRPMetaDataNode');
}; };
$scope.addTemplateNode = function(name, type) { $scope.addTemplateNode = function(name, type) {
@ -420,10 +429,11 @@
/* authParams mechanism: show used auth modules only (launched by stoggle) */ /* authParams mechanism: show used auth modules only (launched by stoggle) */
$scope.filters = {}; $scope.filters = {};
$scope.execFilters = function() { $scope.execFilters = function(scope) {
scope = scope ? scope : $scope;
for (var filter in $scope.filters) { for (var filter in $scope.filters) {
if ($scope.filters.hasOwnProperty(filter)) { if ($scope.filters.hasOwnProperty(filter)) {
filterFunctions[filter]($scope, $q, $scope.filters[filter]); filterFunctions[filter](scope, $q, $scope.filters[filter]);
} }
} }
}; };
@ -481,8 +491,10 @@
d.reject('Empty response from server'); d.reject('Empty response from server');
} else if (data.error) { } else if (data.error) {
if (data.error == 'setDefault') { if (data.error == 'setDefault') {
if (node.default) { if (node.
node.nodes = node.default.slice(0); default) {
node.nodes = node.
default.slice(0);
} else node.nodes = []; } else node.nodes = [];
delete node.cnodes; delete node.cnodes;
d.resolve('Set data to default value'); d.resolve('Set data to default value');
@ -515,7 +527,8 @@
$scope.openCnode = function(scope) { $scope.openCnode = function(scope) {
$scope.download(scope).then(function() { $scope.download(scope).then(function() {
scope.toggle(); scope.toggle();
}, function(reason) { },
function(reason) {
if (typeof reason == 'string') { if (typeof reason == 'string') {
alert(reason); alert(reason);
} }
@ -552,7 +565,8 @@
f = 'text'; f = 'text';
} }
if (node.nodes || node._nodes || node.cnodes) { if (node.nodes || node._nodes || node.cnodes) {
$scope.form = f != 'text' ? f : 'home'; $scope.form = f != 'text' ? f:
'home';
} else { } else {
$scope.form = f; $scope.form = f;
/* Get datas */ /* Get datas */
@ -591,7 +605,8 @@
}).error(function(j, e) { }).error(function(j, e) {
$scope.waiting = false; $scope.waiting = false;
}); });
}, function() { },
function() {
console.log('New key cancelled'); console.log('New key cancelled');
}); });
} }
@ -632,15 +647,18 @@
}; };
$q.all(tmp).then(function() { $q.all(tmp).then(function() {
d.resolve(node.data); d.resolve(node.data);
}, function(j, e) { },
function(j, e) {
d.reject(e); d.reject(e);
$scope.waiting = false; $scope.waiting = false;
}); });
} else { } else {
$http.get($scope.confPrefix + $scope.currentCfg.cfgNum + '/' + (node.get ? node.get : node.title)).success(function(data) { $http.get($scope.confPrefix + $scope.currentCfg.cfgNum + '/' + (node.get ? node.get : node.title)).success(function(data) {
/* Set default value if response is null or if asked by server */ /* Set default value if response is null or if asked by server */
if ((data.value === null || (data.error && data.error == 'setDefault')) && node.default !== null) { if ((data.value === null || (data.error && data.error == 'setDefault')) && node.
node.data = node.default; default !== null) {
node.data = node.
default;
} else { } else {
node.data = data.value; node.data = data.value;
} }
@ -664,7 +682,6 @@
return d.promise; return d.promise;
}; };
/* function `pathEvent(event, next; current)`: /* function `pathEvent(event, next; current)`:
* Called when $location.path() change, launch getCfg() with the new * Called when $location.path() change, launch getCfg() with the new
* configuration number * configuration number
@ -722,22 +739,20 @@
$scope.waiting = true; $scope.waiting = true;
$scope.data = []; $scope.data = [];
$q.all([ $q.all([
$translator.init($scope.lang), $translator.init($scope.lang), $http.get(staticPrefix + "struct.json").success(function(data) {
$http.get(staticPrefix + "struct.json").success(function(data) { tmp = data;
tmp = data; console.log("Structure loaded");
console.log("Structure loaded"); })]).then(function() {
}) console.log("Starting structure binding");
]) $scope.data = tmp;
.then(function() { tmp = null;
console.log("Starting structure binding"); setScopeVars($scope);
$scope.data = tmp; $scope.form = 'home';
tmp = null; $scope.waiting = false;
setScopeVars($scope); },
$scope.form = 'home'; function(j, e) {
$scope.waiting = false; $scope.waiting = false;
}, function(j, e) { });
$scope.waiting = false;
});
}; };
var c = $location.path().match(new RegExp('^/confs/(latest|[0-9]+)')); var c = $location.path().match(new RegExp('^/confs/(latest|[0-9]+)'));
if (!c) { if (!c) {

Loading…
Cancel
Save