114 lines
4.1 KiB
TypeScript
114 lines
4.1 KiB
TypeScript
import {Component} from '@angular/core';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {Meta, Title} from '@angular/platform-browser';
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service';
|
|
import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service';
|
|
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
|
|
|
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
|
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
|
|
|
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
|
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
|
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
|
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
|
|
import {StakeholderService} from "../services/stakeholder.service";
|
|
import {Stakeholder} from "../stakeholder";
|
|
|
|
@Component({
|
|
selector: 'monitor',
|
|
templateUrl: 'monitor.component.html',
|
|
})
|
|
|
|
export class MonitorComponent {
|
|
public piwiksub: any;
|
|
public pageContents = null;
|
|
public divContents = null;
|
|
public status: number;
|
|
public loading: boolean = true;
|
|
public errorCodes: ErrorCodes;
|
|
public stakeholder: Stakeholder;
|
|
private errorMessages: ErrorMessagesComponent;
|
|
properties: EnvProperties;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private _router: Router,
|
|
private _meta: Meta,
|
|
private _title: Title,
|
|
private _piwikService: PiwikService,
|
|
private helper: HelperService,
|
|
private stakeholderService: StakeholderService,
|
|
private seoService: SEOService) {
|
|
this.errorCodes = new ErrorCodes();
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
this.status = this.errorCodes.LOADING;
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.route.data
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
this.route.params.subscribe( params => {
|
|
this.properties = data.envSpecific;
|
|
var url = data.envSpecific.baseLink + this._router.url;
|
|
this.stakeholderService.getStakeholder(params['id']).subscribe(stakeholder => {
|
|
this.stakeholder = stakeholder;
|
|
this.seoService.createLinkForCanonicalURL(url, false);
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
|
var description = "Monitor | " + this.stakeholder.index_name;
|
|
var title = "Monitor | " + this.stakeholder.index_shortName;
|
|
this._meta.updateTag({content: description}, "name='description'");
|
|
this._meta.updateTag({content: description}, "property='og:description'");
|
|
this._meta.updateTag({content: title}, "property='og:title'");
|
|
this._title.setTitle(title);
|
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
|
this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
|
|
}
|
|
//this.getDivContents();
|
|
this.getPageContents();
|
|
}, error => {
|
|
console.log(error);
|
|
this._router.navigate(['']);
|
|
})
|
|
});
|
|
});
|
|
}
|
|
|
|
private getPageContents() {
|
|
this.helper.getPageHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
|
|
this.pageContents = contents;
|
|
})
|
|
}
|
|
|
|
private getDivContents() {
|
|
this.helper.getDivHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
|
|
this.divContents = contents;
|
|
})
|
|
}
|
|
|
|
public quote(param: string): string {
|
|
return StringUtils.quote(param);
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
if (this.piwiksub) {
|
|
this.piwiksub.unsubscribe();
|
|
}
|
|
}
|
|
|
|
private handleError(message: string, error): number {
|
|
var code = "";
|
|
if (!error.status) {
|
|
var error = error.json();
|
|
code = error.code;
|
|
} else {
|
|
code = error.status;
|
|
}
|
|
|
|
console.error("Monitor (component): " + message, error);
|
|
|
|
return this.errorMessages.getErrorCode(code);
|
|
}
|
|
}
|