Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Session} from '../login/utils/helper.class';
4
import {HelperFunctions} from "../utils/HelperFunctions.class";
5

    
6
@Component({
7
  selector: 'reload',
8
  template: `
9
    <loading [full]="true"></loading>
10
  `
11
})
12
export class ReloadComponent {
13
  
14
  constructor(private route: ActivatedRoute, private _router: Router) {
15
  }
16
  
17
  public ngOnInit() {
18
    let URL = Session.getReloadUrl();
19
    if (URL && URL["path"] && URL["path"] != "") {
20
      let url: string = URL["path"];
21
      let host = URL["host"];
22
      let paramsObject = ((URL["params"] && URL["params"] != null) ? Session.getParamsObj(URL["params"]) : null);
23
      if (host == (location.protocol + "//" + location.host)) {
24
        let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/";
25
        url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url;
26
        if (paramsObject) {
27
          Session.setReloadUrl("", "", "", "");
28
          if(URL['fragment'] && URL['fragment'] !== '') {
29
            this._router.navigate([url], {queryParams: paramsObject, fragment: URL['fragment']});
30
          } else {
31
            this._router.navigate([url], {queryParams: paramsObject});
32
          }
33
        } else {
34
          Session.setReloadUrl("", "", "", "");
35
          if(URL['fragment'] && URL['fragment'] !== '') {
36
            this._router.navigate([url], {fragment: URL['fragment']});
37
          } else {
38
            this._router.navigate([url]);
39
          }
40
        }
41
      } else {
42
        Session.setReloadUrl("", "", "", "");
43
        window.location.href = host + url + ((URL["params"] && URL["params"] != null) ? ((URL["params"].indexOf("?") == -1 ? "?" : "") + URL["params"]) : "");
44
      }
45
      
46
    } else {
47
      Session.setReloadUrl("", "", "", "");
48
      this._router.navigate(['/']);
49
    }
50
  }
51
  
52
}
(2-2/3)