From a2d1b1d1a7fe18e6967f567ff185ba68f52bb613 Mon Sep 17 00:00:00 2001 From: Andria Capai Date: Tue, 17 Jan 2023 23:53:00 +0100 Subject: [PATCH] refactor: site component with site-service add function to site.services.ts [Refs ticket]: #4 --- .../monitoring-sitesgroups.component.ts | 41 ++---------- frontend/app/services/sites.service.ts | 64 +++++++++++++++++++ 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/frontend/app/components/monitoring-sitesgroups/monitoring-sitesgroups.component.ts b/frontend/app/components/monitoring-sitesgroups/monitoring-sitesgroups.component.ts index cd834a6db..572cc08b0 100644 --- a/frontend/app/components/monitoring-sitesgroups/monitoring-sitesgroups.component.ts +++ b/frontend/app/components/monitoring-sitesgroups/monitoring-sitesgroups.component.ts @@ -116,30 +116,17 @@ export class MonitoringSitesGroupsComponent implements OnInit { this._sites_service .getSitesGroups(offset, LIMIT, params) .subscribe((data: PaginatedSitesGroup) => { - console.log(data) + // console.log(data) this.page = {count: data.count, limit: data.limit, offset: data.offset - 1} - this.sitesGroups = { - features: data.items.map((group) => { - let { - geometry, - properties, - ...others - } = group; - let result = {"geometry":geometry,"properties":properties,"type":"Feature"} - console.log("result",result) - console.log(group) - return result; - }), - type: "FeatureCollection", - }; - console.log(this.sitesGroups); - this.getDataTable(); + this.sitesGroups = this._sites_service.setFormatToGeoJson(data) + // console.log(this.sitesGroups); + this.dataTable = this._sites_service.getDataTable(this.sitesGroups); this.listAllColName = this.colsTable(); // console.log(this.listAllColName) this.columns = this.listAllColName; this.rows = this.dataTable; - console.log("rows", this.rows); - console.log("columns", this.columns); + // console.log("rows", this.rows); + // console.log("columns", this.columns); this.groupSiteId = this.sitesGroups.features[0].properties.id_sites_group; console.log("this.groupSiteId", this.groupSiteId); this.initObjectsStatus(); @@ -151,22 +138,6 @@ export class MonitoringSitesGroupsComponent implements OnInit { this.getSites(e.offset + 1, this.filters) } - getDataTable() { - this.dataTable = this.sitesGroups.features.map((groupSite) => { - let { - comments, - data, - // geometry, - uuid_sites_group, - // type, - id_sites_group, - sites_group_description, - ...dataTable - } = groupSite.properties; - return dataTable; - }); - // console.log(this.dataTable) - } colsTable() { console.log(this.dataTable) diff --git a/frontend/app/services/sites.service.ts b/frontend/app/services/sites.service.ts index 4a1cd0a60..f258a7773 100644 --- a/frontend/app/services/sites.service.ts +++ b/frontend/app/services/sites.service.ts @@ -3,7 +3,39 @@ import { Injectable } from "@angular/core"; import { CacheService } from "./cache.service"; import { ConfigService } from "./config.service"; import { HttpClient } from "@angular/common/http"; +import { GeoJSON } from "leaflet"; +interface SitesGroups{ + comments?: string; + data?: any; + // geometry: any; + id_sites_group: number; + nb_sites: number; + nb_visits: number; + sites_group_code: string; + sites_group_description?: string; + sites_group_name: string; + uuid_sites_group: string; +} + +interface SitesGroupsExtended extends Omit { + // properties:Omit; + properties:SitesGroups + type:string; +} +interface Page { + count: number; + limit: number; + offset: number; +} + +interface PaginatedSitesGroup extends Page{ + items: SitesGroupsExtended[]; +} +interface CustomGeoJson { + type: "FeatureCollection"; + features: SitesGroupsExtended[]; +} @Injectable() export class SitesService { @@ -14,4 +46,36 @@ export class SitesService { getSitesGroups(offset=1, limit=10, params={}) { return this._cacheService.request("get", `sites_groups`, {queryParams: {offset, limit, ...params}}); } + + setFormatToGeoJson(data:PaginatedSitesGroup):CustomGeoJson{ + return { + features: data.items.map((group) => { + let { + geometry, + properties, + ..._ + } = group; + let result = {"geometry":geometry,"properties":properties,"type":"Feature"} + console.log("result",result) + console.log(group) + return result; + }), + type: "FeatureCollection", + }; + } + + getDataTable(data:CustomGeoJson) { + return data.features.map((groupSite) => { + let { + comments, + data, + uuid_sites_group, + id_sites_group, + sites_group_description, + ...dataTable + } = groupSite.properties; + return dataTable; + }); + } + }