openaire-library/deposit/deposit.component.ts

92 lines
3.2 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import { Router } from '@angular/router';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import { Meta} from '../../angular2-meta';
import {PiwikService} from '../utils/piwik/piwik.service';
@Component({
selector: 'deposit',
templateUrl: 'deposit.component.html'
})
export class DepositComponent {
@Input() compatibility: string = '';
@Input() mapUrl: string = null; // optional in case i-frame is needed
@Input() searchBySubjects: boolean = false; // optional: in case search by subjects is needed
public status: number;
// Type of entity: Publication or Research Data
@Input() requestFor: string = "Publications";
// url's needed for information text
public openAccess: string;
public openAccessRepo: string;
public fp7Guidlines: string;
public h2020Guidlines: string;
public ercGuidlines: string;
public helpdesk: string;
// Id of the new selected organization to be searched
public selectedId: string = "";
public warningMessage: string = "";
piwiksub:any;
constructor (private _router: Router, private _meta: Meta, private _piwikService:PiwikService) {
this.openAccess = OpenaireProperties.getOpenAccess();
this.openAccessRepo = OpenaireProperties.getOpenAccessRepo();
this.fp7Guidlines = OpenaireProperties.getFP7Guidlines();
this.h2020Guidlines = OpenaireProperties.getH2020Guidlines();
this.ercGuidlines = OpenaireProperties.getERCGuidlines();
this.helpdesk = OpenaireProperties.getHelpdesk();
this.updateTitle("Deposit "+this.requestFor);
this.updateDescription("Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor);
this.updateUrl(OpenaireProperties.getBaseLink()+this._router.url);
if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
this.piwiksub = this._piwikService.trackView("Deposit "+this.requestFor).subscribe();
}
}
ngOnDestroy() {
if(this.piwiksub){
this.piwiksub.unsubscribe();
}
}
public organizationSelected(id: string) {
console.info("organization selected");
if(id && id.length > 0){
if(this.requestFor == "Publications") {
this._router.navigate( ['participate/deposit-publications-result'], { queryParams: { "organizationId": id } } );
} else if(this.requestFor == "Research Data") {
this._router.navigate( ['participate/deposit-datasets-result'], { queryParams: { "organizationId": id } } );
}
} else {
this.warningMessage = "No organization selected";
}
}
public valueChanged($event){
this.selectedId = $event.value;
}
private updateDescription(description:string){
this._meta.updateMeta("description", description);
this._meta.updateProperty("og:description", description);
}
private updateTitle(title:string){
var _prefix ="OpenAIRE | ";
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
this._meta.setTitle(_title );
this._meta.updateProperty("og:title",_title);
}
private updateUrl(url:string){
this._meta.updateProperty("og:url", url);
}
}