|
1 | 1 | import { AfterViewInit, Component, Inject, Renderer } from '@angular/core';
|
| 2 | +import { Http } from '@angular/http'; |
2 | 3 | import { DOCUMENT } from '@angular/platform-browser';
|
3 |
| -import { NavigationEnd, Router } from '@angular/router'; |
| 4 | +import { NavigationEnd, Router, UrlSerializer } from '@angular/router'; |
| 5 | +import 'rxjs/add/operator/map'; |
4 | 6 |
|
5 | 7 | @Component({
|
6 | 8 | selector: 'top-menu',
|
7 | 9 | templateUrl: './top-menu.component.html'
|
8 | 10 | })
|
9 | 11 | export class TopMenuComponent implements AfterViewInit {
|
10 |
| - public isShown: boolean = false; |
| 12 | + public isShown = false; |
| 13 | + public appUrl: string; |
| 14 | + public appHash: string; |
| 15 | + public currentVersion: string; |
| 16 | + public previousDocs: string[] = []; |
| 17 | + public isLocalhost = false; |
11 | 18 |
|
12 |
| - private renderer: Renderer; |
13 |
| - private document: any; |
14 |
| - private router: Router; |
15 |
| - |
16 |
| - public constructor(renderer: Renderer, @Inject(DOCUMENT) document: any, router: Router) { |
17 |
| - this.router = router; |
18 |
| - this.renderer = renderer; |
19 |
| - this.document = document; |
| 19 | + public constructor(private renderer: Renderer, |
| 20 | + @Inject(DOCUMENT) private document: any, |
| 21 | + private router: Router, |
| 22 | + private http: Http) { |
20 | 23 | }
|
21 | 24 |
|
22 | 25 | public ngAfterViewInit(): any {
|
23 | 26 | // todo: remove this sh**
|
24 |
| - const getUrl = (router: Router) => router.routerState.snapshot.url.slice(0, router.routerState.snapshot.url.indexOf('#')); |
| 27 | + this.isLocalhost = location.hostname === 'localhost'; |
| 28 | + const getUrl = (router: Router) => { |
| 29 | + const indexOfHash = router.routerState.snapshot.url.indexOf('#'); |
| 30 | + |
| 31 | + return router.routerState.snapshot.url.slice(0, indexOfHash); |
| 32 | + }; |
25 | 33 | let _prev = getUrl(this.router);
|
26 | 34 | this.router.events.subscribe((event: any) => {
|
27 |
| - let _cur = getUrl(this.router); |
| 35 | + const _cur = getUrl(this.router); |
| 36 | + this.appHash = location.hash === '#/' ? '' : location.hash; |
28 | 37 | if (event instanceof NavigationEnd && _cur !== _prev) {
|
29 | 38 | _prev = _cur;
|
30 | 39 | this.toggle(false);
|
31 | 40 | }
|
32 | 41 | });
|
| 42 | + |
| 43 | + this.http.get('assets/json/versions.json') |
| 44 | + .map(res => res.json()) |
| 45 | + .subscribe((data: any) => { |
| 46 | + this.previousDocs = data; |
| 47 | + }); |
| 48 | + this.http.get('assets/json/current-version.json') |
| 49 | + .map(res => res.json()) |
| 50 | + .subscribe((data: any) => { |
| 51 | + this.currentVersion = data.version; |
| 52 | + }); |
| 53 | + |
| 54 | + this.appUrl = location.protocol + '//' + location.hostname + (this.isLocalhost ? ':' + location.port + '/' : '/'); |
33 | 55 | }
|
34 | 56 |
|
35 | 57 | public toggle(isShown?: boolean): void {
|
|
0 commit comments