Append overScheme to notifications explorer (#2012)

This commit is contained in:
Christophe Maudoux 2019-11-18 22:03:22 +01:00
parent 72511bca83
commit b63217d878
4 changed files with 65 additions and 12 deletions

View File

@ -2,6 +2,9 @@
# LemonLDAP::NG Notifications Explorer client # LemonLDAP::NG Notifications Explorer client
### ###
# Max number of notifications to display (see overScheme)
max = 25
scheme = [ scheme = [
(v) -> (v) ->
"groupBy=substr(uid,1)" "groupBy=substr(uid,1)"
@ -11,6 +14,19 @@ scheme = [
"uid=#{v}" "uid=#{v}"
] ]
# When number of children nodes exceeds "max" value
# and does not return "null", a level is added. See
# "$scope.updateTree" method
overScheme =
(v,level,over) ->
# "v.length > over" avoids a loop if one user opened more than "max"
# notifications
console.log 'overSchema => level', level, 'over', over
if level == 1 and v.length > over
"uid=#{v}*&groupBy=substr(uid,#{(level+over+1)})"
else
null
# Session menu # Session menu
menu = menu =
actives: [ actives: [
@ -112,7 +128,7 @@ llapp.controller 'NotificationsExplorerCtrl', [ '$scope', '$translator', '$locat
$scope.stoggle = (scope) -> $scope.stoggle = (scope) ->
node = scope.$modelValue node = scope.$modelValue
if node.nodes.length == 0 if node.nodes.length == 0
$scope.updateTree node.value, node.nodes, node.level, node.query $scope.updateTree node.value, node.nodes, node.level, node.over, node.query, node.count
scope.toggle() scope.toggle()
$scope.notifDate = (s) -> $scope.notifDate = (s) ->
@ -139,19 +155,34 @@ llapp.controller 'NotificationsExplorerCtrl', [ '$scope', '$translator', '$locat
$scope.init() $scope.init()
autoId = 0 autoId = 0
$scope.updateTree = (value, node, level, currentQuery) -> $scope.updateTree = (value, node, level, over, currentQuery, count) ->
$scope.waiting = true $scope.waiting = true
query = scheme[level] value, currentQuery query = scheme[level] value, currentQuery
# If number of notifications exceeds "max", call it
if count > max
if tmp = overScheme value, level, over
over++
query = tmp
level = level - 1
else
over = 0
else
over = 0
# Launch HTTP query
$http.get("#{scriptname}notifications/#{$scope.type}?#{query}").then (response) -> $http.get("#{scriptname}notifications/#{$scope.type}?#{query}").then (response) ->
data = response.data data = response.data
if data.result if data.result
for n in data.values for n in data.values
autoId++ autoId++
n.id = "node#{autoId}" n.id = "node#{autoId}"
if level <scheme.length - 1 if level < scheme.length - 1
n.nodes = [] n.nodes = []
n.level = level + 1 n.level = level + 1
n.query = query n.query = query
n.over = over
node.push n node.push n
$scope.waiting = false $scope.waiting = false
, (resp) -> , (resp) ->
@ -246,7 +277,7 @@ llapp.controller 'NotificationsExplorerCtrl', [ '$scope', '$translator', '$locat
$scope.currentNotification = null $scope.currentNotification = null
$q.all [ $q.all [
$translator.init $scope.lang $translator.init $scope.lang
$scope.updateTree '', $scope.data, 0 $scope.updateTree '', $scope.data, 0, 0
] ]
.then -> .then ->
$scope.waiting = false $scope.waiting = false

View File

@ -5,7 +5,9 @@
*/ */
(function() { (function() {
var llapp, menu, scheme; var llapp, max, menu, overScheme, scheme;
max = 25;
scheme = [ scheme = [
function(v) { function(v) {
@ -17,6 +19,15 @@
} }
]; ];
overScheme = function(v, level, over) {
console.log('overSchema => level', level, 'over', over);
if (level === 1 && v.length > over) {
return "uid=" + v + "*&groupBy=substr(uid," + (level + over + 1) + ")";
} else {
return null;
}
};
menu = { menu = {
actives: [ actives: [
{ {
@ -131,7 +142,7 @@
var node; var node;
node = scope.$modelValue; node = scope.$modelValue;
if (node.nodes.length === 0) { if (node.nodes.length === 0) {
$scope.updateTree(node.value, node.nodes, node.level, node.query); $scope.updateTree(node.value, node.nodes, node.level, node.over, node.query, node.count);
return scope.toggle(); return scope.toggle();
} }
}; };
@ -164,10 +175,21 @@
} }
}); });
autoId = 0; autoId = 0;
$scope.updateTree = function(value, node, level, currentQuery) { $scope.updateTree = function(value, node, level, over, currentQuery, count) {
var query; var query, tmp;
$scope.waiting = true; $scope.waiting = true;
query = scheme[level](value, currentQuery); query = scheme[level](value, currentQuery);
if (count > max) {
if (tmp = overScheme(value, level, over)) {
over++;
query = tmp;
level = level - 1;
} else {
over = 0;
}
} else {
over = 0;
}
return $http.get(scriptname + "notifications/" + $scope.type + "?" + query).then(function(response) { return $http.get(scriptname + "notifications/" + $scope.type + "?" + query).then(function(response) {
var data, i, len, n, ref; var data, i, len, n, ref;
data = response.data; data = response.data;
@ -181,6 +203,7 @@
n.nodes = []; n.nodes = [];
n.level = level + 1; n.level = level + 1;
n.query = query; n.query = query;
n.over = over;
} }
node.push(n); node.push(n);
} }
@ -301,7 +324,7 @@
$scope.data = []; $scope.data = [];
$scope.currentScope = null; $scope.currentScope = null;
$scope.currentNotification = null; $scope.currentNotification = null;
$q.all([$translator.init($scope.lang), $scope.updateTree('', $scope.data, 0)]).then(function() { $q.all([$translator.init($scope.lang), $scope.updateTree('', $scope.data, 0, 0)]).then(function() {
return $scope.waiting = false; return $scope.waiting = false;
}, function(resp) { }, function(resp) {
return $scope.waiting = false; return $scope.waiting = false;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long