Skip to content

Commit

Permalink
refactor(front): rename interfaces, remove classes
Browse files Browse the repository at this point in the history
Better types
  • Loading branch information
Maxime Vergez committed Jan 23, 2023
1 parent dfd39fd commit 5baaaa6
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 167 deletions.
60 changes: 3 additions & 57 deletions frontend/app/class/monitoring-site.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
37 changes: 0 additions & 37 deletions frontend/app/class/monitoring-sites-group.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ 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",
templateUrl: "./monitoring-properties-g.component.html",
styleUrls: ["./monitoring-properties-g.component.css"],
})
export class MonitoringPropertiesGComponent implements OnInit {
@Input() selectedObj: MonitoringSitesGroup;
@Input() selectedObj: ISitesGroup;
@Input() bEdit: boolean;
@Output() bEditChange = new EventEmitter<boolean>();

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -108,7 +108,7 @@ export class MonitoringSitesGroupsComponent implements OnInit {
getSitesGroups(page = 1, params = {}) {
this._sites_group_service
.get(page, LIMIT, params)
.subscribe((data: Paginated<MonitoringSitesGroup>) => {
.subscribe((data: IPaginated<ISitesGroup>) => {
this.page = {
count: data.count,
limit: data.limit,
Expand All @@ -125,7 +125,7 @@ export class MonitoringSitesGroupsComponent implements OnInit {
getSitesGroupsById(page = 1, params = {}) {
this._sites_group_service
.get(page, LIMIT, params)
.subscribe((data: Paginated<MonitoringSitesGroup>) => {
.subscribe((data: IPaginated<ISitesGroup>) => {
this.page = {
count: data.count,
limit: data.limit,
Expand All @@ -140,7 +140,7 @@ export class MonitoringSitesGroupsComponent implements OnInit {
console.log(params);
this._sites_group_service
.getSitesChild(page, LIMIT, params)
.subscribe((data: Paginated<MonitoringSite>) => {
.subscribe((data: IPaginated<ISite>) => {
this.page = {
count: data.count,
limit: data.limit,
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/interfaces/column.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Column {
export interface IColumn {
name: string;
prop: string;
description?: string;
Expand Down
9 changes: 4 additions & 5 deletions frontend/app/interfaces/geom.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -41,7 +40,7 @@ export interface IGeomService {
limit: number,
page: number,
params: JsonData
): Observable<Paginated<IGeomObject>>;
): Observable<IPaginated<IGeomObject>>;
// get_geometries(): GeoJson
// create(obj: IGeomObject)
// patch(obj: IGeomObject)
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/interfaces/page.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface Page {
export interface IPage {
count: number;
limit: number;
page: number;
}

export interface Paginated<T> extends Page {
export interface IPaginated<T> extends IPage {
items: T[];
}
6 changes: 3 additions & 3 deletions frontend/app/services/data-table.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@angular/core";
import { Column } from "../interfaces/column";
import { IColumn } from "../interfaces/column";

interface ItemObjectTable {
id: number | null;
Expand All @@ -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],
Expand Down
25 changes: 10 additions & 15 deletions frontend/app/services/sites.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,16 +14,13 @@ export class SitesService implements IGeomService {
page: number = 1,
limit: number = 10,
params: JsonData = {}
): Observable<Paginated<MonitoringSite>> {
return this._cacheService
.request<Observable<Paginated<ISite>>>("get", `sites`, {
): Observable<IPaginated<ISite>> {
return this._cacheService.request<Observable<IPaginated<ISite>>>(
"get",
`sites`,
{
queryParams: { page, limit, ...params },
})
.pipe(
map((response: Paginated<ISite>) => ({
...response,
items: response.items.map((item: ISite) => item as MonitoringSite),
}))
);
}
);
}
}
54 changes: 20 additions & 34 deletions frontend/app/services/sites_group.service.ts
Original file line number Diff line number Diff line change
@@ -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) {}
Expand All @@ -16,19 +13,14 @@ export class SitesGroupService implements IGeomService {
page: number = 1,
limit: number = 10,
params: JsonData = {}
): Observable<Paginated<MonitoringSitesGroup>> {
return this._cacheService
.request<Observable<Paginated<ISitesGroup>>>("get", `sites_groups`, {
): Observable<IPaginated<ISitesGroup>> {
return this._cacheService.request<Observable<IPaginated<ISitesGroup>>>(
"get",
`sites_groups`,
{
queryParams: { page, limit, ...params },
})
.pipe(
map((response: Paginated<ISitesGroup>) => ({
...response,
items: response.items.map(
(item: ISitesGroup) => item as MonitoringSitesGroup
),
}))
);
}
);
}

// getById(
Expand All @@ -50,23 +42,17 @@ export class SitesGroupService implements IGeomService {
// );
// }


getSitesChild(page: number = 1,
getSitesChild(
page: number = 1,
limit: number = 10,
params: JsonData = {},
): Observable<Paginated<MonitoringSite>> {
return this._cacheService
.request<Observable<Paginated<ISite>>>("get", `sites`, {
params: JsonData = {}
): Observable<IPaginated<ISite>> {
return this._cacheService.request<Observable<IPaginated<ISite>>>(
"get",
`sites`,
{
queryParams: { page, limit, ...params },
})
.pipe(
map((response: Paginated<ISite>) => ({
...response,
items: response.items.map(
(item: ISite) => item as MonitoringSite
),
}))
);
}
);
}

}
1 change: 1 addition & 0 deletions frontend/app/types/jsondata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type JsonData = { [key: string]: any };

0 comments on commit 5baaaa6

Please sign in to comment.