Project

General

Profile

1
import {Injectable} from '@angular/core';
2
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
3
import {HttpClient, HttpHeaders} from '@angular/common/http';
4

    
5
@Injectable()
6
export class ManageCommunityProjectsService {
7
  constructor(private http: HttpClient ) {}
8

    
9
  removeProject (properties:EnvProperties, pid: string, id: string):any {
10
    //let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'});
11
    //let options = new RequestOptions({headers: headers, body: id});
12

    
13
    let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'});
14

    
15
    let url = properties.communityAPI+pid+"/projects";
16
    //return this.http.delete(url, options)
17
    return this.http.request('delete', url, { body: id, headers: headers})
18
  }
19

    
20
  addProject(properties:EnvProperties, pid: string, project: any) {
21
      //let headers = new Headers({'Content-Type': 'application/json'});
22
      //let options = new RequestOptions({headers: headers});
23

    
24
    let headers = new HttpHeaders({'Content-Type': 'application/json'});
25

    
26
    let url = properties.communityAPI+pid+"/projects";
27

    
28
      let communityProject = this.convertSearchProjectToCommunityProject(project, pid);
29
      let testProject: any = {
30
        "acronym": "test",
31
        "communityId": "egi",
32
        "funder": "test",
33
        "grantId": "test",
34
        "name": "test",
35
        "openaireId": "test"
36
      };
37

    
38
      return this.http.post<any>(url, JSON.stringify(communityProject), {headers: headers});
39
      //return this.http.post(url, JSON.stringify(communityProject), options)
40
                      //.map(res => <any> res.json())
41
    }
42

    
43
  convertSearchProjectToCommunityProject(project: any, community: string) : any {
44
    let communityProject = {
45
            "acronym": "",
46
            "communityId": community,
47
            "funder": "",
48
            "grantId": "",
49
            "name": "",
50
            "openaireId": ""
51
    }
52

    
53
    communityProject.acronym = project.acronym;
54
    communityProject.name = project.title.name;
55
    communityProject.funder = project.funderShortname;
56
    communityProject.grantId = project.code;
57
    communityProject.openaireId = project.id;
58

    
59
    return communityProject;
60
  }
61

    
62
}
(3-3/4)