Skip to content

Commit

Permalink
refactor: site component with site-service
Browse files Browse the repository at this point in the history
add function to site.services.ts

[Refs ticket]: #4
  • Loading branch information
andriacap committed Jan 17, 2023
1 parent f2c40cb commit a2d1b1d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down
64 changes: 64 additions & 0 deletions frontend/app/services/sites.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeoJSON.Feature, "P"|"type"> {
// properties:Omit<SitesGroups,"geometry">;
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 {
Expand All @@ -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;
});
}

}

0 comments on commit a2d1b1d

Please sign in to comment.