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

128 lines
4.3 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { FetchDataproviders } from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
import { SearchDataprovidersService } from '../../services/searchDataproviders.service';
import {OrganizationService} from '../../services/organization.service';
import { Meta} from '../../../angular2-meta';
import {RouterHelper} from '../../utils/routerHelper.class';
import {PiwikService} from '../../utils/piwik/piwik.service';
@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 = "";
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;
constructor ( private _router: Router,
private route: ActivatedRoute,
private _searchDataprovidersService: SearchDataprovidersService,
private _meta: Meta, private _piwikService:PiwikService) {
this.zenodo = OpenaireProperties.getZenodoURL();
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
this.status = this.errorCodes.LOADING;
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();
}
}
ngOnInit() {
console.info('depositResult init');
this.sub = this.route.queryParams.subscribe(params => {
this.subject = params['q'];
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.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders();
}
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.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);
}
}