Move getCommunity to Community folder and rename parseCommunities to searchCommunity
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@50965 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
2faf70e764
commit
803dd44a68
|
@ -14,10 +14,6 @@ export class CommunitiesService {
|
|||
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseResults(res));
|
||||
}
|
||||
|
||||
getCommunity(id:string , url: string) {
|
||||
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunities(id,res));
|
||||
}
|
||||
|
||||
parseResults(data: any): CommunityInfo[] {
|
||||
let communities: CommunityInfo[] = [];
|
||||
|
||||
|
@ -49,46 +45,4 @@ export class CommunitiesService {
|
|||
return communities;
|
||||
}
|
||||
|
||||
|
||||
parseCommunities(id:string, data:any): CommunityInfo[] {
|
||||
let community: CommunityInfo[] = [];
|
||||
|
||||
let notFound:boolean = true;
|
||||
|
||||
let length = Array.isArray(data) ? data.length :1;
|
||||
|
||||
for (let i=0; i<length && notFound; i++) {
|
||||
|
||||
let resData = Array.isArray(data) ? data[i] : data;
|
||||
|
||||
var result: CommunityInfo = new CommunityInfo();
|
||||
|
||||
if(Array.isArray(resData) && id == resData[0].id) {
|
||||
|
||||
notFound = false;
|
||||
|
||||
result['title'] = resData[0].name;
|
||||
result['shortTitle'] = resData[0].shortName;
|
||||
result['communityId'] = resData[0].id;
|
||||
result['queryId'] = resData[0].queryId;
|
||||
result['logoUrl'] = resData[0].logoUrl;
|
||||
result['description'] = resData[0].description;
|
||||
|
||||
} else if(!Array.isArray(resData) && id == resData.id) {
|
||||
|
||||
notFound = false;
|
||||
|
||||
result['title'] = resData.name;
|
||||
result['shortTitle'] = resData.shortName;
|
||||
result['communityId'] = resData.id;
|
||||
result['queryId'] = resData.queryId;
|
||||
result['logoUrl'] = resData.logoUrl;
|
||||
result['description'] = resData.description;
|
||||
}
|
||||
community.push(result);
|
||||
}
|
||||
|
||||
return community;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ export class CommunityComponent {
|
|||
//console.log(communityId);
|
||||
});
|
||||
|
||||
this._communitiesService.getCommunity(this.communityId,'https://dev-openaire.d4science.org/openaire/community/communities').subscribe (
|
||||
this._communityService.getCommunity(this.communityId,'https://dev-openaire.d4science.org/openaire/community/communities').subscribe (
|
||||
communityInfo => {
|
||||
this.communityInfo = communityInfo;
|
||||
console.log(communityInfo);
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Http, Response, Headers, RequestOptions } from '@angular/http';
|
|||
import { Observable } from 'rxjs/Rx';
|
||||
|
||||
import { ResultInfo } from './results/resultInfo';
|
||||
import { CommunityInfo } from '../utils/communityInfo';
|
||||
|
||||
@Injectable()
|
||||
export class CommunityService {
|
||||
|
@ -94,4 +95,49 @@ export class CommunityService {
|
|||
return results;
|
||||
}
|
||||
|
||||
getCommunity(id:string , url: string) {
|
||||
return this.http.get(url).map(res => <any> res.json()).map(res => this.searchCommunity(id,res));
|
||||
}
|
||||
|
||||
searchCommunity(id:string, data:any): CommunityInfo[] {
|
||||
let community: CommunityInfo[] = [];
|
||||
|
||||
let notFound:boolean = true;
|
||||
|
||||
let length = Array.isArray(data) ? data.length :1;
|
||||
|
||||
for (let i=0; i<length && notFound; i++) {
|
||||
|
||||
let resData = Array.isArray(data) ? data[i] : data;
|
||||
|
||||
var result: CommunityInfo = new CommunityInfo();
|
||||
|
||||
if(Array.isArray(resData) && id == resData[0].id) {
|
||||
|
||||
notFound = false;
|
||||
|
||||
result['title'] = resData[0].name;
|
||||
result['shortTitle'] = resData[0].shortName;
|
||||
result['communityId'] = resData[0].id;
|
||||
result['queryId'] = resData[0].queryId;
|
||||
result['logoUrl'] = resData[0].logoUrl;
|
||||
result['description'] = resData[0].description;
|
||||
|
||||
} else if(!Array.isArray(resData) && id == resData.id) {
|
||||
|
||||
notFound = false;
|
||||
|
||||
result['title'] = resData.name;
|
||||
result['shortTitle'] = resData.shortName;
|
||||
result['communityId'] = resData.id;
|
||||
result['queryId'] = resData.queryId;
|
||||
result['logoUrl'] = resData.logoUrl;
|
||||
result['description'] = resData.description;
|
||||
}
|
||||
community.push(result);
|
||||
}
|
||||
return community;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue