From b3ad81ec8c7bf6b1b617365feae3e9a158ccf0bf Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Fri, 16 Oct 2020 23:28:00 +0200 Subject: [PATCH] Display notification content (#2353) --- .../lib/Lemonldap/NG/Manager/Notifications.pm | 33 ++++++++++++++----- .../site/coffee/notifications.coffee | 8 ++--- .../site/htdocs/static/js/notifications.js | 11 +++---- .../htdocs/static/js/notifications.min.js | 2 +- .../htdocs/static/js/notifications.min.js.map | 2 +- .../site/htdocs/static/languages/en.json | 2 +- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm index 804d2c063..ed06b935a 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm @@ -5,6 +5,7 @@ use utf8; use Mouse; use JSON qw(from_json to_json); use POSIX qw(strftime); +use MIME::Base64 qw(decode_base64); use Lemonldap::NG::Common::Conf::Constants; use Lemonldap::NG::Common::PSGI::Constants; @@ -243,40 +244,56 @@ sub notifications { } sub notification { - my ( $self, $req, $id, $type, $uid, $ref ) = @_; + my ( $self, $req, $id, $type ) = @_; + my $backend = $self->{notificationStorage}; + $self->logger->debug("Notification storage: $backend"); if ( $type eq 'actives' ) { - ( $uid, $ref ) = ( $id =~ /([^_]+?)_(.+)/ ); + my ( $uid, $ref ) = ( $id =~ /([^_]+?)_(.+)/ ); my $n = $self->notifAccess->get( $uid, $ref ); unless ($n) { $self->userLogger->notice( - "Notification $ref not found for user $uid"); + "Active notification $ref not found for user $uid"); return $self->sendJSONresponse( $req, { result => 0, - error => "Notification $ref not found for user $uid" + error => "Active otification $ref not found for user $uid" } ); } + $self->logger->debug("Active notification $ref found for user $uid"); return $self->sendJSONresponse( $req, { result => 1, count => 1, notifications => [ values %$n ] } ); } else { + my ( $date, $uid, $ref ) = + $backend eq 'File' + ? ( $id =~ /([^_]+?)_(.+?)_(.+?)\.done/ ) + : ( $id =~ /([^_]+?)_(.+?)_(.+)/ ); + $ref = decode_base64($ref) if ( $backend eq 'File' ); my $n = $self->notifAccess->getAccepted( $uid, $ref ); unless ($n) { $self->userLogger->notice( - "Notification $ref not found for user $uid"); + "Done notification $ref not found for user $uid"); return $self->sendJSONresponse( $req, { result => 0, - error => "Notification $ref not found for user $uid" + error => "Done notification $ref not found for user $uid" } ); } - return $self->sendJSONresponse( $req, - { result => 1, count => 1, done => $id, notifications => [ values %$n ] } ); + $self->logger->debug("Done notification $ref found for user $uid"); + return $self->sendJSONresponse( + $req, + { + result => 1, + count => 1, + done => $id, + notifications => [ values %$n ] + } + ); } } diff --git a/lemonldap-ng-manager/site/coffee/notifications.coffee b/lemonldap-ng-manager/site/coffee/notifications.coffee index 94af30468..103c3abd3 100644 --- a/lemonldap-ng-manager/site/coffee/notifications.coffee +++ b/lemonldap-ng-manager/site/coffee/notifications.coffee @@ -206,12 +206,10 @@ llapp.controller 'NotificationsExplorerCtrl', [ '$scope', '$translator', '$locat $scope.currentScope = scope node = scope.$modelValue notificationId = node.notification - query = '' if $scope.type == 'actives' - notificationId = "#{node.uid}_#{node.reference}" - if $scope.type == 'done' - query = "?uid=#{node.uid}&reference=#{node.reference}" - $http.get("#{scriptname}notifications/#{$scope.type}/#{notificationId}#{query}").then (response) -> + node.reference.replace(/#/, '_') + notificationId = "#{node.uid}_" + node.reference.replace(/#/, '_') + $http.get("#{scriptname}notifications/#{$scope.type}/#{notificationId}").then (response) -> $scope.currentNotification = uid: node.uid reference: node.reference diff --git a/lemonldap-ng-manager/site/htdocs/static/js/notifications.js b/lemonldap-ng-manager/site/htdocs/static/js/notifications.js index 3e05762ea..96ea12258 100644 --- a/lemonldap-ng-manager/site/htdocs/static/js/notifications.js +++ b/lemonldap-ng-manager/site/htdocs/static/js/notifications.js @@ -243,19 +243,16 @@ } }; $scope.displayNotification = function(scope) { - var node, notificationId, query; + var node, notificationId; $scope.waiting = true; $scope.currentScope = scope; node = scope.$modelValue; notificationId = node.notification; - query = ''; if ($scope.type === 'actives') { - notificationId = node.uid + "_" + node.reference; + node.reference.replace(/#/, '_'); + notificationId = (node.uid + "_") + node.reference.replace(/#/, '_'); } - if ($scope.type === 'done') { - query = "?uid=" + node.uid + "&reference=" + node.reference; - } - $http.get(scriptname + "notifications/" + $scope.type + "/" + notificationId + query).then(function(response) { + $http.get(scriptname + "notifications/" + $scope.type + "/" + notificationId).then(function(response) { var e, notif; $scope.currentNotification = { uid: node.uid, diff --git a/lemonldap-ng-manager/site/htdocs/static/js/notifications.min.js b/lemonldap-ng-manager/site/htdocs/static/js/notifications.min.js index fb1f8149f..8bb0ed4a0 100644 --- a/lemonldap-ng-manager/site/htdocs/static/js/notifications.min.js +++ b/lemonldap-ng-manager/site/htdocs/static/js/notifications.min.js @@ -1 +1 @@ -(function(){var c,m,g;g=[function(t){return"groupBy=substr(uid,1)"},function(t){return"uid="+t+"*&groupBy=uid"},function(t){return"uid="+t}],m=function(t,e,n){return console.log("overScheme => level",e,"over",n),1===e&&t.length>n?"uid="+t+"*&groupBy=substr(uid,"+(e+n+1)+")":null},c={actives:[{title:"markAsDone",icon:"check"}],done:[{title:"deleteNotification",icon:"trash"}],new:[{title:"save",icon:"save"}],home:[]},angular.module("llngNotificationsExplorer",["ui.tree","ui.bootstrap","llApp"]).controller("NotificationsExplorerCtrl",["$scope","$translator","$location","$q","$http","$uibModal",function(f,e,t,o,r,a){var d,n,i;return f.links=links,f.menulinks=menulinks,f.staticPrefix=staticPrefix,f.scriptname=scriptname,f.formPrefix=formPrefix,f.availableLanguages=availableLanguages,f.waiting=!0,f.showM=!1,f.showT=!0,f.showForm=!1,f.data=[],f.form={},f.formPost={},f.currentScope=null,f.currentNotification=null,f.menu=c,f.translateP=e.translateP,f.translate=e.translate,f.translateTitle=function(t){return e.translateField(t,"title")},f.menuClick=function(t){if(t.popup)window.open(t.popup);else switch(t.action||(t.action=t.title),typeof t.action){case"function":t.action(f.currentNode,f);break;case"string":f[t.action]();break;default:console.log(typeof t.action)}return f.showM=!1},f.markAsDone=function(){return f.waiting=!0,r.put(scriptname+"notifications/"+f.type+"/"+f.currentNotification.uid+"_"+f.currentNotification.reference,{done:1}).then(function(t){return f.currentNotification=null,f.currentScope.remove(),f.message={title:"notificationDeleted"},f.showModal("alert.html"),f.waiting=!1,f.init()},function(t){return f.message={title:"notificationNotDeleted",message:t.statusText},f.showModal("alert.html"),f.waiting=!1,f.init()})},f.deleteNotification=function(){return f.waiting=!0,r.delete(scriptname+"notifications/"+f.type+"/"+f.currentNotification.uid+"_"+f.currentNotification.reference+"_"+f.currentNotification.done).then(function(t){return f.currentNotification=null,f.currentScope.remove(),f.message={title:"notificationPurged"},f.showModal("alert.html"),f.waiting=!1,f.init()},function(t){return f.message={title:"notificationNotPurged",message:t.statusText},f.showModal("alert.html"),f.waiting=!1,f.init()})},f.stoggle=function(t){var e;return 0===(e=t.$modelValue).nodes.length&&f.updateTree(e.value,e.nodes,e.level,e.over,e.query,e.count),t.toggle()},f.notifDate=function(t){return null!=t?(t.match(/(\d{4})-(\d{2})-(\d{2})/)&&(t=t.substr(0,4)+t.substr(5,2)+t.substr(8,2)),new Date(t.substr(0,4),t.substr(4,2)-1,t.substr(6,2)).toLocaleDateString()):""},f.getLanguage=function(t){return f.lang=t,f.form.date?f.form.date=new Date:f.form="white",f.init(),f.showM=!1},f.$on("$locationChangeSuccess",function(t,e,n){var i;return i=e.match(/#!?\/(\w+)/),f.type=null!=i?i[1]:"actives","new"===f.type?f.displayCreateForm():(f.showForm=!1,f.init())}),d=0,f.updateTree=function(a,c,u,l,t,e){var s,n;if(f.waiting=!0,s=g[u](a,t),25 level",e,"over",n),1===e&&t.length>n?"uid="+t+"*&groupBy=substr(uid,"+(e+n+1)+")":null},c={actives:[{title:"markAsDone",icon:"check"}],done:[{title:"deleteNotification",icon:"trash"}],new:[{title:"save",icon:"save"}],home:[]},angular.module("llngNotificationsExplorer",["ui.tree","ui.bootstrap","llApp"]).controller("NotificationsExplorerCtrl",["$scope","$translator","$location","$q","$http","$uibModal",function(f,e,t,o,i,r){var d,n,a;return f.links=links,f.menulinks=menulinks,f.staticPrefix=staticPrefix,f.scriptname=scriptname,f.formPrefix=formPrefix,f.availableLanguages=availableLanguages,f.waiting=!0,f.showM=!1,f.showT=!0,f.showForm=!1,f.data=[],f.form={},f.formPost={},f.currentScope=null,f.currentNotification=null,f.menu=c,f.translateP=e.translateP,f.translate=e.translate,f.translateTitle=function(t){return e.translateField(t,"title")},f.menuClick=function(t){if(t.popup)window.open(t.popup);else switch(t.action||(t.action=t.title),typeof t.action){case"function":t.action(f.currentNode,f);break;case"string":f[t.action]();break;default:console.log(typeof t.action)}return f.showM=!1},f.markAsDone=function(){return f.waiting=!0,i.put(scriptname+"notifications/"+f.type+"/"+f.currentNotification.uid+"_"+f.currentNotification.reference,{done:1}).then(function(t){return f.currentNotification=null,f.currentScope.remove(),f.message={title:"notificationDeleted"},f.showModal("alert.html"),f.waiting=!1,f.init()},function(t){return f.message={title:"notificationNotDeleted",message:t.statusText},f.showModal("alert.html"),f.waiting=!1,f.init()})},f.deleteNotification=function(){return f.waiting=!0,i.delete(scriptname+"notifications/"+f.type+"/"+f.currentNotification.uid+"_"+f.currentNotification.reference+"_"+f.currentNotification.done).then(function(t){return f.currentNotification=null,f.currentScope.remove(),f.message={title:"notificationPurged"},f.showModal("alert.html"),f.waiting=!1,f.init()},function(t){return f.message={title:"notificationNotPurged",message:t.statusText},f.showModal("alert.html"),f.waiting=!1,f.init()})},f.stoggle=function(t){var e;return 0===(e=t.$modelValue).nodes.length&&f.updateTree(e.value,e.nodes,e.level,e.over,e.query,e.count),t.toggle()},f.notifDate=function(t){return null!=t?(t.match(/(\d{4})-(\d{2})-(\d{2})/)&&(t=t.substr(0,4)+t.substr(5,2)+t.substr(8,2)),new Date(t.substr(0,4),t.substr(4,2)-1,t.substr(6,2)).toLocaleDateString()):""},f.getLanguage=function(t){return f.lang=t,f.form.date?f.form.date=new Date:f.form="white",f.init(),f.showM=!1},f.$on("$locationChangeSuccess",function(t,e,n){var i;return i=e.match(/#!?\/(\w+)/),f.type=null!=i?i[1]:"actives","new"===f.type?f.displayCreateForm():(f.showForm=!1,f.init())}),d=0,f.updateTree=function(a,c,u,l,t,e){var s,n;if(f.waiting=!0,s=g[u](a,t),25