2020-03-17 14:46:32 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2020-03-18 03:37:39 +01:00
|
|
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
2020-03-17 14:46:32 +01:00
|
|
|
import { CookieService } from './cookie.service';
|
|
|
|
|
2020-03-18 03:37:39 +01:00
|
|
|
import { Observable, of } from 'rxjs';
|
|
|
|
import { map, retry, catchError } from 'rxjs/operators';
|
2020-03-17 14:46:32 +01:00
|
|
|
|
|
|
|
import { environment } from '../environments/environment'
|
2020-03-18 03:37:39 +01:00
|
|
|
import { apiURL, apiRetry } from './api-utils'
|
2020-03-20 00:01:45 +01:00
|
|
|
import Folder from './folder'
|
2020-03-17 14:46:32 +01:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class DbStatusService {
|
2020-03-18 03:37:39 +01:00
|
|
|
private folderStatus: Object = {};
|
2020-03-19 00:39:01 +01:00
|
|
|
private headers: HttpHeaders;
|
2020-03-17 14:46:32 +01:00
|
|
|
private dbStatusUrl = environment.production ? apiURL + 'rest/db/status' : 'api/dbStatus';
|
|
|
|
|
|
|
|
constructor(private http: HttpClient, private cookieService: CookieService) {
|
2020-03-19 00:39:01 +01:00
|
|
|
this.headers = new HttpHeaders(this.cookieService.getCSRFHeader())
|
2020-03-17 14:46:32 +01:00
|
|
|
}
|
|
|
|
|
2020-03-20 00:01:45 +01:00
|
|
|
getFolderStatus(id: string): Observable<Folder.Status> {
|
2020-03-19 00:39:01 +01:00
|
|
|
let httpOptions: { headers: HttpHeaders } |
|
|
|
|
{ headers: HttpHeaders, params: HttpParams };
|
2020-03-18 03:37:39 +01:00
|
|
|
if (id) {
|
2020-03-19 00:39:01 +01:00
|
|
|
httpOptions = {
|
|
|
|
headers: this.headers,
|
|
|
|
params: new HttpParams().set('folder', id)
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
httpOptions = { headers: this.headers };
|
2020-03-18 03:37:39 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 14:46:32 +01:00
|
|
|
return this.http
|
2020-03-20 00:01:45 +01:00
|
|
|
.get<Folder.Status>(this.dbStatusUrl, httpOptions)
|
2020-03-18 03:37:39 +01:00
|
|
|
.pipe(
|
|
|
|
retry(apiRetry),
|
|
|
|
map(res => {
|
2020-03-19 00:39:01 +01:00
|
|
|
// Remove from array in developement
|
|
|
|
// in-memory-web-api returns arrays
|
|
|
|
if (!environment.production) {
|
2020-03-20 00:01:45 +01:00
|
|
|
console.log("status res!", res);
|
2020-03-19 00:39:01 +01:00
|
|
|
const a: any = res as any;
|
|
|
|
if (a.length > 0) {
|
|
|
|
return res[0];
|
|
|
|
}
|
2020-03-20 00:01:45 +01:00
|
|
|
return {};
|
2020-03-19 00:39:01 +01:00
|
|
|
}
|
2020-03-18 03:37:39 +01:00
|
|
|
return res;
|
|
|
|
})
|
2020-03-17 14:46:32 +01:00
|
|
|
);
|
|
|
|
}
|
2020-03-18 03:37:39 +01:00
|
|
|
}
|