diff --git a/rest/index.php b/rest/index.php index 1205d6dc4691f7ff93d611a625802a49498eccd7..ebcd558ba15a5e3e5ec7feb77279ad7a7c0e850d 100755 --- a/rest/index.php +++ b/rest/index.php @@ -365,7 +365,6 @@ $app->delete('/resources/unfollow', \Resource\controllers\UserFollowedResourceCo $app->get('/followedResources', \Resource\controllers\UserFollowedResourceController::class . ':getFollowedResources'); $app->get('/followedResources/{resId}/baskets', \Resource\controllers\UserFollowedResourceController::class . ':getBaskets'); $app->get('/followedResources/filters', \Resource\controllers\UserFollowedResourceController::class . ':getFilters'); -$app->get('/followedResources/count', \Resource\controllers\UserFollowedResourceController::class . ':getNumberOfFollowedResources'); //ResourcesList $app->get('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}', \Resource\controllers\ResourceListController::class . ':get'); diff --git a/src/app/resource/controllers/UserFollowedResourceController.php b/src/app/resource/controllers/UserFollowedResourceController.php index 92bfbda7a1339bb1164ae758afa5c4a6f13d2a17..ab14f80aace78506aebfcccf1c8dbe4b3c768bd7 100644 --- a/src/app/resource/controllers/UserFollowedResourceController.php +++ b/src/app/resource/controllers/UserFollowedResourceController.php @@ -221,11 +221,4 @@ class UserFollowedResourceController return $response->withJson($filters); } - - public static function getNumberOfFollowedResources(Request $request, Response $response) - { - $followedResources = UserFollowedResourceModel::get(['select' => ['res_id'], 'where' => ['user_id = ?'], 'data' => [$GLOBALS['id']]]); - - return $response->withJson(['nbResourcesFollowed' => count($followedResources)]); - } } diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 8a7471d150312fb418cf4e3f37c952c9b5bdf26b..0023fdb9be8ce240d2fa3173ed623cc02db49719 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -35,6 +35,7 @@ use Parameter\models\ParameterModel; use Resource\controllers\ResController; use Resource\controllers\StoreController; use Resource\models\ResModel; +use Resource\models\UserFollowedResourceModel; use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; @@ -515,6 +516,8 @@ class UserController $user['passwordRules'] = PasswordModel::getEnabledRules(); $user['canModifyPassword'] = true; $user['privileges'] = PrivilegeController::getPrivilegesByUser(['userId' => $user['id']]); + $userFollowed = UserFollowedResourceModel::get(['select' => ['count(1) as nb'], 'where' => ['user_id = ?'], 'data' => [$GLOBALS['id']]]); + $user['nbFollowedResources'] = $userFollowed[0]['nb']; $loggingMethod = CoreConfigModel::getLoggingMethod(); if (in_array($loggingMethod['id'], self::ALTERNATIVES_CONNECTIONS_METHODS)) { diff --git a/src/frontend/app/folder/document-list/folder-document-list.component.ts b/src/frontend/app/folder/document-list/folder-document-list.component.ts index 12a1582a266069a3f26c6cc3e32af9f3100abad5..79f52ea6966231b5ec2233eeb80b2d7811fac3f2 100644 --- a/src/frontend/app/folder/document-list/folder-document-list.component.ts +++ b/src/frontend/app/folder/document-list/folder-document-list.component.ts @@ -23,7 +23,6 @@ import { FolderActionListComponent } from '../folder-action-list/folder-action-l import { FiltersListService } from '../../../service/filtersList.service'; import { trigger, transition, style, animate } from '@angular/animations'; import { FoldersService } from '../folders.service'; -import { MenuShortcutComponent } from '../../menu/menu-shortcut.component'; declare function $j(selector: any): any; @@ -99,7 +98,6 @@ export class FolderDocumentListComponent implements OnInit { @ViewChild('actionsListContext', { static: true }) actionsList: FolderActionListComponent; @ViewChild('appPanelList', { static: true }) appPanelList: PanelListComponent; - @ViewChild('menuShortcut', { static: true }) menuShortcut: MenuShortcutComponent; currentSelectedChrono: string = ''; @@ -378,7 +376,7 @@ export class FolderDocumentListComponent implements OnInit { toggleMailTracking(row: any) { if (!row.mailTracking) { this.http.post('../../rest/resources/follow', {resources: [row.resId]}).pipe( - tap(() => this.menuShortcut.nbResourcesFollowed++), + tap(() => this.headerService.addFollowedDocument()), catchError((err: any) => { this.notify.handleErrors(err); return of(false); @@ -386,7 +384,7 @@ export class FolderDocumentListComponent implements OnInit { ).subscribe(); } else { this.http.request('DELETE', '../../rest/resources/unfollow', { body: { resources: [row.resId] } }).pipe( - tap(() => this.menuShortcut.nbResourcesFollowed--), + tap(() => this.headerService.removeFollowedDocument()), catchError((err: any) => { this.notify.handleErrors(err); return of(false); diff --git a/src/frontend/app/home/followed-list/followed-document-list.component.ts b/src/frontend/app/home/followed-list/followed-document-list.component.ts index a24ff940ce30fafa06c83ee591d526f3d02d2319..e21b40de5fadbdc8c710c66447ae86034a772d79 100644 --- a/src/frontend/app/home/followed-list/followed-document-list.component.ts +++ b/src/frontend/app/home/followed-list/followed-document-list.component.ts @@ -340,7 +340,7 @@ export class FollowedDocumentListComponent implements OnInit { filter((data: string) => data === 'ok'), exhaustMap(() => this.http.request('DELETE', '../../rest/resources/unfollow' , { body: { resources: [row.resId] } })), tap((data: any) => { - this.menuShortcut.nbResourcesFollowed--; + this.headerService.removeFollowedDocument(); this.initResultList(); }) ).subscribe(); diff --git a/src/frontend/app/list/basket-list.component.ts b/src/frontend/app/list/basket-list.component.ts index caa17b0d6714910fc1a2f140e915096eb1ee8f87..a601b85335eb640649760fdbb800b10cda877ec1 100755 --- a/src/frontend/app/list/basket-list.component.ts +++ b/src/frontend/app/list/basket-list.component.ts @@ -24,7 +24,6 @@ import { PanelFolderComponent } from '../folder/panel/panel-folder.component'; import { FoldersService } from '../folder/folders.service'; import { ActionsService } from '../actions/actions.service'; import { ContactsListModalComponent } from '../contact/list/modal/contacts-list-modal.component'; -import { MenuShortcutComponent } from '../menu/menu-shortcut.component'; declare function $j(selector: any): any; @@ -100,7 +99,6 @@ export class BasketListComponent implements OnInit { @ViewChild('filtersTool', { static: true }) filtersTool: FiltersToolComponent; @ViewChild('appPanelList', { static: true }) appPanelList: PanelListComponent; @ViewChild('basketHome', { static: true }) basketHome: BasketHomeComponent; - @ViewChild('menuShortcut', { static: true }) menuShortcut: MenuShortcutComponent; @ViewChild('panelFolder', { static: true }) panelFolder: PanelFolderComponent; currentSelectedChrono: string = ''; @@ -493,9 +491,10 @@ export class BasketListComponent implements OnInit { } toggleMailTracking(row: any) { + console.log(this.headerService.nbResourcesFollowed); if (!row.mailTracking) { this.http.post('../../rest/resources/follow', {resources: [row.resId]}).pipe( - tap(() => this.menuShortcut.nbResourcesFollowed++), + tap(() => this.headerService.addFollowedDocument()), catchError((err: any) => { this.notify.handleErrors(err); return of(false); @@ -503,7 +502,7 @@ export class BasketListComponent implements OnInit { ).subscribe(); } else { this.http.request('DELETE', '../../rest/resources/unfollow', { body: { resources: [row.resId] } }).pipe( - tap(() => this.menuShortcut.nbResourcesFollowed--), + tap(() => this.headerService.removeFollowedDocument()), catchError((err: any) => { this.notify.handleErrors(err); return of(false); @@ -511,6 +510,7 @@ export class BasketListComponent implements OnInit { ).subscribe(); } row.mailTracking = !row.mailTracking; + console.log(this.headerService.nbResourcesFollowed); } } diff --git a/src/frontend/app/menu/menu-shortcut.component.html b/src/frontend/app/menu/menu-shortcut.component.html index fbea56d2b817db4868da25da726920a5f7ff4214..32ad6bad06f5e3080418f482ed1fcb8946890c49 100755 --- a/src/frontend/app/menu/menu-shortcut.component.html +++ b/src/frontend/app/menu/menu-shortcut.component.html @@ -7,7 +7,7 @@ <button style="z-index: 9999;" color="default" mat-fab (click)="gotToMenu(shortcut);" matTooltip="{{shortcut.label}}" matTooltipPosition="above"> <mat-icon class="fa {{shortcut.style}}" style="height:auto;font-size:22px;" - matBadge="{{this.nbResourcesFollowed}}" matBadgeHidden="{{shortcut.id != 'followed'}}" + matBadge="{{headerService.nbResourcesFollowed}}" matBadgeHidden="{{shortcut.id != 'followed'}}" ></mat-icon> </button> </span> diff --git a/src/frontend/app/menu/menu-shortcut.component.ts b/src/frontend/app/menu/menu-shortcut.component.ts index 36c5a301f455935b504ee35446ae24deb0e262a9..67a69145f8ad1e4b218ee748df9ae8e709a1810e 100755 --- a/src/frontend/app/menu/menu-shortcut.component.ts +++ b/src/frontend/app/menu/menu-shortcut.component.ts @@ -5,6 +5,7 @@ import { LANG } from '../translate.component'; import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material/dialog'; import { AppService } from '../../service/app.service'; import { PrivilegeService } from '../../service/privileges.service'; +import { HeaderService } from '../../service/header.service'; declare function $j(selector: any): any; @@ -22,17 +23,16 @@ export class MenuShortcutComponent implements OnInit { speedDialFabButtons: any = []; speedDialFabColumnDirection = 'column'; shortcuts: any; - nbResourcesFollowed: any; constructor( public http: HttpClient, private _router: Router, public dialog: MatDialog, public appService: AppService, - public privilegeService: PrivilegeService + public privilegeService: PrivilegeService, + private headerService: HeaderService, ) { this.router = _router; - /**/ } ngOnInit(): void { @@ -41,11 +41,6 @@ export class MenuShortcutComponent implements OnInit { loadShortcuts() { this.shortcuts = this.privilegeService.getCurrentUserShortcuts(); - - this.http.get("../../rest/followedResources/count") - .subscribe((data: any) => { - this.nbResourcesFollowed = data.nbResourcesFollowed; - }); } onSpeedDialFabClicked(group: any, shortcut: any) { diff --git a/src/frontend/service/app.guard.ts b/src/frontend/service/app.guard.ts index 53ecce73c6dd8427538e910b2910ebe279f4890b..963a3d9480452a10f287c1938380f021e6a815e5 100644 --- a/src/frontend/service/app.guard.ts +++ b/src/frontend/service/app.guard.ts @@ -36,7 +36,8 @@ export class AppGuard implements CanActivate { groups: data.groups, preferences: data.preferences, privileges: data.privileges[0] === 'ALL_PRIVILEGES' ? this.privilegeService.getAllPrivileges() : data.privileges - } + }; + this.headerService.nbResourcesFollowed = data.nbFollowedResources; return true; }) ); diff --git a/src/frontend/service/header.service.ts b/src/frontend/service/header.service.ts index c643efdf801557981eef583d433b35119a284362..6f2ca8e86a1c0a9aa4e4876c6674b167109bb018 100755 --- a/src/frontend/service/header.service.ts +++ b/src/frontend/service/header.service.ts @@ -11,6 +11,7 @@ export class HeaderService { subHeaderMessage: string = ""; user: any = { firstname: "", lastname: "", groups : [], privileges : [] }; lang: any = LANG; + nbResourcesFollowed: number = 0; constructor(public http: HttpClient) { } @@ -51,4 +52,12 @@ export class HeaderService { this.subHeaderMessage = subTitle; this.headerMessageIcon = icon; } + + removeFollowedDocument() { + this.nbResourcesFollowed--; + } + + addFollowedDocument() { + this.nbResourcesFollowed++; + } }