/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ import { Injectable } from '@angular/core'; import { Router, Event, NavigationStart } from '@angular/router'; import { RoutingDisabler } from './RoutingDisabler'; @Injectable() export class RoutingDisablerService { private _locks: Array = new Array(); private _disabler: RoutingDisabler = null; get isDisabled(): boolean { return this._disabler !== null; } constructor(private _router: Router) {} public disable(lockId: string): void { if (!this._disabler) { this._disabler = new RoutingDisabler(this._router); } if (this._locks.indexOf(lockId) < 0) { this._locks.push(lockId); } } public enable(lockId: string): void { let idx = this._locks.indexOf(lockId); if (idx >= 0) { this._locks.splice(idx, 1); if (this._locks.length == 0) { this._disabler.reEnable(); this._disabler = null; } } } }