diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm index 500ea84e2..7cdbf95b8 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm @@ -219,7 +219,7 @@ sub display { PING => $self->conf->{portalPingInterval}, REQUIRE_OLDPASSWORD => $self->conf->{portalRequireOldPassword}, HIDE_OLDPASSWORD => 0, - FAVAPPS => $self->favAppsRule->( $req, $req->userData ), + STARS => $self->favAppsRule->( $req, $req->userData ), $self->menu->params($req), ( $req->data->{customScript} diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm index b7ad7b756..e9ec9a0a5 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm @@ -19,7 +19,10 @@ has menuModules => ( builder => sub { my $conf = $_[0]->{conf}; my @res; - foreach (qw(FavApps Appslist ChangePassword LoginHistory OidcConsents Logout)) { + foreach ( + qw(FavApps Appslist ChangePassword LoginHistory OidcConsents Logout) + ) + { my $cond = $conf->{"portalDisplay$_"} // 1; $_[0]->p->logger->debug("Evaluate condition $cond for module $_"); my $tmp = @@ -60,7 +63,8 @@ sub params { my ( $self, $req ) = @_; $self->{conf}->{imgPath} ||= $self->{staticPrefix}; my %res; - my @defaultTabs = (qw/favApps appslist password logout loginHistory oidcConsents/); + my @defaultTabs = + (qw/favApps appslist password logout loginHistory oidcConsents/); my @customTabs = split( /,\s*/, $self->{conf}->{customMenuTabs} || '' ); # Tab to display @@ -124,6 +128,7 @@ sub params { sub displayModules { my ( $self, $req ) = @_; my $displayModules = []; + my $favAppslistRef = $self->favAppslist($req); # Foreach module, eval condition # Store module in result if condition is valid @@ -132,11 +137,12 @@ sub displayModules { if ( $module->[1]->( $req, $req->userData ) ) { my $moduleHash = { $module->[0] => 1 }; - if ( $module->[0] eq 'Appslist' ) { - $moduleHash->{'APPSLIST_LOOP'} = $self->appslist($req); + if ( $module->[0] eq 'FavApps' ) { + $moduleHash->{'FAVAPPS_LOOP'} = $favAppslistRef; } - elsif ( $module->[0] eq 'FavApps' ) { - $moduleHash->{'FAVAPPS_LOOP'} = $self->favAppslist($req); + elsif ( $module->[0] eq 'Appslist' ) { + $moduleHash->{'APPSLIST_LOOP'} = + $self->appslist( $req, $favAppslistRef ); } elsif ( $module->[0] eq 'LoginHistory' ) { $moduleHash->{'SUCCESS_LOGIN'} = @@ -155,7 +161,7 @@ sub displayModules { push @$displayModules, $moduleHash; } } - + $displayModules->[0]->{FavApps} = scalar @{$favAppslistRef}; return $displayModules; } @@ -182,7 +188,8 @@ sub favAppslist { $self->logger->debug("No favorite Apps found"); $_favApps = []; } - $self->logger->debug( scalar @$_favApps . " favorite Apps found for $user" ); + $self->logger->debug( + scalar @$_favApps . " favorite Apps found for $user" ); return $_favApps; } @@ -191,7 +198,7 @@ sub favAppslist { # Returns categories and applications list as HTML::Template loop # @return categories and applications list sub appslist { - my ( $self, $req ) = @_; + my ( $self, $req, $favAppslistRef ) = @_; my $appslist = []; return $appslist unless defined $self->conf->{applicationList}; @@ -200,7 +207,8 @@ sub appslist { my $catlevel = 0; my $applicationList = clone( $self->conf->{applicationList} ); - my $filteredList = $self->_filter( $req, $applicationList ); + my $filteredList = + $self->_filter( $req, $applicationList, $favAppslistRef ); push @$appslist, $self->_buildCategoryHash( $req, "", $filteredList, $catlevel ); @@ -270,10 +278,11 @@ sub _buildApplicationHash { my $applications; # Get application items - my $appname = $apphash->{options}->{name} || $appid; - my $appuri = $apphash->{options}->{uri} || ""; - my $appdesc = $apphash->{options}->{description}; - my $applogo = $apphash->{options}->{logo}; + my $appname = $apphash->{options}->{name} || $appid; + my $appuri = $apphash->{options}->{uri} || ""; + my $appdesc = $apphash->{options}->{description}; + my $applogo = $apphash->{options}->{logo}; + my $appIsFavApp = $apphash->{options}->{isFavApp} || "0"; # Detect sub applications my $subapphash; @@ -299,6 +308,7 @@ sub _buildApplicationHash { appdesc => $appdesc, applogo => $applogo, appid => $appid, + appisfav => $appIsFavApp, }; $applicationHash->{applications} = $applications if $applications; return $applicationHash; @@ -311,7 +321,7 @@ sub _buildApplicationHash { # @param $apphash Menu elements # @return filtered hash sub _filter { - my ( $self, $req, $apphash ) = @_; + my ( $self, $req, $apphash, $favAppslistRef ) = @_; my $filteredHash; my $key; @@ -321,7 +331,7 @@ sub _filter { } # Filter hash - $self->_filterHash( $req, $filteredHash ); + $self->_filterHash( $req, $filteredHash, $favAppslistRef ); # Hide empty categories $self->_isCategoryEmpty($filteredHash); @@ -334,8 +344,7 @@ sub _filter { # @param $apphash Menu elements # @return filtered hash sub _filterHash { - my ( $self, $req, $apphash ) = @_; - + my ( $self, $req, $apphash, $favAppslistRef ) = @_; foreach my $key ( keys %$apphash ) { next if $key =~ /(type|options|catname)/; if ( $apphash->{$key}->{type} @@ -343,7 +352,7 @@ sub _filterHash { { # Filter the category - $self->_filterHash( $req, $apphash->{$key} ); + $self->_filterHash( $req, $apphash->{$key}, $favAppslistRef ); } if ( $apphash->{$key}->{type} and $apphash->{$key}->{type} eq "application" ) @@ -354,7 +363,17 @@ sub _filterHash { next if $appkey =~ /(type|options|catname)/; # We have sub elements, so we filter them - $self->_filterHash( $req, $apphash->{$key} ); + $self->_filterHash( $req, $apphash->{$key}, $favAppslistRef ); + } + + # Check if app is marked as favorite + my $appuri = $apphash->{$key}->{options}->{uri}; + foreach (@$favAppslistRef) { + if ( $_->{appuri} eq $appuri ) { + $apphash->{$key}->{options}->{isFavApp} = "1"; + $self->logger->debug("App $appuri is marked as favorite"); + last; + } } # Check rights diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FavApps.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FavApps.pm index f8e443e4d..d51fbdd11 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FavApps.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FavApps.pm @@ -60,10 +60,10 @@ sub register { return $self->p->sendError( $req, 'Missing App. URI', 400 ); } $self->logger->debug("Favorite application URI received : $uri"); - my $id = $req->param('id') || ''; - my $logo = $req->param('logo') || ''; - my $desc = $req->param('desc') || ''; - my $name = $req->param('name') || ''; + my $id = $req->param('id') || ''; + my $logo = $req->param('logo') || ''; + my $desc = $req->param('desc') || ''; + my $name = $req->param('name') || ''; # Read existing favorite Apps $self->logger->debug("Looking for $user favorite Apps..."); @@ -146,7 +146,8 @@ sub read { apps => $_favApps } ); - $self->logger->debug( scalar @$_favApps . " favorite Apps found for $user" ); + $self->logger->debug( + scalar @$_favApps . " favorite Apps found for $user" ); return [ 200, @@ -174,7 +175,13 @@ sub _isFavApp { sub _appendFavApp { my ( $self, $_favApps, $uri, $id, $logo, $desc, $name ) = @_; push @$_favApps, - { appuri => $uri, appid => $id, applogo => $logo, appdesc => $desc, appname => $name }; + { + appuri => $uri, + appid => $id, + applogo => $logo, + appdesc => $desc, + appname => $name + }; $self->logger->debug("App. $uri appended"); return $_favApps; } diff --git a/lemonldap-ng-portal/site/coffee/favapps.coffee b/lemonldap-ng-portal/site/coffee/favapps.coffee index cd6f41239..58aab2ee8 100644 --- a/lemonldap-ng-portal/site/coffee/favapps.coffee +++ b/lemonldap-ng-portal/site/coffee/favapps.coffee @@ -31,6 +31,7 @@ FavApps = (star) -> switchStar = (star, status) -> star.attr('src', "#{window.staticPrefix}common/icons/star#{status}.png") + #window.location.reload() # Switch "star" events $(document).ready -> diff --git a/lemonldap-ng-portal/site/templates/bootstrap/menu.tpl b/lemonldap-ng-portal/site/templates/bootstrap/menu.tpl index 1edc828e8..9dc02f645 100644 --- a/lemonldap-ng-portal/site/templates/bootstrap/menu.tpl +++ b/lemonldap-ng-portal/site/templates/bootstrap/menu.tpl @@ -20,7 +20,12 @@