image.service.ts
2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { Injectable } from '@angular/core';
import { Http, Response, Headers, URLSearchParams } from '@angular/http';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
declare var jQuery: any;
@Injectable()
export class ImageService {
constructor(private http: Http) {
}
public getRemianingFilesData(filePath: string): Observable<any> {
return this.http.get(filePath).map(this.getData).catch(this.handleError);
}
public getBodyViewData(index: number): Observable<any> {
console.log("getBodyViewData.index :" + index);
return this.http.get('../assets/data/json/da/body-views/' + index + '/da_dat_layer_' + index + '.json');
}
public updateImageData(imageData: any): Observable<any> {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('bodyViewIndex', imageData.bodyViewIndex);
headers.append('layerNumber', imageData.layerNumber);
headers.append('bodyRegion', imageData.bodyRegion);
let payload: string = JSON.stringify(imageData);
console.log('inside updateImageData.JSON.stringify(imageData)= ' + payload);
return this.http.post('/API/api/ProcessImage', payload, { headers: headers })
.map(this.extractData)
.catch(this.handleError);
}
//public updateImageData(imageData: any): any {
// const headers = new Headers();
// headers.append('Content-Type', 'application/json');
// let payload: string = JSON.stringify(imageData);
// console.log('inside updateImageData.JSON.stringify(imageData)= ' + payload);
// //return this.http.post('/API/api/ProcessImage', payload, { headers: headers })
// // .map(this.extractData)
// // .catch(this.handleError);
// jQuery.ajax({
// headers: {
// 'Accept': 'application/json',
// 'Content-Type': 'application/json'
// },
// url: '/API/api/ProcessImage/Post',
// type: 'POST',
// data: { "value": payload },
// success: function (result) {
// return result;
// }
// });
//}
private getData(res:Response){
const body = res.json();
console.log("inside getData.body: "+body)
return body || {};
}
private extractData(res: Response) {
const body = res.json();
return body || {};
}
private handleError(error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
let errMsg: string;
if (error instanceof Response) {
const body = error.json() || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
}
}