diff --git a/frontend/app/class/monitoring-site.ts b/frontend/app/class/monitoring-site.ts index 990763c55..d33650386 100644 --- a/frontend/app/class/monitoring-site.ts +++ b/frontend/app/class/monitoring-site.ts @@ -1,67 +1,13 @@ -import { ISite, JsonData } from "../interfaces/geom"; -import { GeoJSON } from "geojson"; - -export enum columnNameSite{ +export enum columnNameSite { base_site_name = "Nom", last_visit = "Dernière visite", nb_visits = "Nb. visites", base_site_code = "Code", altitude_max = "Alt.max", - altitude_min = "Alt.min" + altitude_min = "Alt.min", } -export const extendedDetailsSite= { +export const extendedDetailsSite = { ...columnNameSite, base_site_description: "Description", }; -export class MonitoringSite implements ISite { - altitude_max: number; - altitude_min: number; - base_site_code: string; - base_site_description?: string; - base_site_name: string; - data: JsonData; - first_use_date: string; - geometry: GeoJSON.FeatureCollection; - id_base_site: number; - id_nomenclature_type_site?: number; - last_visit?: Date; - meta_create_date: Date; - meta_update_date: Date; - nb_visits: number; - uuid_base_site: string; - - constructor( - altitude_max: number, - altitude_min: number, - base_site_code: string, - base_site_description: string, - base_site_name: string, - data: JsonData, - geometry: GeoJSON.FeatureCollection, - first_use_date: string, - id_base_site: number, - id_nomenclature_type_site: number, - last_visit: Date, - meta_create_date: Date, - meta_update_date: Date, - nb_visits: number, - uuid_base_site: string - ) { - this.altitude_max = altitude_max; - this.altitude_min = altitude_min; - this.base_site_code = base_site_code; - this.base_site_description = base_site_description; - this.base_site_name = base_site_name; - this.data = data; - this.first_use_date = first_use_date; - this.geometry = geometry; - this.id_base_site = id_base_site; - this.id_nomenclature_type_site = id_nomenclature_type_site; - this.last_visit = last_visit; - this.meta_create_date = meta_create_date; - this.meta_update_date = meta_update_date; - this.nb_visits = nb_visits; - this.uuid_base_site = uuid_base_site; - } -} diff --git a/frontend/app/class/monitoring-sites-group.ts b/frontend/app/class/monitoring-sites-group.ts index 8bed67806..21ae7f540 100644 --- a/frontend/app/class/monitoring-sites-group.ts +++ b/frontend/app/class/monitoring-sites-group.ts @@ -1,6 +1,3 @@ -import { ISitesGroup, JsonData } from "../interfaces/geom"; -import { GeoJSON } from "geojson"; - export enum columnNameSiteGroup { sites_group_name = "Nom", nb_sites = "Nb. sites", @@ -14,37 +11,3 @@ export const extendedDetailsSiteGroup = { sites_group_description: "Description", }; // export type detailsSiteGroups = columnNameSiteGroup | extendedDetailsSiteGroup - -export class MonitoringSitesGroup implements ISitesGroup { - id_sites_group: number; - sites_group_name: string; - sites_group_code: string; - sites_group_description: string; - geometry: GeoJSON.FeatureCollection; - data: JsonData; - nb_sites: number; - nb_visits: number; - uuid_sites_group: string; //FIXME: see if OK - - constructor( - id_sites_group: number, - sites_group_name: string, - sites_group_code: string, - sites_group_description: string, - geometry: GeoJSON.FeatureCollection, - data: JsonData, - nb_sites: number, - nb_visits: number, - uuid_sites_group: string = "" //FIXME: see if OK - ) { - this.id_sites_group = id_sites_group; - this.sites_group_name = sites_group_name; - this.sites_group_code = sites_group_code; - this.sites_group_description = sites_group_description; - this.geometry = geometry; - this.data = data; - this.nb_sites = nb_sites; - this.nb_visits = nb_visits; - this.uuid_sites_group = uuid_sites_group; - } -} diff --git a/frontend/app/components/monitoring-properties-g/monitoring-properties-g.component.ts b/frontend/app/components/monitoring-properties-g/monitoring-properties-g.component.ts index 0fc3b71f4..c9967b46c 100644 --- a/frontend/app/components/monitoring-properties-g/monitoring-properties-g.component.ts +++ b/frontend/app/components/monitoring-properties-g/monitoring-properties-g.component.ts @@ -8,9 +8,9 @@ import { } from "@angular/core"; import { FormControl } from "@angular/forms"; import { - MonitoringSitesGroup, extendedDetailsSiteGroup, } from "../../class/monitoring-sites-group"; +import { ISitesGroup } from "../../interfaces/geom"; @Component({ selector: "pnx-monitoring-properties-g", @@ -18,7 +18,7 @@ import { styleUrls: ["./monitoring-properties-g.component.css"], }) export class MonitoringPropertiesGComponent implements OnInit { - @Input() selectedObj: MonitoringSitesGroup; + @Input() selectedObj: ISitesGroup; @Input() bEdit: boolean; @Output() bEditChange = new EventEmitter(); @@ -28,7 +28,7 @@ export class MonitoringPropertiesGComponent implements OnInit { infosColsSiteGroups: typeof extendedDetailsSiteGroup = extendedDetailsSiteGroup; color: string = "white"; - dataDetails: MonitoringSitesGroup; + dataDetails: ISitesGroup; datasetForm = new FormControl(); bUpdateSyntheseSpinner = false; diff --git a/frontend/app/components/monitoring-sitesgroups/monitoring-sitesgroups.component.ts b/frontend/app/components/monitoring-sitesgroups/monitoring-sitesgroups.component.ts index a071bc459..a3f6a56d9 100644 --- a/frontend/app/components/monitoring-sitesgroups/monitoring-sitesgroups.component.ts +++ b/frontend/app/components/monitoring-sitesgroups/monitoring-sitesgroups.component.ts @@ -1,10 +1,9 @@ import { Component, OnInit, Input } from "@angular/core"; import { SitesGroupService } from "../../services/sites_group.service"; import { - MonitoringSitesGroup, columnNameSiteGroup, } from "../../class/monitoring-sites-group"; -import { Page, Paginated } from "../../interfaces/page"; +import { IPaginated, IPage } from "../../interfaces/page"; import { Router, Event, @@ -13,8 +12,9 @@ import { NavigationError, ActivatedRoute, } from "@angular/router"; -import { MonitoringSite, columnNameSite } from "../../class/monitoring-site"; +import { columnNameSite } from "../../class/monitoring-site"; import { Subscription } from "rxjs"; +import { ISite, ISitesGroup } from "../../interfaces/geom"; const LIMIT = 10; @@ -24,13 +24,13 @@ const LIMIT = 10; styleUrls: ["./monitoring-sitesgroups.component.css"], }) export class MonitoringSitesGroupsComponent implements OnInit { - @Input() page: Page; - @Input() sitesGroups: MonitoringSitesGroup[]; - @Input() sitesChild: MonitoringSite[]; + @Input() page: IPage; + @Input() sitesGroups: ISitesGroup[]; + @Input() sitesChild: ISite[]; @Input() columnNameSiteGroup: typeof columnNameSiteGroup = columnNameSiteGroup; @Input() columnNameSite: typeof columnNameSite = columnNameSite; - @Input() sitesGroupsSelected: MonitoringSitesGroup; + @Input() sitesGroupsSelected: ISitesGroup; @Input() rows; @Input() colsname; @@ -108,7 +108,7 @@ export class MonitoringSitesGroupsComponent implements OnInit { getSitesGroups(page = 1, params = {}) { this._sites_group_service .get(page, LIMIT, params) - .subscribe((data: Paginated) => { + .subscribe((data: IPaginated) => { this.page = { count: data.count, limit: data.limit, @@ -125,7 +125,7 @@ export class MonitoringSitesGroupsComponent implements OnInit { getSitesGroupsById(page = 1, params = {}) { this._sites_group_service .get(page, LIMIT, params) - .subscribe((data: Paginated) => { + .subscribe((data: IPaginated) => { this.page = { count: data.count, limit: data.limit, @@ -140,7 +140,7 @@ export class MonitoringSitesGroupsComponent implements OnInit { console.log(params); this._sites_group_service .getSitesChild(page, LIMIT, params) - .subscribe((data: Paginated) => { + .subscribe((data: IPaginated) => { this.page = { count: data.count, limit: data.limit, diff --git a/frontend/app/interfaces/column.ts b/frontend/app/interfaces/column.ts index 2f395be28..82f803037 100644 --- a/frontend/app/interfaces/column.ts +++ b/frontend/app/interfaces/column.ts @@ -1,4 +1,4 @@ -export interface Column { +export interface IColumn { name: string; prop: string; description?: string; diff --git a/frontend/app/interfaces/geom.ts b/frontend/app/interfaces/geom.ts index 3bbeb5fdb..f464fc48b 100644 --- a/frontend/app/interfaces/geom.ts +++ b/frontend/app/interfaces/geom.ts @@ -1,12 +1,11 @@ import { GeoJSON } from "geojson"; import { Observable } from "rxjs"; -import { Paginated } from "./page"; - -export type JsonData = { [key: string]: any }; +import { JsonData } from "../types/jsondata"; +import { IPaginated } from "./page"; export interface IGeomObject { data: JsonData; - geometry: GeoJSON.FeatureCollection; + geometry: GeoJSON.Geometry; } export interface ISitesGroup extends IGeomObject { @@ -41,7 +40,7 @@ export interface IGeomService { limit: number, page: number, params: JsonData - ): Observable>; + ): Observable>; // get_geometries(): GeoJson // create(obj: IGeomObject) // patch(obj: IGeomObject) diff --git a/frontend/app/interfaces/page.ts b/frontend/app/interfaces/page.ts index 1f41f6a84..b1541dae0 100644 --- a/frontend/app/interfaces/page.ts +++ b/frontend/app/interfaces/page.ts @@ -1,9 +1,9 @@ -export interface Page { +export interface IPage { count: number; limit: number; page: number; } -export interface Paginated extends Page { +export interface IPaginated extends IPage { items: T[]; } diff --git a/frontend/app/services/data-table.service.ts b/frontend/app/services/data-table.service.ts index 0d17d5687..6f350182b 100644 --- a/frontend/app/services/data-table.service.ts +++ b/frontend/app/services/data-table.service.ts @@ -1,5 +1,5 @@ import { Injectable } from "@angular/core"; -import { Column } from "../interfaces/column"; +import { IColumn } from "../interfaces/column"; interface ItemObjectTable { id: number | null; @@ -19,9 +19,9 @@ export class DataTableService { constructor() {} - colsTable(colName, dataTable): Column[] { + colsTable(colName, dataTable): IColumn[] { const arr = Object.keys(colName); - const allColumn: Column[] = arr + const allColumn: IColumn[] = arr .filter((item) => Object.keys(dataTable).includes(item)) .map((elm) => ({ name: colName[elm], diff --git a/frontend/app/services/sites.service.ts b/frontend/app/services/sites.service.ts index 9a3f10adf..1d13e026e 100644 --- a/frontend/app/services/sites.service.ts +++ b/frontend/app/services/sites.service.ts @@ -1,12 +1,10 @@ import { Injectable } from "@angular/core"; import { Observable } from "rxjs"; -import { map } from "rxjs/operators"; -// import { GeoJSON } from "geojson"; import { CacheService } from "./cache.service"; -import { IGeomService, JsonData, ISite } from "../interfaces/geom"; -import { Paginated } from "../interfaces/page"; -import { MonitoringSite } from "../class/monitoring-site"; +import { IGeomService, ISite } from "../interfaces/geom"; +import { IPaginated } from "../interfaces/page"; +import { JsonData } from "../types/jsondata"; @Injectable() export class SitesService implements IGeomService { @@ -16,16 +14,13 @@ export class SitesService implements IGeomService { page: number = 1, limit: number = 10, params: JsonData = {} - ): Observable> { - return this._cacheService - .request>>("get", `sites`, { + ): Observable> { + return this._cacheService.request>>( + "get", + `sites`, + { queryParams: { page, limit, ...params }, - }) - .pipe( - map((response: Paginated) => ({ - ...response, - items: response.items.map((item: ISite) => item as MonitoringSite), - })) - ); + } + ); } } diff --git a/frontend/app/services/sites_group.service.ts b/frontend/app/services/sites_group.service.ts index 9271224d2..27ae0217d 100644 --- a/frontend/app/services/sites_group.service.ts +++ b/frontend/app/services/sites_group.service.ts @@ -1,13 +1,10 @@ import { Injectable } from "@angular/core"; import { Observable } from "rxjs"; -import { map } from "rxjs/operators"; -// import { GeoJSON } from "geojson"; import { CacheService } from "./cache.service"; -import { IGeomService, JsonData, ISitesGroup, ISite } from "../interfaces/geom"; -import { Paginated } from "../interfaces/page"; -import { MonitoringSitesGroup } from "../class/monitoring-sites-group"; -import { MonitoringSite } from "../class/monitoring-site"; +import { IGeomService, ISitesGroup, ISite } from "../interfaces/geom"; +import { IPaginated } from "../interfaces/page"; +import { JsonData } from "../types/jsondata"; @Injectable() export class SitesGroupService implements IGeomService { constructor(private _cacheService: CacheService) {} @@ -16,19 +13,14 @@ export class SitesGroupService implements IGeomService { page: number = 1, limit: number = 10, params: JsonData = {} - ): Observable> { - return this._cacheService - .request>>("get", `sites_groups`, { + ): Observable> { + return this._cacheService.request>>( + "get", + `sites_groups`, + { queryParams: { page, limit, ...params }, - }) - .pipe( - map((response: Paginated) => ({ - ...response, - items: response.items.map( - (item: ISitesGroup) => item as MonitoringSitesGroup - ), - })) - ); + } + ); } // getById( @@ -50,23 +42,17 @@ export class SitesGroupService implements IGeomService { // ); // } - - getSitesChild(page: number = 1, + getSitesChild( + page: number = 1, limit: number = 10, - params: JsonData = {}, - ): Observable> { - return this._cacheService - .request>>("get", `sites`, { + params: JsonData = {} + ): Observable> { + return this._cacheService.request>>( + "get", + `sites`, + { queryParams: { page, limit, ...params }, - }) - .pipe( - map((response: Paginated) => ({ - ...response, - items: response.items.map( - (item: ISite) => item as MonitoringSite - ), - })) - ); + } + ); } - } diff --git a/frontend/app/types/jsondata.ts b/frontend/app/types/jsondata.ts new file mode 100644 index 000000000..fa13d6798 --- /dev/null +++ b/frontend/app/types/jsondata.ts @@ -0,0 +1 @@ +export type JsonData = { [key: string]: any };