data.service.ts 1.28 KB
Newer Older
Laura Morel's avatar
Laura Morel committed
1
2
3
4
5
6
7
8
9
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class DataService {

Laura Morel's avatar
Laura Morel committed
10
  private baseURL = 'http://127.0.0.1:8000';
Laura Morel's avatar
Laura Morel committed
11
12
13
14
15
16
17
18
19
20
21
22
23

  constructor(private http: HttpClient) { }

  get_img(species, size): Observable<any> {
    const sp = species.replace(" ", "_");
    const imgurl: string = `${this.baseURL}/${sp}/img/${size}`;
    console.log("Fetching image at ", imgurl);
    const options = {responseType: 'blob' as 'blob'};
    const result = this.http.get(imgurl, { responseType:'text' as 'text'});
    console.log(result)
    return result;
  }

Laura Morel's avatar
Laura Morel committed
24
  filter_highlight(data: Object): Observable<Blob> {
Laura Morel's avatar
Laura Morel committed
25
26
//    const sp = data['species'].replace(" ", "_");
    let url: string = `${this.baseURL}/api/img`;
Laura Morel's avatar
Laura Morel committed
27
    console.log(data);
Laura Morel's avatar
Laura Morel committed
28
    url = url + `?q=${JSON.stringify(data)}`;
Laura Morel's avatar
Laura Morel committed
29
30
31
    console.log("Fetching image at ", url);
//    return url;
    return this.http.get(`${url}`, {responseType: 'blob', reportProgress: true});
Laura Morel's avatar
Laura Morel committed
32
33
34
35
36
37
  }

  get_fields(data: Object): Observable<Object> {
    let url = `${this.baseURL}/api/fields`;
    url = url + `?q=${JSON.stringify(data)}`;
    console.log("Fetching metadata at ", url);
Laura Morel's avatar
Laura Morel committed
38
    return this.http.get(url, {responseType: 'json'})
Laura Morel's avatar
Laura Morel committed
39
40
  }
}