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
|
import {StakeholderService} from "../services/stakeholder.service";
|
17
|
import {Stakeholder} from "../stakeholder";
|
18
|
|
19
|
@Component({
|
20
|
selector: 'monitor',
|
21
|
templateUrl: 'monitor.component.html',
|
22
|
})
|
23
|
|
24
|
export class MonitorComponent {
|
25
|
public piwiksub: any;
|
26
|
public pageContents = null;
|
27
|
public divContents = null;
|
28
|
public status: number;
|
29
|
public loading: boolean = true;
|
30
|
public errorCodes: ErrorCodes;
|
31
|
public stakeholder: Stakeholder;
|
32
|
private errorMessages: ErrorMessagesComponent;
|
33
|
properties: EnvProperties;
|
34
|
|
35
|
constructor(
|
36
|
private route: ActivatedRoute,
|
37
|
private _router: Router,
|
38
|
private _meta: Meta,
|
39
|
private _title: Title,
|
40
|
private _piwikService: PiwikService,
|
41
|
private helper: HelperService,
|
42
|
private stakeholderService: StakeholderService,
|
43
|
private seoService: SEOService) {
|
44
|
this.errorCodes = new ErrorCodes();
|
45
|
this.errorMessages = new ErrorMessagesComponent();
|
46
|
this.status = this.errorCodes.LOADING;
|
47
|
}
|
48
|
|
49
|
public ngOnInit() {
|
50
|
this.route.data
|
51
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
52
|
this.route.params.subscribe( params => {
|
53
|
this.properties = data.envSpecific;
|
54
|
var url = data.envSpecific.baseLink + this._router.url;
|
55
|
this.stakeholderService.getStakeholder(params['id']).subscribe(stakeholder => {
|
56
|
this.stakeholder = stakeholder;
|
57
|
this.seoService.createLinkForCanonicalURL(url, false);
|
58
|
this._meta.updateTag({content: url}, "property='og:url'");
|
59
|
var description = "Monitor | " + this.stakeholder.index_name;
|
60
|
var title = "Monitor | " + this.stakeholder.index_shortName;
|
61
|
this._meta.updateTag({content: description}, "name='description'");
|
62
|
this._meta.updateTag({content: description}, "property='og:description'");
|
63
|
this._meta.updateTag({content: title}, "property='og:title'");
|
64
|
this._title.setTitle(title);
|
65
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
66
|
this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
|
67
|
}
|
68
|
//this.getDivContents();
|
69
|
this.getPageContents();
|
70
|
}, error => {
|
71
|
console.log(error);
|
72
|
this._router.navigate(['']);
|
73
|
})
|
74
|
});
|
75
|
});
|
76
|
}
|
77
|
|
78
|
private getPageContents() {
|
79
|
this.helper.getPageHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
|
80
|
this.pageContents = contents;
|
81
|
})
|
82
|
}
|
83
|
|
84
|
private getDivContents() {
|
85
|
this.helper.getDivHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
|
86
|
this.divContents = contents;
|
87
|
})
|
88
|
}
|
89
|
|
90
|
public quote(param: string): string {
|
91
|
return StringUtils.quote(param);
|
92
|
}
|
93
|
|
94
|
public ngOnDestroy() {
|
95
|
if (this.piwiksub) {
|
96
|
this.piwiksub.unsubscribe();
|
97
|
}
|
98
|
}
|
99
|
|
100
|
private handleError(message: string, error): number {
|
101
|
var code = "";
|
102
|
if (!error.status) {
|
103
|
var error = error.json();
|
104
|
code = error.code;
|
105
|
} else {
|
106
|
code = error.status;
|
107
|
}
|
108
|
|
109
|
console.error("Monitor (component): " + message, error);
|
110
|
|
111
|
return this.errorMessages.getErrorCode(code);
|
112
|
}
|
113
|
}
|