Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Meta, Title} from '@angular/platform-browser';
4
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
5
import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service';
6
import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service';
7
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
8

    
9
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
10
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
11

    
12
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
13
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
14
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
15
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
16

    
17
@Component({
18
  selector: 'home',
19
  templateUrl: 'home.component.html',
20
})
21

    
22
export class HomeComponent {
23
  public piwiksub: any;
24

    
25
  public pageTitle = "OpenAIRE | Monitor";
26
  public pageContents = null;
27
  public divContents = null;
28
  public status: number;
29
  public loading: boolean = true;
30
  public subscriberErrorMessage: string = "";
31
  public errorCodes: ErrorCodes;
32
  private errorMessages: ErrorMessagesComponent;
33

    
34
  properties: EnvProperties;
35
  public keyword: string = "";
36
  public type: string = "all";
37

    
38
  constructor(
39
    private route: ActivatedRoute,
40
    private _router: Router,
41
    private _meta: Meta,
42
    private _title: Title,
43
    private _piwikService: PiwikService,
44
    private helper: HelperService,
45
    private seoService: SEOService) {
46

    
47
    var description = "OpenAIRE - Monitor, monitor dashboard, funder, statistics, ";
48
    var title = "OpenAIRE - Monitor";
49

    
50
    this._meta.updateTag({content: description}, "name='description'");
51
    this._meta.updateTag({content: description}, "property='og:description'");
52
    this._meta.updateTag({content: title}, "property='og:title'");
53
    this._title.setTitle(title);
54

    
55
    this.errorCodes = new ErrorCodes();
56
    this.errorMessages = new ErrorMessagesComponent();
57
    this.status = this.errorCodes.LOADING;
58
  }
59

    
60
  public ngOnInit() {
61
    this.route.data
62
      .subscribe((data: { envSpecific: EnvProperties }) => {
63
        this.properties = data.envSpecific;
64
        var url = data.envSpecific.baseLink + this._router.url;
65
        this.seoService.createLinkForCanonicalURL(url, false);
66
        this._meta.updateTag({content: url}, "property='og:url'");
67
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
68
          this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Monitor", this.properties.piwikSiteId).subscribe();
69
        }
70
        //this.getDivContents();
71
        this.getPageContents();
72
      });
73
  }
74

    
75
  private getPageContents() {
76
    this.helper.getPageHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
77
      this.pageContents = contents;
78
    })
79
  }
80

    
81
  private getDivContents() {
82
    this.helper.getDivHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
83
      this.divContents = contents;
84
    })
85
  }
86

    
87
  public quote(param: string): string {
88
    return StringUtils.quote(param);
89
  }
90

    
91
  public ngOnDestroy() {
92
    if (this.piwiksub) {
93
      this.piwiksub.unsubscribe();
94
    }
95
  }
96

    
97
  private handleError(message: string, error): number {
98
    var code = "";
99
    if (!error.status) {
100
      var error = error.json();
101
      code = error.code;
102
    } else {
103
      code = error.status;
104
    }
105

    
106
    console.error("Communities (component): " + message, error);
107

    
108
    return this.errorMessages.getErrorCode(code);
109
  }
110
}
(3-3/4)