Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { NavigationEnd, Router, RoutesRecognized } from '@angular/router';
3
import { AuthenticationService } from './services/authentication.service';
4
import { environment } from '../environments/environment';
5
import { MatomoInjector, MatomoTracker } from 'ngx-matomo';
6

    
7
@Component({
8
  selector: 'oa-repo-manager',
9
  templateUrl: './app.component.html',
10
  styleUrls: ['./app.component.css'],
11
})
12
export class AppComponent implements OnInit {
13

    
14
  open: boolean = true;
15

    
16
  constructor(private router: Router,
17
              private authService: AuthenticationService,
18
              private matomoInjector: MatomoInjector,
19
              private matomoTracker: MatomoTracker) {
20

    
21
    console.log('21-06-2019. Fixed matomo to log userIds?');
22

    
23
    let piwikUrl;
24
    if (window.location.origin.includes('beta')) {
25
      // piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=92&rec=1';
26
      piwikUrl = '92';
27
    } else if (window.location.origin.includes('localhost:4200') ||
28
               window.location.origin.includes('athenarc')) {
29
      // piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=92&rec=1';
30
      piwikUrl = '9222222';
31
    } else {
32
      // piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=111&rec=1';
33
      piwikUrl = '111';
34
    }
35
    this.matomoInjector.init('https://analytics.openaire.eu/', piwikUrl);
36

    
37
    /*disabling console.log in production*/
38
    if ( environment.production === true ) {
39
      console.log = function () {};
40
    }
41

    
42
    // URL of the SPA to redirect the user to after login
43
    // this.authService.redirectUrl = "/dashboard";
44

    
45
    if (window.location.pathname.includes('/compatibility/browseHistory/')) {
46
      this.authService.redirectUrl = window.location.pathname;
47
      console.log('redirectUrl', this.authService.redirectUrl);
48
    }
49

    
50
    this.authService.tryLogin();
51
  }
52

    
53
  ngOnInit() {
54
    this.router.events.subscribe((evt) => {
55
      if (!(evt instanceof NavigationEnd)) {
56
        return;
57
      }
58
      if (this.authService.isLoggedIn) {
59
        this.matomoTracker.setUserId(this.authService.getUserEmail());
60
      }
61
      window.scrollTo(0, 0);
62
    });
63
  }
64

    
65
  isLandingRoute() {
66
    // console.log('Is home route? Route is: ' + this.router.url);
67
    return (this.router.url === '/') || (this.router.url === '/home') || (this.router.url === '/about');
68
  }
69

    
70
  public toggleOpen(event: MouseEvent) {
71
    event.preventDefault();
72
    this.open = !this.open;
73
  }
74

    
75
  // ngAfterContentInit() {
76
  //
77
  //   // this.loadScript('assets/js/common.js');
78
  //   // this.loadScript('assets/js/uikit_custom.js');
79
  //   // this.loadScript('assets/js/altair_admin_common.js');
80
  //   this.loadScript('assets/js/altair_admin_common.min.js');
81
  //
82
  //   // setTimeout( () => {
83
  //   //   // this.loadScript('assets/js/common.js');
84
  //   //   // this.loadScript('assets/js/uikit_custom.js');
85
  //   //   this.loadScript('assets/js/altair_admin_common.min.js');
86
  //   // }, 2000);
87
  //
88
  //   // $.getScript('assets/js/altair_admin_common.min.js');
89
  //
90
  //
91
  //
92
  //   // // Load the script
93
  //   // // var self = this;
94
  //   //
95
  //   // var script = <HTMLScriptElement>document.createElement("SCRIPT");
96
  //   // script.src = 'assets/js/altair_admin_common.min.js';
97
  //   // script.type = 'text/javascript';
98
  //   // // self.script = <HTMLScriptElement>document.createElement("SCRIPT");
99
  //   // // self.script.src = '../Content/js/settings.js';
100
  //   // // self.script.type = 'text/javascript';
101
  //   // document.getElementsByTagName("head")[0].appendChild(script);
102
  // }
103
  //
104
  // public loadScript(url) {
105
  //   console.log('preparing to load...')
106
  //   let node = document.createElement('script');
107
  //   node.src = url;
108
  //   node.type = 'text/javascript';
109
  //   document.getElementsByTagName('head')[0].appendChild(node);
110
  // }
111

    
112
}
(5-5/6)