59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
import {Http, Response} from '@angular/http';
|
|
import {Headers, RequestOptions} from '@angular/http';
|
|
import {Observable} from 'rxjs/Rx';
|
|
|
|
import {ZenodoCommunityInfo} from './zenodoCommunityInfo';
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
@Injectable()
|
|
export class ZenodoCommunitiesService {
|
|
|
|
constructor(private http:Http) {
|
|
}
|
|
|
|
getZenodoCommunities(properties:EnvProperties, url: string) {
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
|
.map(res => <any> res.json()).map(res => [this.parseZenodoCommunities(res.hits.hits),res.hits.total]);
|
|
}
|
|
getZenodoCommunityById(properties:EnvProperties, url: string, openaireId:string) {
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
|
.map(res => <any> res.json()).map(res => {
|
|
var community = this.parseZenodoCommunity(res);
|
|
community["openaireId"]=openaireId;
|
|
return community;
|
|
});
|
|
}
|
|
|
|
parseZenodoCommunities(data: any): ZenodoCommunityInfo[] {
|
|
let zenodoCommunities: ZenodoCommunityInfo[] = [];
|
|
|
|
for (let i=0; i<data.length; i++) {
|
|
let resData = data[i];
|
|
|
|
|
|
zenodoCommunities.push(this.parseZenodoCommunity(resData));
|
|
}
|
|
return zenodoCommunities;
|
|
}
|
|
|
|
parseZenodoCommunity(resData:any):ZenodoCommunityInfo {
|
|
var result: ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
|
|
|
result['title'] = resData.title;
|
|
result['id'] = resData.id;
|
|
result['description'] = resData.description;
|
|
result['link'] = resData.links.html;
|
|
result['logoUrl'] = resData.logo_url;
|
|
result['date'] = resData.updated;
|
|
result['page'] = resData.page;
|
|
return result;
|
|
|
|
}
|
|
|
|
getTotalZenodoCommunities(properties:EnvProperties, url: string) {
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
|
.map(res => <any> res.json()).map(res => res.hits.total);
|
|
}
|
|
}
|