Project

General

Profile

1
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
    let options = new RequestOptions({headers: headers, body: id});
17

    
18
    let url = properties.communityAPI+communityId+"/projects";
19
    return this.http.delete(url, options)
20
  }
21

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

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

    
28
      let communityProject = this.convertSearchProjectToCommunityProject(project, communityId);
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(url, JSON.stringify(communityProject), options)
39
                      .map(res => <any> res.json())
40
    }
41

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

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

    
58
    return communityProject;
59
  }
60

    
61
}
(4-4/5)