From 598166ba5b0490ffc1e8454f904fb117abd247a0 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Tue, 26 Mar 2019 17:22:50 +0100 Subject: [PATCH] fusion shortcuts menu service with header service --- src/frontend/app/app.component.ts | 7 +++-- src/frontend/app/app.module.ts | 3 +- .../app/menu/main-header.component.html | 10 +++--- .../app/menu/main-header.component.ts | 30 +++--------------- .../app/menu/menu-shortcut.component.html | 10 +++--- .../app/menu/menu-shortcut.component.ts | 8 ++--- src/frontend/service/header.service.ts | 31 +++++++++++++++++-- src/frontend/service/shortcut-menu.service.ts | 10 ------ 8 files changed, 53 insertions(+), 56 deletions(-) delete mode 100755 src/frontend/service/shortcut-menu.service.ts diff --git a/src/frontend/app/app.component.ts b/src/frontend/app/app.component.ts index fac3d3ece7b..840c8be8bf7 100755 --- a/src/frontend/app/app.component.ts +++ b/src/frontend/app/app.component.ts @@ -2,6 +2,7 @@ import { Component, ViewEncapsulation } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { MatIconRegistry } from '@angular/material'; import { MAT_TOOLTIP_DEFAULT_OPTIONS, MatTooltipDefaultOptions } from '@angular/material'; +import { HeaderService } from '../service/header.service'; /** Custom options the configure the tooltip's default show/hide delays. */ export const myCustomTooltipDefaults: MatTooltipDefaultOptions = { @@ -30,14 +31,16 @@ declare function $j(selector: any): any; }) export class AppComponent { - constructor(iconReg: MatIconRegistry, sanitizer: DomSanitizer) { + constructor(iconReg: MatIconRegistry, sanitizer: DomSanitizer, public headerService: HeaderService) { iconReg.addSvgIcon('maarchLogo', sanitizer.bypassSecurityTrustResourceUrl('static.php?filename=logo_white.svg')).addSvgIcon('maarchLogoOnly', sanitizer.bypassSecurityTrustResourceUrl('img/logo_only_white.svg')); if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { angularGlobals.mobileMode = true; } else { angularGlobals.mobileMode = false; - } + } + + this.headerService.loadHeader(); /*REMOVE AFTER FULL MAARCH V2*/ $j('my-app').css({"display":"block"}); diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts index 6e216ae84c7..20bb4b8d37b 100755 --- a/src/frontend/app/app.module.ts +++ b/src/frontend/app/app.module.ts @@ -4,7 +4,6 @@ import { SharedModule } from './app-common.module'; import { CustomSnackbarComponent } from './notification.service'; import { ConfirmModalComponent } from './confirmModal.component'; -import { ShortcutMenuService } from '../service/shortcut-menu.service'; import { HeaderService } from '../service/header.service'; import { FiltersListService } from '../service/filtersList.service'; @@ -122,7 +121,7 @@ import { AvisWorkflowComponent } from './avis/avis-workflow.componen SendShippingActionComponent, ViewDocActionComponent ], - providers: [ ShortcutMenuService, HeaderService, FiltersListService ], + providers: [ HeaderService, FiltersListService ], bootstrap: [ AppComponent ] }) export class AppModule { } diff --git a/src/frontend/app/menu/main-header.component.html b/src/frontend/app/menu/main-header.component.html index 3ec2233ddd0..65472733a31 100755 --- a/src/frontend/app/menu/main-header.component.html +++ b/src/frontend/app/menu/main-header.component.html @@ -10,7 +10,7 @@ <mat-icon mat-list-icon class="fa fa-th" style="font-size:20px;color:white;height:auto;"></mat-icon> </button> <mat-menu #applications="matMenu" class="headerMaarchShortcut"> - <ng-container *ngFor="let shortcut of user.menu"> + <ng-container *ngFor="let shortcut of headerService.menu"> <button (click)="gotToMenu(shortcut);" style="white-space:inherit;height: 100px;line-height:20px;" class="col-md-4 col-xs-6" mat-button color="primary" matTooltip="{{shortcut.comment}}"> <i class="{{shortcut.style}} fa-2x"></i> <br/>{{shortcut.name}} @@ -18,21 +18,21 @@ </ng-container> </mat-menu> <button mat-button [matMenuTriggerFor]="menu" *ngIf="!mobileMode"> - <mat-icon mat-list-icon class="fa fa-user fa-2x" style="color:white; margin:0px 12px 8px 0px;"></mat-icon>{{user.firstname.charAt(0) | uppercase}}. {{user.lastname | uppercase}}</button> + <mat-icon mat-list-icon class="fa fa-user fa-2x" style="color:white; margin:0px 12px 8px 0px;"></mat-icon>{{headerService.user.firstname.charAt(0) | uppercase}}. {{headerService.user.lastname | uppercase}}</button> <mat-menu #menu="matMenu" class="headerMaarch"> <canvas class="header-bg" width="250" height="70" style="margin-top:-8px;background-image: url('static.php?filename=login-banner.jpg');background-size:cover;border-bottom: solid 1px white;"></canvas> <i title="{{lang.myProfileAccess}}" routerLink="/profile" style="cursor:pointer;z-index:1;color:white;position: absolute;left: 85px;top: 17px;background-image: url('static.php?filename=logo_only.svg');width: 70px;height: 70px;background-size: cover;background-position: top center;border-radius: 50%;border: solid white;background-color:white;"></i> <div class="content" style="padding-top:10px;color:white;max-height:250px;overflow-y:auto;overflow-x:hidden;"> - <p routerLink="/profile" class="text-center" style="cursor:pointer;">{{user.firstname}} {{user.lastname | uppercase}}</p> + <p routerLink="/profile" class="text-center" style="cursor:pointer;">{{headerService.user.firstname}} {{headerService.user.lastname | uppercase}}</p> <mat-list> <h3 mat-subheader style="color:white;">{{lang.groups}}</h3> <mat-divider></mat-divider> - <mat-list-item *ngFor="let group of user.groups"> + <mat-list-item *ngFor="let group of headerService.user.groups"> <p mat-line style="color:white;opacity:0.5;"> {{group.group_desc}} </p> </mat-list-item> <h3 mat-subheader style="color:white;">{{lang.entities}}</h3> <mat-divider></mat-divider> - <mat-list-item *ngFor="let entity of user.entities"> + <mat-list-item *ngFor="let entity of headerService.user.entities"> <p mat-line style="color:white;opacity:0.5;"> {{entity.entity_label}} </p> </mat-list-item> </mat-list> diff --git a/src/frontend/app/menu/main-header.component.ts b/src/frontend/app/menu/main-header.component.ts index f57c8079288..5fab6abdb9e 100755 --- a/src/frontend/app/menu/main-header.component.ts +++ b/src/frontend/app/menu/main-header.component.ts @@ -4,7 +4,6 @@ import { MatSidenav, MatDialog, MatDialogRef } from '@angular/material import { HttpClient } from '@angular/common/http'; import { Router } from '@angular/router'; import { IndexingGroupModalComponent } from './menu-shortcut.component'; -import { ShortcutMenuService } from '../../service/shortcut-menu.service'; import { HeaderService } from '../../service/header.service'; @@ -31,7 +30,7 @@ export class MainHeaderComponent implements OnInit { snav2 : MatSidenav; - constructor(public http: HttpClient, private zone: NgZone, private _router: Router, private shortcut: ShortcutMenuService, public headerService: HeaderService, public dialog: MatDialog) { + constructor(public http: HttpClient, private zone: NgZone, private _router: Router, public headerService: HeaderService, public dialog: MatDialog) { this.router = _router; this.mobileMode = angularGlobals.mobileMode; window['MainHeaderComponent'] = { @@ -41,28 +40,7 @@ export class MainHeaderComponent implements OnInit { }; } - ngOnInit(): void { - this.coreUrl = angularGlobals.coreUrl; - this.http.get(this.coreUrl + 'rest/header') - .subscribe((data: any) => { - this.user = data.user; - this.user.menu = data.menu; - - this.shortcut.shortcutsData.user = data.user; - data.menu.unshift({ - "name" : this.lang.home, - "comment" : this.lang.home, - "servicepage" : "/home", - "shortcut" : "true", - "style" : "fa fa-home", - "angular" : "true" - }); - this.shortcut.shortcutsData.menu = data.menu; - - }, (err) => { - console.log(err.error.errors); - }); - } + ngOnInit(): void { } setTitle(title: string) { this.zone.run(() => this.titleHeader = title); @@ -82,8 +60,8 @@ export class MainHeaderComponent implements OnInit { } gotToMenu(shortcut:any) { - if (shortcut.id == 'index_mlb' && this.shortcut.shortcutsData.user.indexingGroups.length > 1) { - this.config = { data: { indexingGroups:this.shortcut.shortcutsData.user.indexingGroups, link:shortcut.servicepage } }; + if (shortcut.id == 'index_mlb' && this.headerService.user.indexingGroups.length > 1) { + this.config = { data: { indexingGroups:this.headerService.user.indexingGroups, link:shortcut.menu.servicepage } }; this.dialogRef = this.dialog.open(IndexingGroupModalComponent, this.config); } else if (shortcut.angular == 'true') { this.router.navigate([shortcut.servicepage]); diff --git a/src/frontend/app/menu/menu-shortcut.component.html b/src/frontend/app/menu/menu-shortcut.component.html index 32f67490c47..e9eb6be0bc9 100755 --- a/src/frontend/app/menu/menu-shortcut.component.html +++ b/src/frontend/app/menu/menu-shortcut.component.html @@ -5,22 +5,22 @@ <mat-expansion-panel> <mat-expansion-panel-header> <mat-panel-title style="justify-content: center;"> - {{shortcut.shortcutsData.user.firstname}} {{shortcut.shortcutsData.user.lastname | uppercase}} + {{headerService.user.firstname}} {{headerService.user.lastname | uppercase}} </mat-panel-title> </mat-expansion-panel-header> <mat-list> <mat-divider></mat-divider> - <mat-list-item *ngFor="let group of shortcut.shortcutsData.user.groups"> + <mat-list-item *ngFor="let group of headerService.user.groups"> <p mat-line style="color:#666;opacity:0.5;"> {{group.group_desc}} </p> </mat-list-item> <h3 mat-subheader style="color:#666;">{{lang.groups}}</h3> <mat-divider></mat-divider> - <mat-list-item *ngFor="let group of shortcut.shortcutsData.user.groups"> + <mat-list-item *ngFor="let group of headerService.user.groups"> <p mat-line style="color:#666;opacity:0.5;"> {{group.group_desc}} </p> </mat-list-item> <h3 mat-subheader style="color:#666;">{{lang.entities}}</h3> <mat-divider></mat-divider> - <mat-list-item *ngFor="let entity of shortcut.shortcutsData.user.entities"> + <mat-list-item *ngFor="let entity of headerService.user.entities"> <p mat-line style="color:#666;opacity:0.5;"> {{entity.entity_label}} </p> </mat-list-item> </mat-list> @@ -30,7 +30,7 @@ <mat-nav-list> <h3 mat-subheader>{{lang.shortcut}}</h3> <div class="button-row" style="padding-left: 10px;padding-right: 10px;display: flex;width: 300px;margin-top: -10px;margin-bottom: 10px;"> - <ng-container *ngFor="let shortcut of shortcut.shortcutsData.menu"> + <ng-container *ngFor="let shortcut of headerService.menu"> <span style="flex:1;text-align: left;padding: 5px;" *ngIf="(shortcut.id == 'index_mlb' && speedDialFabButtons.length<=1) || (shortcut.id != 'index_mlb' && shortcut.shortcut == 'true')"> <button style="z-index: 9999;" color="default" mat-fab (click)="gotToMenu(shortcut);" matTooltip="{{shortcut.name}}" matTooltipPosition="above"> diff --git a/src/frontend/app/menu/menu-shortcut.component.ts b/src/frontend/app/menu/menu-shortcut.component.ts index 62a666eaf50..fa3958cc334 100755 --- a/src/frontend/app/menu/menu-shortcut.component.ts +++ b/src/frontend/app/menu/menu-shortcut.component.ts @@ -3,8 +3,8 @@ import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { Location } from '@angular/common'; import { LANG } from '../translate.component'; -import { ShortcutMenuService } from '../../service/shortcut-menu.service'; import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material'; +import { HeaderService } from '../../service/header.service'; declare function $j(selector: any) : any; @@ -28,7 +28,7 @@ export class MenuShortcutComponent implements OnInit { speedDialFabColumnDirection = 'column'; - constructor(public http: HttpClient, private _location: Location, private _router: Router, public shortcut: ShortcutMenuService, public dialog: MatDialog) { + constructor(public http: HttpClient, private _location: Location, private _router: Router, public headerService: HeaderService, public dialog: MatDialog) { this.mobileMode = angularGlobals.mobileMode; this.router = _router; /**/ @@ -37,8 +37,8 @@ export class MenuShortcutComponent implements OnInit { ngOnInit(): void { this.coreUrl = angularGlobals.coreUrl; setTimeout(() => { - if(this.shortcut.shortcutsData.user.indexingGroups.length > 0) { - this.shortcut.shortcutsData.user.indexingGroups.forEach((group: any) => { + if(this.headerService.user.indexingGroups.length > 0) { + this.headerService.user.indexingGroups.forEach((group: any) => { this.speedDialFabButtons.push({ icon: 'fa fa-plus', tooltip: this.lang.indexingWithProfile+' '+ group.label, diff --git a/src/frontend/service/header.service.ts b/src/frontend/service/header.service.ts index d4abbcc94f5..1a6015f15a8 100755 --- a/src/frontend/service/header.service.ts +++ b/src/frontend/service/header.service.ts @@ -1,10 +1,37 @@ import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { LANG } from '../app/translate.component'; @Injectable() export class HeaderService { - headerMessage : string = ""; - subHeaderMessage : string = ""; + headerMessage: string = ""; + subHeaderMessage: string = ""; + user: any = { firstname: "", lastname: "" }; + menu: any[] = []; + lang: any = LANG; + constructor(public http: HttpClient) { } + + loadHeader() { + this.http.get('../../rest/header') + .subscribe((data: any) => { + this.user = data.user; + this.user.menu = data.menu; + + data.menu.unshift({ + "name": this.lang.home, + "comment": this.lang.home, + "servicepage": "/home", + "shortcut": "true", + "style": "fa fa-home", + "angular": "true" + }); + this.menu = data.menu; + + }, (err) => { + console.log(err.error.errors); + }); + } setHeader(maintTitle: string, subTitle: any = '') { this.headerMessage = maintTitle; diff --git a/src/frontend/service/shortcut-menu.service.ts b/src/frontend/service/shortcut-menu.service.ts deleted file mode 100755 index 24bee986942..00000000000 --- a/src/frontend/service/shortcut-menu.service.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Injectable } from '@angular/core'; - -@Injectable() -export class ShortcutMenuService { - - shortcutsData : any = { - user : [], - menu : [] - }; -} -- GitLab