diff --git a/src/app/_services/data.service.ts b/src/app/_services/data.service.ts index 6f75da0..80bbc73 100644 --- a/src/app/_services/data.service.ts +++ b/src/app/_services/data.service.ts @@ -3,18 +3,20 @@ import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http' import { Observable } from 'rxjs' import { map } from 'rxjs/operators' -export class MeasuresItem { - constructor( - public $uri: string, - public caption: string, - ) {} - get id(): string { - return this.$uri.substr(this.$uri.lastIndexOf('/') + 1) - } - get name(): string { - return this.caption || this.id - } -} +import { ApiService, DataProvider, MeasuresItem } from '../openapi' + +// export class MeasuresItem { +// constructor( +// public $uri: string, +// public caption: string, +// ) {} +// get id(): string { +// return this.$uri.substr(this.$uri.lastIndexOf('/') + 1) +// } +// get name(): string { +// return this.caption || this.id +// } +// } export class MeasuresItemsList { constructor( @@ -25,18 +27,16 @@ export class MeasuresItemsList { @Injectable() export class DataService { - constructor(private _http: HttpClient){ } + constructor( + public api: ApiService, + ) {} - getResources(): Observable<Object[]> { - return this._http.get<Object[]>('/api/list') + getResources(): Observable<DataProvider[]> { + return this.api.listDataProvidersApiDataProvidersGet() } getList(store: string): Observable<MeasuresItem[]> { - return this._http.get<MeasuresItem[]>('/api/' + store).pipe( - map(res => res.map( - item => new MeasuresItem(item['$uri'], item['caption']) - )) - ) + return this.api.getModelListApiDataProviderStoreGet({store: store}) } getValues( @@ -55,18 +55,17 @@ export class DataService { p['time'] = {"$between": [rangeFrom, rangeTo]} } s['time'] = false - let params = new HttpParams() - .set('where', JSON.stringify(p)) - .set('sort', JSON.stringify(s)) - .set('resample', sampling) - .set('format', format) + // let params = new HttpParams() + // .set('where', JSON.stringify(p)) + // .set('sort', JSON.stringify(s)) + // .set('resample', sampling) + // .set('format', format) // FIXME: add the name of the value to fetch - return this._http.get<Object>( - '/api/' + store + '/values/' + value, - { - params: params, - observe: 'response' - } - ) + return this.api.getModelValuesApiStoreNameValuesValueGet({ + storeName: store, + value: value, + where: JSON.stringify(p), + resample: sampling + }) } } diff --git a/src/app/measures/measures-list/measures-home.component.ts b/src/app/measures/measures-list/measures-home.component.ts index c058e11..ced14aa 100644 --- a/src/app/measures/measures-list/measures-home.component.ts +++ b/src/app/measures/measures-list/measures-home.component.ts @@ -12,9 +12,12 @@ export class MeasuresHomeComponent implements OnInit { private router: Router ) {} ngOnInit() { - const defaultStore = this.configService.conf['measures']['defaultStore'] - if (defaultStore) { - this.router.navigate(['/measures', defaultStore]) - } + this.configService.conf.subscribe( + conf => { + if (conf.measures) { + this.router.navigate(['/measures', conf.measures['defaultStore']]) + } + } + ) } } \ No newline at end of file diff --git a/src/app/measures/measures-list/measures-list-resolver.service.ts b/src/app/measures/measures-list/measures-list-resolver.service.ts index e252b64..c1f19ea 100644 --- a/src/app/measures/measures-list/measures-list-resolver.service.ts +++ b/src/app/measures/measures-list/measures-list-resolver.service.ts @@ -3,7 +3,8 @@ import { Router, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/ro import { Observable, of, EMPTY, forkJoin } from 'rxjs' import { map, mergeMap, take, first } from 'rxjs/operators' -import { DataService, MeasuresItem } from '../../_services/data.service' +import { DataService } from '../../_services/data.service' +import { MeasuresItem } from '../../openapi' @Injectable() export class MeasuresListResolver { diff --git a/src/app/measures/measures-list/measures-list.component.ts b/src/app/measures/measures-list/measures-list.component.ts index 26a2c20..632f073 100644 --- a/src/app/measures/measures-list/measures-list.component.ts +++ b/src/app/measures/measures-list/measures-list.component.ts @@ -5,8 +5,9 @@ import { ActivatedRoute, Router, ParamMap } from '@angular/router' import { Observable, of } from 'rxjs' import { map, startWith, switchMap } from 'rxjs/operators' -import { MeasuresItem, DataService } from '../../_services/data.service' +import { DataService } from '../../_services/data.service' import { ConfigService } from '../../config.service' +import { MeasuresItem, DataProvider } from '../../openapi' @Component({ selector: 'gisaf-measures-list', diff --git a/src/app/measures/measures.component.html b/src/app/measures/measures.component.html index baf0a41..4cf397f 100644 --- a/src/app/measures/measures.component.html +++ b/src/app/measures/measures.component.html @@ -2,10 +2,10 @@ <mat-drawer opened=true mode='side'> <mat-list-item *ngFor="let store of stores"> <button mat-button - matTooltip="{{ store['name'] }}" + matTooltip="{{ store.name }}" matTooltipPosition="right" - [routerLink]="store['store']" routerLinkActive="active"> - {{ store['name'] }} + [routerLink]="store.store" routerLinkActive="active"> + {{ store.name }} </button> </mat-list-item> </mat-drawer> diff --git a/src/app/measures/measures.component.ts b/src/app/measures/measures.component.ts index 447217e..3f55136 100644 --- a/src/app/measures/measures.component.ts +++ b/src/app/measures/measures.component.ts @@ -7,6 +7,7 @@ import { Observable, of } from 'rxjs' import { DataService } from '../_services/data.service' import { ConfigService } from '../config.service' +import { DataProvider } from '../openapi' @Component({ selector: 'gisaf-measures', @@ -15,7 +16,7 @@ import { ConfigService } from '../config.service' changeDetection: ChangeDetectionStrategy.OnPush, }) export class MeasuresComponent implements OnInit { - stores: Array<Object> = [] + stores: DataProvider[] = [] constructor( public configService: ConfigService, diff --git a/src/app/openapi/index.ts b/src/app/openapi/index.ts index 732ca4b..92970da 100644 --- a/src/app/openapi/index.ts +++ b/src/app/openapi/index.ts @@ -35,6 +35,7 @@ export type { Map } from './models/Map'; export type { MapInitData } from './models/MapInitData'; export type { MaplibreStyle } from './models/MaplibreStyle'; export type { Measures } from './models/Measures'; +export type { MeasuresItem } from './models/MeasuresItem'; export type { ModelAction } from './models/ModelAction'; export type { ModelInfo } from './models/ModelInfo'; export type { ModelValue } from './models/ModelValue'; diff --git a/src/app/openapi/models/DataProvider.ts b/src/app/openapi/models/DataProvider.ts index b00446f..8fb5ecb 100644 --- a/src/app/openapi/models/DataProvider.ts +++ b/src/app/openapi/models/DataProvider.ts @@ -3,6 +3,7 @@ /* tslint:disable */ /* eslint-disable */ export type DataProvider = { + store: string; name: string; values: Array<string>; }; diff --git a/src/app/openapi/models/MeasuresItem.ts b/src/app/openapi/models/MeasuresItem.ts new file mode 100644 index 0000000..ec95b9c --- /dev/null +++ b/src/app/openapi/models/MeasuresItem.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type MeasuresItem = { + id: number; + name: string; +}; + diff --git a/src/app/openapi/services/ApiService.ts b/src/app/openapi/services/ApiService.ts index ad4f1ae..7215beb 100644 --- a/src/app/openapi/services/ApiService.ts +++ b/src/app/openapi/services/ApiService.ts @@ -10,6 +10,7 @@ import type { BootstrapData } from '../models/BootstrapData'; import type { CategoryRead } from '../models/CategoryRead'; import type { DataProvider } from '../models/DataProvider'; import type { FeatureInfo } from '../models/FeatureInfo'; +import type { MeasuresItem } from '../models/MeasuresItem'; import type { ModelInfo } from '../models/ModelInfo'; import type { Project } from '../models/Project'; import type { RoleRead } from '../models/RoleRead'; @@ -147,6 +148,65 @@ export class ApiService { }, }); } + /** + * Get Model List + * Json REST store API compatible with Flask Potion and Angular + * Get the list of items (used for making the list of items in measures) + * Filter only items with at least one measure + * @returns MeasuresItem Successful Response + * @throws ApiError + */ + public getModelListApiDataProviderStoreGet({ + store, + }: { + store: string, + }): Observable<Array<MeasuresItem>> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/data-provider/{store}', + path: { + 'store': store, + }, + errors: { + 404: `Not found`, + 422: `Validation Error`, + }, + }); + } + /** + * Get Model Values + * Get values + * @returns any Successful Response + * @throws ApiError + */ + public getModelValuesApiStoreNameValuesValueGet({ + storeName, + value, + where, + resample, + }: { + storeName: string, + value: string, + where: string, + resample?: (string | null), + }): Observable<any> { + return __request(OpenAPI, this.http, { + method: 'GET', + url: '/api/{store_name}/values/{value}', + path: { + 'store_name': storeName, + 'value': value, + }, + query: { + 'where': where, + 'resample': resample, + }, + errors: { + 404: `Not found`, + 422: `Validation Error`, + }, + }); + } /** * Get Stores * @returns Store Successful Response