From 7c5c4acf0e6643bfc33555fa45f50d32b564db29 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 8 Apr 2022 13:52:00 +0100 Subject: [PATCH] improve --- src/app/guards/auth.guard.ts | 28 ++++++++++++- src/app/guards/inactivity.guard.ts | 2 +- src/app/guards/login.guard.ts | 7 +++- src/app/home/home.page.ts | 3 +- src/app/services/route.service.ts | 9 +++++ .../worker/document-counter.service.spec.ts | 16 -------- .../worker/document-counter.service.ts | 39 ------------------- 7 files changed, 43 insertions(+), 61 deletions(-) delete mode 100644 src/app/services/worker/document-counter.service.spec.ts delete mode 100644 src/app/services/worker/document-counter.service.ts diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts index f8c5cbbda..688f6d22c 100644 --- a/src/app/guards/auth.guard.ts +++ b/src/app/guards/auth.guard.ts @@ -5,7 +5,7 @@ import { AuthService } from '../services/auth.service'; import { PermissionService } from '../services/permission.service'; import { LocalstoreService } from '../store/localstore.service'; import { SessionStore } from '../store/session.service'; - +import { RouteService } from 'src/app/services/route.service' @Injectable({ providedIn: 'root' }) @@ -15,6 +15,7 @@ export class AuthGuard implements CanActivate { private localstoreService: LocalstoreService, private authService: AuthService, public p: PermissionService, + private RouteService: RouteService ){} canActivate( @@ -35,7 +36,30 @@ export class AuthGuard implements CanActivate { this.authService.loginChat(); } - return true; + const pathname = window.location.pathname + + if(this.p.userPermission(this.p.permissionList.Agenda.access) && pathname.startsWith('/home/agenda')) { + return true; + } else if (this.p.userPermission(this.p.permissionList.Gabinete.access) && pathname.startsWith('/home/gabinete-digital')) { + return true; + } + else if(this.p.userPermission(this.p.permissionList.Chat.access) && pathname.startsWith('/home/chat')) { + return true; + } else if(this.p.userPermission(this.p.permissionList.Actions.access) && pathname.startsWith('/home/publications')) { + return true; + } else if ((this.p.userPermission([this.p.permissionList.Agenda.access]) || this.p.userPermission([this.p.permissionList.Gabinete.access])) && pathname.startsWith('/home/events')) { + + } else if (pathname == '/') { + return true + } + else if (this.RouteService.history.length >= 1) { + const pathName = this.RouteService.getLastRouteA() + this.router.navigate([pathName]); + } else { + this.router.navigate(['/']); + } + + return false; } } diff --git a/src/app/guards/inactivity.guard.ts b/src/app/guards/inactivity.guard.ts index f3a06be73..e4cd3f7a8 100644 --- a/src/app/guards/inactivity.guard.ts +++ b/src/app/guards/inactivity.guard.ts @@ -29,7 +29,7 @@ export class InactivityGuard implements CanActivate { else if(this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)){ this.router.navigate(['/home/chat']); } - else if(this.p.userPermission(this.p.permissionList.Actions.access)){ + else if(this.p.userPermission(this.p.permissionList.Actions.access)) { this.router.navigate(['/home/publications']); } else { diff --git a/src/app/guards/login.guard.ts b/src/app/guards/login.guard.ts index 8b7a734d3..d086c6180 100644 --- a/src/app/guards/login.guard.ts +++ b/src/app/guards/login.guard.ts @@ -3,12 +3,16 @@ import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Rout import { Observable } from 'rxjs'; import { SessionStore } from '../store/session.service'; import { Platform } from '@ionic/angular'; +import { RouteService } from 'src/app/services/route.service' @Injectable({ providedIn: 'root' }) export class LoginGuard implements CanActivate { - constructor( private router:Router, private platform: Platform,) { + constructor( + private router:Router, + private platform: Platform, + private RouteService: RouteService ) { } canActivate( @@ -27,6 +31,7 @@ export class LoginGuard implements CanActivate { } else if(SessionStore.exist && !SessionStore.user.Inactivity && SessionStore.user.LoginPreference == 'Pin' && !this.platform.is('desktop') && !this.platform.is('mobileweb')) { this.router.navigate(['/inactivity']); return false + } else { return true } diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 04b9a5291..668efb97f 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -15,7 +15,6 @@ import { SessionStore } from '../store/session.service'; import { StorageService } from '../services/storage.service'; import { File } from '@ionic-native/file/ngx'; /* import { WebNotificationPopupService } from '../services/notification/web-notification-popup.service'; */ -import { DocumentCounterService } from '../services/worker/document-counter.service'; import { PermissionService } from '../services/permission.service'; import { BackgroundService } from 'src/app/services/background.service'; import { OfflineManagerService } from 'src/app/services/offline-manager.service'; @@ -33,6 +32,7 @@ import { NativeNotificationService } from 'src/app/services/native-notification. import { UserSession } from '../models/user.model'; import { PermissionList } from '../models/permission/permissionList'; + @Component({ selector: 'app-home', templateUrl: './home.page.html', @@ -92,7 +92,6 @@ export class HomePage implements OnInit { private activeroute: ActivatedRoute, /* private webnotification: WebNotificationsService, */ public p: PermissionService, - public documentCounterService: DocumentCounterService, private despachoRule: DespachoService, private inativityService: InativityService, private storageService: StorageService, diff --git a/src/app/services/route.service.ts b/src/app/services/route.service.ts index 2f0c59440..ac5b250b4 100644 --- a/src/app/services/route.service.ts +++ b/src/app/services/route.service.ts @@ -88,4 +88,13 @@ export class RouteService { } + + getLastRoute() { + return this.history[this.history.length - 1] + } + + getLastRouteA() { + return this.history[this.history.length - 2] + } + } diff --git a/src/app/services/worker/document-counter.service.spec.ts b/src/app/services/worker/document-counter.service.spec.ts deleted file mode 100644 index bc3c0f89e..000000000 --- a/src/app/services/worker/document-counter.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { DocumentCounterService } from './document-counter.service'; - -describe('DocumentCounterService', () => { - let service: DocumentCounterService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(DocumentCounterService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/src/app/services/worker/document-counter.service.ts b/src/app/services/worker/document-counter.service.ts deleted file mode 100644 index eafc6e6db..000000000 --- a/src/app/services/worker/document-counter.service.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Injectable } from '@angular/core'; -import { DespachoStore } from 'src/app/store/despacho-store.service'; -import { EventoAprovacaoStore } from 'src/app/store/eventoaprovacao-store.service'; -import { ExpedienteGdStore } from 'src/app/store/expedientegd-store.service'; -import { PendentesStore } from 'src/app/store/pendestes-store.service'; -import { PedidosStore } from 'src/app/store/pedidos-store.service'; -import { DespachosprStore } from 'src/app/store/despachospr-store.service'; -import { DeplomasStore } from 'src/app/store/deplomas.service'; - - -@Injectable({ - providedIn: 'root' -}) -export class DocumentCounterService { - - expedienteGbStore = ExpedienteGdStore; - pendentesStore = PendentesStore; - despachoStore = DespachoStore; - eventoAprovacaoStore = EventoAprovacaoStore; - pedidosStore = PedidosStore; - // expedientePrStore = ExpedienteprStore; - despachoPrStore = DespachosprStore; - deplomasStore = DeplomasStore - - constructor() { } - - // falta a contagem dos deplomas - get mdTotalDocument(): number { - return this.despachoStore.count + /** this.expedientePrStore.count + */ this.pedidosStore.countdeferimento - + this.pedidosStore.countparecer + this.expedienteGbStore.count + this.despachoPrStore.count + this.pendentesStore.count - + this.eventoAprovacaoStore.count + this.deplomasStore.diplomasListCount + this.deplomasStore.countDiplomasAssinadoListCount + this.deplomasStore.deplomasReviewCount - } - - get prTotalDocument(): number { - return this.despachoStore.count + /** this.expedientePrStore.count + */ this.pedidosStore.countdeferimento - + this.pedidosStore.countparecer + this.expedienteGbStore.count + this.despachoPrStore.count + this.pendentesStore.count - + this.eventoAprovacaoStore.count + this.deplomasStore.diplomasListCount + this.deplomasStore.countDiplomasAssinadoListCount + this.deplomasStore.deplomasReviewCount - } -}