88 lines
3.4 KiB
TypeScript
88 lines
3.4 KiB
TypeScript
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: `
|
|
<div *ngIf="pluginObject">
|
|
<h3>{{pluginObject.title}} </h3>
|
|
|
|
<div *ngIf="services" uk-slider class="uk-slider">
|
|
<ul *ngIf="slides" class="uk-slider-items" uk-height-match="target: .uk-card; row: false">
|
|
<li *ngFor="let slide of [].constructor(slides); let i=index" class="uk-width-1-1 uk-padding">
|
|
<div class="uk-grid uk-child-width-1-3@m uk-child-width-1-1" uk-grid uk-scrollspy="target: [uk-scrollspy-class]; cls: uk-animation-fade; repeat: true">
|
|
<div *ngFor="let service of servicesToShow.slice((i)*slideItems,(i+1)*slideItems)" uk-scrollspy-class>
|
|
<div class="uk-card uk-card-default ">
|
|
<div class="uk-card-media-top">
|
|
<img [src]="service.logo" width="100%" height="" alt="" class="uk-height-max-small">
|
|
</div>
|
|
<div class=" uk-height-max-large uk-padding-small">
|
|
<div class="uk-text-primary">{{service.name}}</div>
|
|
<div class="uk-h5 uk-margin-remove-vertical">{{service.tagline}}</div>
|
|
<div [innerHTML]="service.description" class="uk-text-truncate uk-text-small uk-text-meta"></div>
|
|
<a class="uk-link-text" [href]="service.webpage" target="_blank">Read more</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
<ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin-medium-top"></ul>
|
|
</div>
|
|
</div>
|
|
|
|
`,
|
|
|
|
|
|
})
|
|
export class PluginOpenaireProductsComponent extends PluginBaseComponent<PluginOpenAIREProducts>{
|
|
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++;
|
|
}
|
|
}
|
|
}
|
|
}
|