import {Component, Input} from '@angular/core'; import {Router, ActivatedRoute} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; import {Observable} from 'rxjs'; import {ErrorCodes} from '../utils/properties/errorCodes'; import{EnvProperties} from '../utils/properties/env-properties'; import {RouterHelper} from '../utils/routerHelper.class'; import {FetchDataproviders} from '../utils/fetchEntitiesClasses/fetchDataproviders.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-result', template: `
Share {{requestFor}}

{{organization['name']}} {{organization['name']}}

Keywords: {{subject}}

Please use the information below and contact your repository to deposit your {{requestFor}}.

[no title available]

[no title available]

{{result['type']}} {{result.compatibility}}
Organization: {{organization.name}} {{organization.name}}, ...
Country: {{country}}{{(i < ( result['countries'].slice(0,10).length-1))?", ":""}}{{(i == result['countries'].slice(0,10).length-1 && result['countries'].length > 10)?"...":""}}
Subject: {{subject}}{{(i < ( result['subjects'].slice(0,10).length-1))?", ":""}}{{(i == result['subjects'].slice(0,10).length-1 && result['subjects'].length > 10)?"...":""}}
No organization with ID: {{organizationId}} found.
An error occured.
Service temprorarily unavailable. Please try again later.
No ID for organization.
An error occured. Service temprorarily unavailable. Please try again later. Requested page out of bounds.
No content providers found for institution: {{organization['name']}} () {{organization['name']}} .
No content providers found with classification "{{subject}}".
` }) export class DepositResultComponent { @Input() zenodoInformation: ZenodoInformationClass; @Input() compatibility: string = ''; @Input() piwikSiteId = null; // Type of entity: Publication or Research Data @Input() requestFor: string = "Publications"; public organization: {"name": string, "url": string}; public organizationId: string = ""; // Id of the new selected organization to be searched public selectedId: string = ""; @Input() subjectResults: boolean = false; @Input() subject: string = ""; public status: number; public warningMessage: string = ""; public fetchDataproviders : FetchDataproviders; public linkToSearchDataproviders: string = ""; public parameterNames:string[] =[]; public parameterValues:string[] =[]; public routerHelper:RouterHelper = new RouterHelper(); public errorCodes:ErrorCodes = new ErrorCodes(); sub: any; piwiksub: any; properties:EnvProperties; url=null; constructor ( private _router: Router, private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService, private _organizationService: OrganizationService, private _meta: Meta, private _title: Title, private _piwikService:PiwikService, private seoService: SEOService) { this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService); this.status = this.errorCodes.LOADING; 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.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false); this.updateUrl(data.envSpecific.baseLink+this._router.url); 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(); } }); this.sub = this.route.queryParams.subscribe(params => { this.fetchDataproviders.searchUtils.page = (params['page']=== undefined)?1:+params['page']; if(this.subjectResults) { this.status = this.errorCodes.DONE; this.subject = params['subject']; if(!this.subject) { this.subject = ""; } this.parameterNames.push('subject'); this.parameterValues.push(this.subject); this.searchDataprovidersBySubject(); } else { if(this.organizationId) { this.searchDataproviders(); } else { this.organizationId = params['organizationId']; this.parameterNames.push('organizationId'); this.parameterValues.push(this.organizationId); if(this.organizationId){ this.getOrganizationInfo(); } } this.selectedId = ""; } }); } ngDoCheck() { if(!this.subjectResults && (this.organizationId == "" || this.organizationId == undefined)) { this.organizationId = ""; this.status = this.errorCodes.NONE; this.fetchDataproviders.searchUtils.status = this.errorCodes.NONE; } } ngOnDestroy() { this.sub.unsubscribe(); if(this.piwiksub){ this.piwiksub.unsubscribe(); } } public newSubject() { this._router.navigate( ['participate/deposit-subject-result'], { queryParams: { "subject": this.subject } } ); } public searchDataprovidersBySubject() { this.parameterNames = []; this.parameterValues = []; this.parameterNames.push('subject'); this.parameterValues.push(this.subject); this.fetchDataproviders.getResultsBySubjectsForDeposit( (this.subject =="")?"*":this.subject, this.requestFor, this.fetchDataproviders.searchUtils.page, this.fetchDataproviders.searchUtils.size, this.properties); this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders; } private searchDataproviders() { // if(this.organization != undefined) { // this.fetchDataproviders.getResults(this.organization.name, false, 1, 10); // } else if(this.organizationId != undefined) { this.fetchDataproviders.getResultsForDeposit( this.organizationId,this.requestFor, this.fetchDataproviders.searchUtils.page, this.fetchDataproviders.searchUtils.size, this.properties); //} this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders; } private getOrganizationInfo () { this.fetchDataproviders.oldTotalResults = 0; this.fetchDataproviders.searchUtils.totalResults = 0; this._organizationService.getOrganizationNameAndUrlById(this.organizationId,this.properties).subscribe( data => { if(data == null) { this.status = this.errorCodes.NOT_FOUND; this.fetchDataproviders.searchUtils.status = this.errorCodes.NONE; } else { this.organization = data; this.status = this.errorCodes.DONE; this.searchDataproviders(); } }, err => { //console.log(err) this.handleError("Error getting organization name and url for id: "+this.organizationId, err); this.fetchDataproviders.searchUtils.status = this.errorCodes.NONE; if(err.status == '404') { this.status = this.errorCodes.NOT_FOUND; } else if(err.status == '500') { this.status = this.errorCodes.ERROR; } else { this.status = this.errorCodes.NOT_AVAILABLE; } } ); } 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 valueChanged($event){ this.selectedId = $event.value; } public organizationSelected(id: string) { if(id && id.length > 0 && id != this.organizationId){ this.organization = null; this.status = this.errorCodes.LOADING; 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 new organization selected"; } } 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'"); } private handleError(message: string, error) { console.error("Deposit Result Page: "+message, error); } }