Skip to content

Commit

Permalink
feat(wip) : manage map
Browse files Browse the repository at this point in the history
- keep trying to send geometry to "objForm" object (FormGroup)

Reviewed-by: andriacap
  • Loading branch information
andriacap committed Jun 1, 2023
1 parent d4705e3 commit 79d305a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 24 deletions.
18 changes: 15 additions & 3 deletions frontend/app/components/draw-form/draw-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
EventEmitter,
ViewEncapsulation,
} from "@angular/core";
import { FormControl, FormGroup } from "@angular/forms";
import { FormControl } from "@angular/forms";

import { leafletDrawOptions } from "./leaflet-draw.options";
import { CustomMarkerIcon } from "@geonature_common/map/marker/marker.component";
import { FormService } from "../../services/form.service";

@Component({
selector: "pnx-draw-form",
Expand Down Expand Up @@ -37,7 +38,7 @@ export class DrawFormComponent implements OnInit {

@Input() bEdit;

constructor() {}
constructor(private _formService: FormService) {}

ngOnInit() {
// choix du type de geometrie
Expand Down Expand Up @@ -105,7 +106,18 @@ export class DrawFormComponent implements OnInit {
// suivi composant => formControl
bindGeojsonForm(geojson) {
this.geojson = geojson;
this.parentFormControl.setValue(geojson.geometry);
if (!this.parentFormControl){
this._formService.currentFormMap.subscribe((dataForm) => {
if('geometry' in dataForm.frmGp.controls){
this.parentFormControl = dataForm.frmGp.controls['geometry'] as FormControl
this.parentFormControl.setValue(geojson.geometry);
}
})
}
else {
this.parentFormControl.setValue(geojson.geometry);
}

}

ngOnChanges(changes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { tap, mergeMap, map } from 'rxjs/operators';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { tap, mergeMap, map, take } from 'rxjs/operators';
import { ActivatedRoute } from '@angular/router';
import { Router } from '@angular/router';
import { DynamicFormService } from '@geonature_common/form/dynamic-form-generator/dynamic-form.service';
Expand Down Expand Up @@ -86,6 +86,7 @@ export class MonitoringFormComponentG implements OnInit {
}),
mergeMap((frmCtrl) => {
return this.apiService.getConfig().pipe(
take(1),
map((prop) => {
return { frmCtrl, prop: prop };
})
Expand Down Expand Up @@ -158,9 +159,11 @@ export class MonitoringFormComponentG implements OnInit {
this.objForm.addControl('patch_update', this._formBuilder.control(0));
// set geometry
if (this.obj.config['geometry_type']) {
this.objForm.addControl('geometry', this._formBuilder.control('', Validators.required));
let frmCtrlGeom ={frmCtrl:this._formBuilder.control('', Validators.required),frmName:'geometry'}
this.addGeomFormCtrl(frmCtrlGeom)
this._formService.changeFormMapObj({frmGp:this.objForm,bEdit:true, obj: this.obj})
}
this._formService.changeFormMapObj({frmGp:this.objForm,bEdit:true, objForm: this.obj})

this.initForm();
});
}
Expand Down Expand Up @@ -411,6 +414,10 @@ export class MonitoringFormComponentG implements OnInit {
// this.dataForm = rest
this.dataForm = this.objForm.value;
const change = this._configService.change(this.obj.moduleCode, this.obj.objectType);
// if('geometry' in this.objForm.controls){
// this._formService.changeFormMapObj({frmGp:this.objForm,bEdit:true, obj: this.obj})
// }

if (!change) {
return;
}
Expand Down Expand Up @@ -445,6 +452,14 @@ export class MonitoringFormComponentG implements OnInit {
this.extraForm = frmCtrl;
}

addGeomFormCtrl(frmCtrl:{frmCtrl :FormControl,frmName:string}){
if (frmCtrl.frmName in this.objForm.controls) {
this.objForm.setControl(frmCtrl.frmName, frmCtrl.frmCtrl);
} else {
this.objForm.addControl(frmCtrl.frmName, frmCtrl.frmCtrl);
}
}

checkValidExtraFormCtrl() {
if (
this.extraForm.frmName in this.objForm.controls &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ export class MonitoringMapListComponent {
displayMap: boolean = true;
siteSiteGroup: SiteSiteGroup | null = null;
apiService: ApiGeomService;
constructor( private _objService: ObjectService,private _formService: FormService,private _configService: ConfigJsonService) {}
constructor(private _formService: FormService,) {}

initObj(prop) {
// this.apiService.getConfig().subscribe(prop => this.obj['properties'] = prop)
this.obj['properties'] = prop;
}
onActivate(component) {
this._formService.currentFormMap.subscribe(formMapObj => {
this.obj = formMapObj.objForm
this.obj = formMapObj.obj
this.bEdit = formMapObj.bEdit
this.objForm = formMapObj.frmGp
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/interfaces/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ export type IBreadCrumb = {
}


export type IFormMap = { frmGp : FormGroup; bEdit: boolean, objForm: any };
export type IFormMap = { frmGp : FormGroup; bEdit: boolean, obj: any };
23 changes: 13 additions & 10 deletions frontend/app/services/form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ISite, ISitesGroup } from '../interfaces/geom';
import { JsonData } from '../types/jsondata';
import { Utils } from '../utils/utils';
import { MonitoringObjectService } from './monitoring-object.service';
import { FormControl } from '@angular/forms';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { IExtraForm, IFormMap } from '../interfaces/object';


Expand All @@ -23,10 +23,11 @@ export class FormService {
moduleCode: string;
objecType: string;

private formMap = new ReplaySubject<IFormMap>(1);
frmrGrp: FormGroup = this._formBuilder.group({});
private formMap = new BehaviorSubject<IFormMap>({frmGp:this.frmrGrp ,bEdit:true,obj:{}});
currentFormMap = this.formMap.asObservable();

constructor(private _objService: MonitoringObjectService) {}
constructor(private _objService: MonitoringObjectService, private _formBuilder: FormBuilder) {}


changeDataSub(
Expand Down Expand Up @@ -74,9 +75,11 @@ export class FormService {
concatMap((formValues_in) => {
const formValues = Utils.copy(formValues_in);
// geometry
// if (this.config["geometry_type"]) {
// formValues["geometry"] = this.geometry; // copy???
// }
if (obj.config["geometry_type"]) {
// TODO: change null by the geometry load from the object (if edit) or null if create
// formValues["geometry"] = this.geometry; // copy???
formValues["geometry"] = null ; // copy???
}
return of(formValues);
})
);
Expand Down Expand Up @@ -132,10 +135,10 @@ export class FormService {
// };

// TODO: A voir q'il faut remettre
// if (this.config["geometry_type"]) {
// postData["geometry"] = formValue["geometry"];
// postData["type"] = "Feature";
// }
if (obj.config["geometry_type"]) {
postData["geometry"] = formValue["geometry"];
postData["type"] = "Feature";
}
return postData;
}
}

0 comments on commit 79d305a

Please sign in to comment.