Skip to content
Snippets Groups Projects
Verified Commit 0451eabd authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #11405 TIME 1 check followed document in service

parent 11993920
No related branches found
No related tags found
No related merge requests found
......@@ -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');
......
......@@ -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)]);
}
}
......@@ -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)) {
......
......@@ -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);
......
......@@ -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();
......
......@@ -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);
}
}
......
......@@ -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>
......
......@@ -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) {
......
......@@ -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;
})
);
......
......@@ -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++;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment