openaire-library/deposit/deposit.component.ts

108 lines
3.7 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {Router, ActivatedRoute} from '@angular/router';
import {Title, Meta} from '@angular/platform-browser';
import {Observable} from 'rxjs/Observable';
import {EnvProperties} from '../utils/properties/env-properties';
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
@Input() piwikSiteId = null;
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;
properties:EnvProperties;
constructor (private route: ActivatedRoute, private _router: Router,
private _meta: Meta, private _title: Title,
private _piwikService:PiwikService) {
var title = "Deposit "+this.requestFor;
var description = "Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor;
this.updateTitle(title);
this.updateDescription(description);
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.openAccess = this.properties.openAccess;
this.openAccessRepo = this.properties.openAccessRepo;
this.fp7Guidlines = this.properties.fp7Guidlines
this.h2020Guidlines = this.properties.h2020Guidlines
this.ercGuidlines = this.properties.ercGuidlines
this.helpdesk = this.properties.helpdesk;
this.updateUrl(data.envSpecific.baseLink+this._router.url);
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.piwiksub = this._piwikService.trackView(this.properties, "Deposit "+this.requestFor, this.piwikSiteId).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.updateTag({content:description},"name='description'");
this._meta.updateTag({content:description},"property='og:description'");
}
private updateTitle(title:string) {
var _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'");
}
}