openaire-library/deposit/datasets/depositBySubjectResult.comp...

161 lines
5.4 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {Router} from '@angular/router';
import {ActivatedRoute} from '@angular/router';
import {Title, Meta} from '@angular/platform-browser';
import {Observable} from 'rxjs/Observable';
import {EnvProperties} from '../../utils/properties/env-properties';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
import {RouterHelper} from '../../utils/routerHelper.class';
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
import {OrganizationService} from '../../services/organization.service';
import {PiwikService} from '../../utils/piwik/piwik.service';
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
import {ZenodoInformationClass} from '../utils/zenodoInformation.class';
@Component({
selector: 'deposit-by-subject-result',
templateUrl: 'depositBySubjectResult.component.html'
})
export class DepositBySubjectResultComponent {
@Input() compatibility: string = '';
// Type of entity: Publication or Research Data
@Input() requestFor: string = "Research Data";
@Input() subject: string = "";
@Input() piwikSiteId = null;
public newSubject: string= "";
public fetchDataproviders : FetchDataproviders;
public linkToSearchDataproviders = "";
// url of Zenodo
public zenodo: string;
public page: number = 1;
public status: number;
public routerHelper:RouterHelper = new RouterHelper();
public errorCodes:ErrorCodes = new ErrorCodes();
sub: any;
piwiksub: any;
properties:EnvProperties;
url=null;
@Input() zenodoInformation: ZenodoInformationClass;
constructor (private _router: Router,
private route: ActivatedRoute,
private _searchDataprovidersService: SearchDataprovidersService,
private _meta: Meta,
private _title: Title,
private _piwikService:PiwikService,
private seoService: SEOService) {
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
this.status = this.errorCodes.LOADING;
var description = "Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor;
var title = "Deposit "+this.requestFor;
this.updateTitle(title);
this.updateDescription(description);
this.seoService.createLinkForCanonicalURL(false);
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.updateUrl(data.envSpecific.baseLink+this._router.url);
this.zenodo = this.properties.zenodo;
this.url = 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();
}
if(!this.zenodoInformation.url) {
this.zenodoInformation.url = this.properties.zenodo;
}
if(!this.zenodoInformation.name) {
this.zenodoInformation.name = "Zenodo";
}
});
console.info('depositResult init');
this.sub = this.route.queryParams.subscribe(params => {
this.subject = params['subject'];
this.newSubject = this.subject;
this.searchDataproviders();
});
}
// ngDoCheck() {
// if(this.organizationId == "" || this.organizationId == undefined) {
// this.organizationId = "";
// this.status = this.errorCodes.ERROR;
// }
// }
ngOnDestroy() {
this.sub.unsubscribe();
if(this.piwiksub){
this.piwiksub.unsubscribe();
}
}
public totalPages(): number {
let totalPages:any = this.fetchDataproviders.searchUtils.totalResults/(this.fetchDataproviders.searchUtils.size);
if(!(Number.isInteger(totalPages))) {
totalPages = (parseInt(totalPages, 10) + 1);
}
return totalPages;
}
public searchDataproviders() {
this.subject = this.newSubject;
this.fetchDataproviders.getResultsBySubjectsForDeposit( (this.subject =="")?"*":this.subject, this.requestFor, this.page, 10, this.properties);
this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders;
}
public goToDeposit() {
if(this.requestFor == "Publications") {
this._router.navigate( ['participate/deposit-publications'] );
} else if(this.requestFor == "Research Data") {
this._router.navigate( ['participate/deposit-datasets'] );
}
}
public pageChange($event) {
this.page = +$event.value;
this.searchDataproviders();
}
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'");
}
}