1 |
51316
|
konstantin
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {Http, Response, Headers, RequestOptions} from '@angular/http';
|
3 |
|
|
import {Observable} from 'rxjs/Observable';
|
4 |
|
|
import{EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
5 |
|
|
|
6 |
|
|
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
7 |
|
|
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
|
8 |
|
|
import { catchError } from 'rxjs/operators';
|
9 |
|
|
|
10 |
|
|
@Injectable()
|
11 |
|
|
export class ManageCommunityProjectsService {
|
12 |
|
|
constructor(private http: Http ) {}
|
13 |
|
|
|
14 |
|
|
removeProject (properties:EnvProperties, communityId: string, id: string):any {
|
15 |
|
|
let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'});
|
16 |
51417
|
konstantin
|
let options = new RequestOptions({headers: headers, body: id});
|
17 |
51316
|
konstantin
|
|
18 |
|
|
let url = properties.communityAPI+communityId+"/projects";
|
19 |
|
|
console.info(url);
|
20 |
|
|
|
21 |
|
|
return this.http.delete(url, options)
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
addProject(properties:EnvProperties, communityId: string, project: any) {
|
25 |
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
26 |
|
|
let options = new RequestOptions({headers: headers});
|
27 |
|
|
|
28 |
|
|
let url = properties.communityAPI+communityId+"/projects";
|
29 |
|
|
console.info(url);
|
30 |
|
|
|
31 |
|
|
let communityProject = this.convertSearchProjectToCommunityProject(project, communityId);
|
32 |
|
|
console.info(project);
|
33 |
|
|
console.info(communityProject);
|
34 |
|
|
let testProject: any = {
|
35 |
|
|
"acronym": "test",
|
36 |
|
|
"communityId": "egi",
|
37 |
|
|
"funder": "test",
|
38 |
|
|
"grantId": "test",
|
39 |
|
|
"name": "test",
|
40 |
|
|
"openaireId": "test"
|
41 |
|
|
};
|
42 |
|
|
|
43 |
|
|
return this.http.post(url, JSON.stringify(communityProject), options)
|
44 |
|
|
.map(res => <any> res.json())
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
convertSearchProjectToCommunityProject(project: any, community: string) : any {
|
48 |
|
|
let communityProject = {
|
49 |
|
|
"acronym": "",
|
50 |
|
|
"communityId": community,
|
51 |
|
|
"funder": "",
|
52 |
|
|
"grantId": "",
|
53 |
|
|
"name": "",
|
54 |
|
|
"openaireId": ""
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
communityProject.acronym = project.acronym;
|
58 |
|
|
communityProject.name = project.title.name;
|
59 |
|
|
communityProject.funder = project.funderShortname;
|
60 |
|
|
communityProject.grantId = project.code;
|
61 |
|
|
communityProject.openaireId = project.id;
|
62 |
|
|
|
63 |
|
|
return communityProject;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
}
|