2018-06-10 04:40:53 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
2018-07-06 04:37:35 +02:00
|
|
|
import { Title } from '@angular/platform-browser';
|
2018-06-10 04:40:53 +02:00
|
|
|
import {
|
2018-07-06 04:37:35 +02:00
|
|
|
ActivatedRoute,
|
2018-06-10 04:40:53 +02:00
|
|
|
NavigationEnd,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
2018-07-06 04:37:35 +02:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
|
2018-06-10 04:40:53 +02:00
|
|
|
@Injectable()
|
|
|
|
export class RouterService {
|
|
|
|
private previousUrl: string = undefined;
|
|
|
|
private currentUrl: string = undefined;
|
|
|
|
|
2018-07-06 04:37:35 +02:00
|
|
|
constructor(private router: Router, private activatedRoute: ActivatedRoute,
|
2019-02-22 19:17:10 +01:00
|
|
|
private titleService: Title, i18nService: I18nService) {
|
2018-06-10 04:40:53 +02:00
|
|
|
this.currentUrl = this.router.url;
|
|
|
|
router.events.subscribe((event) => {
|
|
|
|
if (event instanceof NavigationEnd) {
|
|
|
|
this.previousUrl = this.currentUrl;
|
|
|
|
this.currentUrl = event.url;
|
2018-07-06 04:37:35 +02:00
|
|
|
|
|
|
|
let title = i18nService.t('pageTitle', 'Bitwarden');
|
|
|
|
let titleId: string = null;
|
|
|
|
let rawTitle: string = null;
|
|
|
|
let child = this.activatedRoute.firstChild;
|
|
|
|
while (child != null) {
|
|
|
|
if (child.firstChild != null) {
|
|
|
|
child = child.firstChild;
|
|
|
|
} else if (child.snapshot.data != null && child.snapshot.data.title != null) {
|
|
|
|
rawTitle = child.snapshot.data.title;
|
|
|
|
break;
|
|
|
|
} else if (child.snapshot.data != null && child.snapshot.data.titleId != null) {
|
|
|
|
titleId = child.snapshot.data.titleId;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
titleId = null;
|
|
|
|
rawTitle = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (titleId != null || rawTitle != null) {
|
|
|
|
const newTitle = rawTitle != null ? rawTitle : i18nService.t(titleId);
|
|
|
|
if (newTitle != null && newTitle !== '') {
|
|
|
|
title = (newTitle + ' | ' + title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.titleService.setTitle(title);
|
2018-06-10 04:40:53 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getPreviousUrl() {
|
|
|
|
return this.previousUrl;
|
|
|
|
}
|
2019-02-22 19:17:10 +01:00
|
|
|
|
|
|
|
setPreviousUrl(url: string) {
|
|
|
|
this.previousUrl = url;
|
|
|
|
}
|
2018-06-10 04:40:53 +02:00
|
|
|
}
|