Skip to content

Commit 9e52c40

Browse files
committed
Default value
1 parent 94aae5a commit 9e52c40

4 files changed

Lines changed: 27 additions & 15 deletions

File tree

frontend/app/components/monitoring-form-g/monitoring-form-g.component.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ export class MonitoringFormGComponent implements OnInit, AfterViewInit {
6161
) {}
6262

6363
ngAfterViewInit() {
64-
this.formValues(this.object).subscribe((formValue) => {
65-
if (this.object) {
66-
this.form.patchValue(formValue);
67-
}
68-
this.setDefaultFormValue();
64+
if (this.object) {
65+
this.form.patchValue(this.object);
66+
}
67+
this.setDefaultFormValue();
68+
69+
this.formValues(this.form.value).subscribe((formValue) => {
70+
this.form.patchValue(formValue);
6971
if (this.config['geometry_type']) {
7072
this._formService.changeFormMapObj({
7173
frmGp: this.form.controls['geometry'] as FormControl,
@@ -106,7 +108,7 @@ export class MonitoringFormGComponent implements OnInit, AfterViewInit {
106108
this.object.geometry = null;
107109
} else {
108110
// TODO pourquoi la conversion en JSON ici ?
109-
this.object.geometry = JSON.parse(this.object.geometry);
111+
this.object.geometry = this.object.geometry;
110112
}
111113
}
112114
}
@@ -126,14 +128,16 @@ export class MonitoringFormGComponent implements OnInit, AfterViewInit {
126128
setDefaultFormValue() {
127129
const value = this.form.value;
128130
const date = new Date();
131+
const isoDate =
132+
date.getFullYear() +
133+
'-' +
134+
String(date.getMonth() + 1).padStart(2, '0') +
135+
'-' +
136+
String(date.getDate()).padStart(2, '0');
129137
const defaultValue = {
130138
id_digitiser: value['id_digitiser'] || this.currentUser.id_role,
131139
id_inventor: value['id_inventor'] || this.currentUser.id_role,
132-
first_use_date: value['first_use_date'] || {
133-
year: date.getUTCFullYear(),
134-
month: date.getUTCMonth() + 1,
135-
day: date.getUTCDate(),
136-
},
140+
first_use_date: value['first_use_date'] || isoDate,
137141
};
138142
this.form.patchValue(defaultValue);
139143
}
@@ -225,8 +229,10 @@ export class MonitoringFormGComponent implements OnInit, AfterViewInit {
225229
return formDef;
226230
}
227231
formValues(objData): Observable<any> {
232+
if (!objData) {
233+
return of(true);
234+
}
228235
let schema = this.config['fields'];
229-
230236
const properties = Utils.copy(objData);
231237
const observables = {};
232238

@@ -235,6 +241,9 @@ export class MonitoringFormGComponent implements OnInit, AfterViewInit {
235241
if (!(elem || [])['type_widget']) {
236242
continue;
237243
}
244+
if (!(attribut_name in properties)) {
245+
continue;
246+
}
238247
observables[attribut_name] = this._formUtils.toForm(elem, properties[attribut_name]);
239248
}
240249

frontend/app/components/monitoring-site-form-g/monitoring-site-form-g.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { DataUtilsService } from '../../services/data-utils.service';
1414
import { JsonData } from '../../types/jsondata';
1515
import { GeoJSONService } from '../../services/geojson.service';
1616
import { NavigationService } from '../../services/navigation.service';
17+
import { MonitoringObjectService } from '../../services/monitoring-object.service';
1718

1819
@Component({
1920
selector: 'pnx-monitoring-site-form-g',
@@ -38,6 +39,7 @@ export class MonitoringSiteFormGComponent extends MonitoringFormGComponent {
3839
_geojsonService: GeoJSONService,
3940
_navigationService: NavigationService,
4041
_route: ActivatedRoute,
42+
_formUtils: MonitoringObjectService,
4143
translate: TranslateService
4244
) {
4345
super(
@@ -50,6 +52,7 @@ export class MonitoringSiteFormGComponent extends MonitoringFormGComponent {
5052
_geojsonService,
5153
_navigationService,
5254
_route,
55+
_formUtils,
5356
translate
5457
);
5558
}

frontend/app/components/monitoring-sites-create/monitoring-sites-create.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export class MonitoringSitesCreateComponent implements OnInit {
3737

3838
ngOnInit() {
3939
this.moduleCode = this._route.snapshot.data.createSite.moduleCode;
40-
this.siteService.setModuleCode(this.moduleCode);
4140

41+
this.currentUser = this._auth.getCurrentUser();
4242
this.moduleConfig = this._configServiceG.config();
4343
this.form = this._formBuilder.group({});
44-
this.currentUser = this._auth.getCurrentUser();
44+
4545
// Création d'un nouveau site
4646
this.site = null;
4747

frontend/app/interfaces/geom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface ISite extends IGeomObject {
4444
types_site: JsonData[];
4545
medias: JsonData[];
4646
id_sites_group: number;
47-
id_inventor: string[];
47+
id_inventor: number;
4848
inventor: string[];
4949
}
5050

0 commit comments

Comments
 (0)