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}}
-
{{service.name}}
{{service.tagline}}
Read more
`,
})
export class PluginOpenaireProductsComponent extends PluginBaseComponent{
services = null;
excludedServiceIds = ["openaire_login","research_community_dashboard"]
servicesToShow = [];
slides = 1;
slideItems = 3;
constructor(private http:HttpClient) {
super()
}
ngOnInit(): void {
super.ngOnInit();
if(!this.services) {
this.subscriptions.push(this.http.get("https://explore.openaire.eu/cache/get?url="+ encodeURIComponent("https://catalogue.openaire.eu/api/catalogue-resources?from=0&quantity=100&order=asc&orderField=name")).subscribe(res =>{
this.services = res["results"].map( x=> {
x.id = x.id.split("openaire.")[1]
return x;
});
this.services = this.services.filter(x=> this.excludedServiceIds.indexOf(x.id) ==-1);
this.calculatePages();
}))
}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++;
}
}
}
}