import {Component, SimpleChanges} from '@angular/core'; import {PluginBaseComponent, PluginBaseInfo} from "../../utils/base-plugin.component"; import {HttpClient} from "@angular/common/http"; export class PluginOpenAIREProducts extends PluginBaseInfo{ title:string ="OpenAIRE services for your community"; serviceIdsArray = ["argos","zenodo","amnesia"]; compare(oldObject): any { return super.compare(oldObject); } } @Component({ selector: 'plugin-openaire-products', template: `

{{pluginObject.title}}

No products info available
`, }) export class PluginOpenaireProductsComponent extends PluginBaseComponent{ services = null; excludedServiceIds = ["openaire_login","research_community_dashboard"] servicesToShow = null; slides = 1; slideItems = 3; api= "https://catalogue.openaire.eu/api/catalogue-resources?from=0&quantity=100&order=asc&orderField=name"; showErrorMessage = false; constructor(private http:HttpClient) { super() } ngOnInit(): void { super.ngOnInit(); if(!this.services) { this.subscriptions.push(this.http.get( this.properties.cacheUrl + encodeURIComponent(this.api)).subscribe(res =>{ this.services = res["results"].map( x=> { if(x.id.indexOf("openaire.")!=-1){ x.id = x.id.split("openaire.")[1] } return x; }); this.services = this.services.filter(x=> this.excludedServiceIds.indexOf(x.id) ==-1); this.calculatePages(); }, error => { this.showErrorMessage = true; })) }else{ this.calculatePages(); } } ngOnChanges(changes: SimpleChanges) { if(this.services) { this.calculatePages(); } } calculatePages(){ this.slides = 1; this.servicesToShow = this.services.filter(x => this.pluginObject.serviceIdsArray.indexOf(x.id) != -1); if (this.servicesToShow.length > this.slideItems) { this.slides = parseInt('' + (this.servicesToShow.length / this.slideItems)); if(this.slides< (this.servicesToShow.length / this.slideItems)){ this.slides++; } } } }