2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Http, Response} from '@angular/http';
|
|
|
|
import {Jsonp, URLSearchParams,ResponseOptions, RequestOptions, Headers} from '@angular/http';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import 'rxjs/add/operator/do';
|
|
|
|
|
|
|
|
import { CustomOptions } from '../claim-utils/service/customOptions.class';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ClaimsByTokenService {
|
|
|
|
|
|
|
|
constructor(private http: Http ) {}
|
|
|
|
|
2018-09-24 12:01:05 +02:00
|
|
|
getClaims(openaireId: string, apiURL:string):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
console.info("getClaims in service");
|
|
|
|
|
2018-09-24 12:01:05 +02:00
|
|
|
//let url = apiURL+"project/claims?projectToken="+token;
|
|
|
|
let url = apiURL+"projects/"+openaireId+"/all_claims";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
let key = url;
|
|
|
|
|
|
|
|
return this.http.get(url, CustomOptions.getAuthOptions())
|
|
|
|
//.map(res => <any> res.text())
|
|
|
|
.map(request => <any> request.json());
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
getClaims(email: string, token: string, user_token: string):any {
|
|
|
|
let url = OpenaireProperties.getClaimsAPIURL(); // What else?
|
|
|
|
let body = JSON.stringify( {"email": email, "token": token} );
|
|
|
|
console.warn('Json body: : '+body);
|
|
|
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
|
|
|
let options = new RequestOptions({ headers: headers });
|
|
|
|
return this.http.post(url, body, options)
|
|
|
|
.map(res => res.json())
|
|
|
|
.do(request => console.info("Insert Response:"+request.status) )
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
updateClaimsCuration( selectedRight: Set<string>, selectedWrong: Set<string>, apiURL:string) {
|
|
|
|
let url = apiURL + "curate/bulk";
|
2017-12-19 13:53:46 +01:00
|
|
|
let claimsCurationInfo: any = []; //e.g.: [{"id":"2","approved":true},{"id":"1","approved":true}]
|
|
|
|
|
|
|
|
selectedRight.forEach(function(selected) {
|
2018-06-29 15:24:49 +02:00
|
|
|
//console.info(selected);
|
2017-12-19 13:53:46 +01:00
|
|
|
let claimCurationInfo: {"id": string, "approved": boolean} = {"id": selected, "approved": true};
|
|
|
|
claimsCurationInfo.push(claimCurationInfo);
|
|
|
|
});
|
|
|
|
|
|
|
|
selectedWrong.forEach(function(selected) {
|
|
|
|
let claimCurationInfo: any = {"id": selected, "approved": false};
|
|
|
|
claimsCurationInfo.push(claimCurationInfo);
|
|
|
|
});
|
|
|
|
|
2018-06-29 15:24:49 +02:00
|
|
|
console.info(claimsCurationInfo);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
let body = JSON.stringify( claimsCurationInfo );
|
|
|
|
console.warn('Json body: : '+body);
|
|
|
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
|
|
|
let options = new RequestOptions({ headers: headers });
|
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
|
|
|
.map(res => res.json())
|
|
|
|
.do(request => console.info("Insert Response:"+request.status) )
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-06-29 15:24:49 +02:00
|
|
|
|
|
|
|
updateClaimCuration( claimCurationInfo: {"id": string, "approved": boolean}, apiURL:string) {
|
|
|
|
let url = apiURL + "curate/bulk";
|
|
|
|
let claimsCurationInfo: any = []; //e.g.: [{"id":"2","approved":true},{"id":"1","approved":true}]
|
|
|
|
claimsCurationInfo.push(claimCurationInfo);
|
|
|
|
|
|
|
|
console.info(claimsCurationInfo);
|
|
|
|
|
|
|
|
let body = JSON.stringify( claimsCurationInfo );
|
|
|
|
console.warn('Json body: : '+body);
|
|
|
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
|
|
|
let options = new RequestOptions({ headers: headers });
|
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
|
|
|
.map(res => res.json())
|
|
|
|
.do(request => console.info("Insert Response:"+request.status) )
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
private handleError (error: Response) {
|
|
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
|
|
|
// instead of just logging it to the console
|
|
|
|
console.log(error);
|
|
|
|
return Observable.throw(error || 'Server error');
|
|
|
|
}
|
|
|
|
}
|