import {Component, Input} from '@angular/core';
import {ZenodoInformationClass} from './utils/zenodoInformation.class';
import {EnvProperties} from "../utils/properties/env-properties";
import {ActivatedRoute, Router} from "@angular/router";
import {PiwikService} from "../utils/piwik/piwik.service";
import {HelperService} from "../utils/helper/helper.service";
import {RouterHelper} from "../utils/routerHelper.class";
import {SEOService} from "../sharedComponents/SEO/SEO.service";
import {Meta, Title} from "@angular/platform-browser";
import {Breadcrumb} from "../utils/breadcrumbs/breadcrumbs.component";
@Component({
selector: 'deposit-first-page',
template: `
`
})
export class DepositFirstPageComponent {
public url: string = null;
public title: string = "Deposit your research - Learn How";
@Input() public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
@Input() piwikSiteId = null;
piwiksub:any;
@Input() communityId = null;
public pageContents = null;
public divContents = null;
public keyword: string;
public depositRoute: string;
public searchPlaceHolder = "Search by title, country, organization, subject, type...";
properties:EnvProperties;
public routerHelper:RouterHelper = new RouterHelper();
@Input() showBreadcrumb:boolean = false;
breadcrumbs:Breadcrumb[] = [];
constructor (private route: ActivatedRoute, private _piwikService:PiwikService,
private helper: HelperService,
private _router: Router,
private _meta: Meta, private _title: Title,
private seoService: SEOService) {
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.url = this.properties.baseLink+this._router.url;
this.seoService.createLinkForCanonicalURL(this.url, false);
var description = "Openaire, Zenodo, repositories, open access, content provider, compatibility, deposit";
this.updateTitle(this.title);
this.updateDescription(description);
this.updateUrl(this.url);
this.depositRoute = this.properties.depositSearchPage;
//this.getDivContents();
this.getPageContents();
if (!this.zenodoInformation) {
this.zenodoInformation = new ZenodoInformationClass();
}
if (!this.zenodoInformation.shareInZenodoUrl) {
this.zenodoInformation.url = this.properties.zenodo;
}
if (!this.zenodoInformation.name) {
this.zenodoInformation.name = "Zenodo";
}
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.piwiksub = this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe();
}
this.breadcrumbs.push({name: 'home', route: '/'}, {name: "Deposit", route: null});
});
}
public getPageContents() {
this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
this.pageContents = contents;
})
}
public getDivContents() {
this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
this.divContents = contents;
})
}
ngOnDestroy() {
if(this.piwiksub){
this.piwiksub.unsubscribe();
}
}
private updateDescription(description:string) {
this._meta.updateTag({content:description},"name='description'");
this._meta.updateTag({content:description},"property='og:description'");
}
private updateTitle(title:string) {
var _prefix ="";
if(!this.communityId) {
_prefix ="OpenAIRE | ";
}
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
this._title.setTitle(_title);
this._meta.updateTag({content:_title},"property='og:title'");
}
private updateUrl(url:string) {
this._meta.updateTag({content:url},"property='og:url'");
}
}