74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Http, Response, Headers, RequestOptions } from '@angular/http';
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
import { CommunityInfo } from './communityInfo';
|
|
|
|
@Injectable()
|
|
export class CommunitiesService {
|
|
|
|
constructor(private http:Http) {
|
|
}
|
|
|
|
getResults(url: string) {
|
|
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseResults(res));
|
|
}
|
|
|
|
// this is for https://dev-openaire.d4science.org/openaire/community/communities
|
|
// parseResults(data: any): CommunityInfo[] {
|
|
// let communities: CommunityInfo[] = [];
|
|
//
|
|
// let length = Array.isArray(data) ? data.length :1;
|
|
//
|
|
// for (let i=0; i<length; i++) {
|
|
// let resData = Array.isArray(data) ? data[i] : data;
|
|
//
|
|
// var result: CommunityInfo = new CommunityInfo();
|
|
//
|
|
// if(Array.isArray(resData)) {
|
|
// result['title'] = resData[0].name;
|
|
// result['logoUrl'] = resData[0].logoUrl;
|
|
// result['description'] = resData[0].description;
|
|
// } else {
|
|
// result['title'] = resData.name;
|
|
// result['logoUrl'] = resData.logoUrl;
|
|
// result['description'] = resData.description;
|
|
// }
|
|
// communities.push(result);
|
|
// }
|
|
//
|
|
// return communities;
|
|
// }
|
|
|
|
//this is for http://rudie.di.uoa.gr:8080/uoa-admin-tools/mock/communities/
|
|
parseResults(data: any): CommunityInfo[] {
|
|
let communities: CommunityInfo[] = [];
|
|
|
|
let length = Array.isArray(data) ? data.length :1;
|
|
|
|
for (let i=0; i<length; i++) {
|
|
let resData = Array.isArray(data) ? data[i] : data;
|
|
|
|
var result: CommunityInfo = new CommunityInfo();
|
|
|
|
if(Array.isArray(resData)) {
|
|
result['title'] = resData[0].name;
|
|
result['shortTitle'] = resData[0].shortName;
|
|
result['communityId'] = resData[0].communityId;
|
|
result['logoUrl'] = resData[0].logo;
|
|
result['description'] = resData[0].description;
|
|
} else {
|
|
result['title'] = resData.name;
|
|
result['shortTitle'] = resData.shortName;
|
|
result['communityId'] = resData.communityId;
|
|
result['logoUrl'] = resData.logo;
|
|
result['description'] = resData.description;
|
|
}
|
|
communities.push(result);
|
|
}
|
|
|
|
return communities;
|
|
}
|
|
|
|
}
|