diff options
author | Ittay Stern <ittay.stern@att.com> | 2018-08-29 17:01:32 +0300 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-02-18 18:35:30 +0200 |
commit | 6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 (patch) | |
tree | 936005c364dc5a7264d6304d4777c3d83494db22 /vid-webpack-master/src/app/drawingBoard/guards/servicePlanningGuard/drawingBoardGuard.ts | |
parent | 67d99f816cc583643c35193197594cf78d8ce60a (diff) |
merge from ecomp a88f0072 - Modern UI
Issue-ID: VID-378
Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/drawingBoard/guards/servicePlanningGuard/drawingBoardGuard.ts')
-rw-r--r-- | vid-webpack-master/src/app/drawingBoard/guards/servicePlanningGuard/drawingBoardGuard.ts | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/drawingBoard/guards/servicePlanningGuard/drawingBoardGuard.ts b/vid-webpack-master/src/app/drawingBoard/guards/servicePlanningGuard/drawingBoardGuard.ts new file mode 100644 index 000000000..4a305b193 --- /dev/null +++ b/vid-webpack-master/src/app/drawingBoard/guards/servicePlanningGuard/drawingBoardGuard.ts @@ -0,0 +1,56 @@ +import {Injectable} from "@angular/core"; +import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router} from "@angular/router"; +import {NgRedux} from "@angular-redux/store"; +import {Observable} from "rxjs"; +import {HttpClient} from "@angular/common/http"; +import {AppState} from "../../../shared/store/reducers"; +import {updateDrawingBoardStatus} from "../../../shared/storeUtil/utils/global/global.actions"; +import {DrawingBoardModes} from "../../service-planning/drawing-board.modes"; +import {of} from "rxjs"; + +@Injectable() +export class DrawingBoardGuard implements CanActivate { + constructor(private store: NgRedux<AppState>, private _http: HttpClient, private _router : Router) { } + canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { + let url : string = `/vid/roles/service_permissions?subscriberId=${next.queryParams['subscriberId']}&serviceType=${next.queryParams['serviceType']}`; + const viewMode = state.url.includes(DrawingBoardModes.RETRY_EDIT)? DrawingBoardModes.RETRY: DrawingBoardModes.VIEW; + return this._http.get(url) + .map((result : DrawingBoardPermissions) => { + if(!result.isEditPermitted){ + this.navigateToNewViewEdit(next.queryParams, viewMode); + return false; + }else { + return true; + } + }).catch(err => { + this.navigateToNewViewEdit(next.queryParams, viewMode); + return of(false); + }); + } + + navigateToNewViewEdit(queryParams: any, mode: DrawingBoardModes): void{ + this.store.dispatch(updateDrawingBoardStatus(mode)); + const viewEditUrlTree = this.getNewViewEditUrlTree(queryParams, mode); + this._router.navigateByUrl(viewEditUrlTree); + window.parent.location.assign('../../serviceModels.htm#'+viewEditUrlTree.toString()); + } + + getNewViewEditUrlTree(queryParams: any, mode: DrawingBoardModes) { + return this._router.createUrlTree( + ['/servicePlanning/' + mode], + { + queryParams: + { + serviceModelId: queryParams['serviceModelId'], + serviceInstanceId: queryParams['serviceInstanceId'], + serviceType : queryParams['serviceType'], + subscriberId : queryParams['subscriberId'], + jobId : queryParams['jobId'], + } + }); + } +} + +export class DrawingBoardPermissions { + isEditPermitted : boolean +} |