From 31c57f8e083c1a68e5f5aa4571caf5bd081dc229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Lafreni=C3=A8re?= <53181414+PhilippeLafreniere18@users.noreply.github.com> Date: Mon, 13 Jun 2022 11:10:52 -0400 Subject: [PATCH] feat(edition): allow send config option / url call for dom / add, modify, delete disabled button config (#1048) * feat(edition): allow send config option and url call for dom * feat(edition): add button disabled config * refactor(edition): Edit mode only with state view * feat(edition): force column value * fix(edition): fix edition mode dom value set --- .../entity-table/entity-table.component.ts | 39 +++++++++++++------ .../lib/entity/shared/entity.interfaces.ts | 1 + .../datasources/datasource.interface.ts | 8 +++- .../shared/edition-workspace.service.ts | 20 +++++++--- .../lib/workspace/shared/edition-workspace.ts | 14 +++++-- 5 files changed, 60 insertions(+), 22 deletions(-) diff --git a/packages/common/src/lib/entity/entity-table/entity-table.component.ts b/packages/common/src/lib/entity/entity-table/entity-table.component.ts index 1889249f24..989237948a 100644 --- a/packages/common/src/lib/entity/entity-table/entity-table.component.ts +++ b/packages/common/src/lib/entity/entity-table/entity-table.component.ts @@ -334,6 +334,12 @@ export class EntityTableComponent implements OnInit, OnChanges, OnDestroy { }); this.formGroup.controls[column.name].setValue(formControlValue); + if (this.isEdition(record) && column.linkColumnForce) { + const entity = record.entity as any; + this.formGroup.controls[column.name].setValue( + entity?.properties[this.getColumnKeyWithoutPropertiesTag(column.linkColumnForce)] + ); + } } else if (column.type === 'date') { if (column.visible) { if (item[key]) { @@ -646,6 +652,7 @@ export class EntityTableComponent implements OnInit, OnChanges, OnDestroy { value = value ? '✓' : ''; // check mark } } else if (column.type === 'list' && value && column.domainValues) { + const entity = record.entity as any; if (column.multiple) { let list_id; typeof value === 'string' ? list_id = value.match(/[\w.-]+/g).map(Number) : list_id = value; @@ -662,27 +669,35 @@ export class EntityTableComponent implements OnInit, OnChanges, OnDestroy { }); this.isEdition(record) ? value = list_id : value = list_option; + } else { + if (!this.isEdition(record) && column.linkColumnForce) { + value = entity?.properties[this.getColumnKeyWithoutPropertiesTag(column.linkColumnForce)]; + } else { + column.domainValues.forEach(option => { + if (typeof value === 'string' && /^\d+$/.test(value)) { + value = parseInt(value); + } + if (option.value === value || option.id === value) { + this.isEdition(record) ? value = option.id : value = option.value; + } + }); + } + } + } else if (column.type === 'autocomplete' && value && column.domainValues) { + const entity = record.entity as any; + if (!this.isEdition(record) && column.linkColumnForce) { + value = entity?.properties[this.getColumnKeyWithoutPropertiesTag(column.linkColumnForce)]; } else { column.domainValues.forEach(option => { if (typeof value === 'string' && /^\d+$/.test(value)) { value = parseInt(value); } if (option.value === value || option.id === value) { - this.isEdition(record) ? value = option.id : value = option.value; + value = option.value; } }); } - } else if (column.type === 'autocomplete' && value && column.domainValues) { - column.domainValues.forEach(option => { - if (typeof value === 'string' && /^\d+$/.test(value)) { - value = parseInt(value); - } - if (option.value === value || option.id === value) { - value = option.value; - } - }); - } - else if (column.type === 'date') { + } else if (column.type === 'date') { if (this.isEdition(record)) { if (value) { let date = moment(value); diff --git a/packages/common/src/lib/entity/shared/entity.interfaces.ts b/packages/common/src/lib/entity/shared/entity.interfaces.ts index 1ba6b5de03..07cd95bb15 100644 --- a/packages/common/src/lib/entity/shared/entity.interfaces.ts +++ b/packages/common/src/lib/entity/shared/entity.interfaces.ts @@ -111,6 +111,7 @@ export interface EntityTableColumn { renderer?: EntityTableColumnRenderer; valueAccessor?: (entity: object, record: EntityRecord) => any; visible?: boolean; + linkColumnForce?: string; sort?: boolean; type?: string; multiple?: boolean; diff --git a/packages/geo/src/lib/datasource/shared/datasources/datasource.interface.ts b/packages/geo/src/lib/datasource/shared/datasources/datasource.interface.ts index 67176531df..b26fd16e08 100644 --- a/packages/geo/src/lib/datasource/shared/datasources/datasource.interface.ts +++ b/packages/geo/src/lib/datasource/shared/datasources/datasource.interface.ts @@ -48,6 +48,7 @@ export interface SourceFieldsOptionsParams { primary?: boolean; visible?: boolean; validation?: SourceFieldsValidationParams; + linkColumnForce?: string; multiple?: boolean; tooltip?: string; } @@ -65,14 +66,18 @@ export interface EditionOptions { addHeaders?: { [key: string]: any }; modifyHeaders?: { [key: string]: any }; modifyProtocol?: string; + addButton?: boolean; + modifyButton?: boolean; + deleteButton?: boolean; } export interface RelationOptions { title: string; name: string; + table?: string; + url?: string; alias?: string; icon?: string; - table: string; parent?: string; tooltip?: string; } @@ -82,6 +87,7 @@ export interface SourceFieldsValidationParams { maxLength?: number; minLength?: number; readonly?: boolean; + send?: boolean; } export interface Legend { diff --git a/packages/geo/src/lib/workspace/shared/edition-workspace.service.ts b/packages/geo/src/lib/workspace/shared/edition-workspace.service.ts index b9cfbb598e..ce470e2bf6 100644 --- a/packages/geo/src/lib/workspace/shared/edition-workspace.service.ts +++ b/packages/geo/src/lib/workspace/shared/edition-workspace.service.ts @@ -255,12 +255,14 @@ export class EditionWorkspaceService { editMode: false, icon: 'pencil', color: 'primary', + disabled: layer.dataSource.options.edition.modifyButton === false ? true : false, click: (feature) => { workspace.editFeature(feature, workspace); } }, { editMode: false, icon: 'delete', color: 'warn', + disabled: layer.dataSource.options.edition.deleteButton === false ? true : false, click: (feature) => { workspace.deleteFeature(feature, workspace); } }, { @@ -326,6 +328,7 @@ export class EditionWorkspaceService { primary: field.primary === true ? true : false, visible: field.visible, validation: field.validation, + linkColumnForce: field.linkColumnForce, type: field.type, domainValues: undefined, relation: undefined, @@ -335,7 +338,7 @@ export class EditionWorkspaceService { }; if (field.type === 'list' || field.type === 'autocomplete') { - this.getDomainValues(field.relation.table).subscribe(result => { + this.getDomainValues(field.relation).subscribe(result => { column.domainValues = result; column.relation = field.relation; }); @@ -426,7 +429,7 @@ export class EditionWorkspaceService { for (const property in feature.properties) { for (const sf of workspace.layer.dataSource.options.sourceFields) { - if (sf.name === property && sf.validation?.readonly) { + if ((sf.name === property && sf.validation?.readonly) || (sf.name === property && sf.validation?.send === false)) { delete feature.properties[property]; } } @@ -530,7 +533,8 @@ export class EditionWorkspaceService { for (const property in feature.properties) { for (const sf of workspace.layer.dataSource.options.sourceFields) { - if ((sf.name === property && sf.validation?.readonly) || property === 'boundedBy') { + if ((sf.name === property && sf.validation?.readonly) || (sf.name === property && sf.validation?.send === false) + || property === 'boundedBy') { delete feature.properties[property]; } } @@ -590,9 +594,9 @@ export class EditionWorkspaceService { feature.edition = false; this.adding$.next(false); workspace.deleteDrawings(); + workspace.entityStore.stateView.clear(); if (feature.newFeature) { - workspace.entityStore.stateView.clear(); workspace.entityStore.delete(feature); workspace.deactivateDrawControl(); @@ -607,14 +611,18 @@ export class EditionWorkspaceService { } } - getDomainValues(table: string): Observable { - let url = this.configService.getConfig('edition.url') + table; + getDomainValues(relation: RelationOptions): Observable { + let url = relation.url; + if (!url) { + url = this.configService.getConfig('edition.url') + relation.table; + } return this.http.get(url).pipe( map(result => { return result; }), catchError((err: HttpErrorResponse) => { + err.error.caught = true; return throwError(err); }) ); diff --git a/packages/geo/src/lib/workspace/shared/edition-workspace.ts b/packages/geo/src/lib/workspace/shared/edition-workspace.ts index 828a1b019a..e79852ea87 100644 --- a/packages/geo/src/lib/workspace/shared/edition-workspace.ts +++ b/packages/geo/src/lib/workspace/shared/edition-workspace.ts @@ -65,10 +65,14 @@ export class EditionWorkspace extends Workspace { }) }); - private filterClauseFunc = (record: EntityRecord) => { + private newFeaturefilterClauseFunc = (record: EntityRecord) => { return record.state.newFeature === true; }; + private editFeaturefilterClauseFunc = (record: EntityRecord) => { + return record.state.edit === true; + }; + public fillColor: string; public strokeColor: string; public strokeWidth: number; @@ -158,7 +162,7 @@ export class EditionWorkspace extends Workspace { // Update domain list if (column.type === 'list' || column.type === 'autocomplete') { - this.editionWorkspaceService.getDomainValues(column.relation.table).subscribe(result => { + this.editionWorkspaceService.getDomainValues(column.relation).subscribe(result => { column.domainValues = result; }); } @@ -180,6 +184,8 @@ export class EditionWorkspace extends Workspace { feature.original_properties = JSON.parse(JSON.stringify(feature.properties)); feature.original_geometry = feature.geometry; feature.idkey = id; + workspace.entityStore.state.updateAll({ edit: false }); + workspace.entityStore.stateView.filter(this.editFeaturefilterClauseFunc); this.addFeatureToStore(feature, workspace); } else { // Only for edition with it's own geometry @@ -187,7 +193,7 @@ export class EditionWorkspace extends Workspace { feature.newFeature = true; this.editionWorkspaceService.adding$.next(true); workspace.entityStore.state.updateAll({ newFeature: false }); - workspace.entityStore.stateView.filter(this.filterClauseFunc); + workspace.entityStore.stateView.filter(this.newFeaturefilterClauseFunc); if (editionOpt.addWithDraw) { const geometryType = editionOpt.geomType; this.onGeometryTypeChange(geometryType, feature, workspace); @@ -279,6 +285,8 @@ export class EditionWorkspace extends Workspace { }) as any; feature.geometry = geometry; + } else { + workspace.entityStore.state.update(feature, { edit: true }, true); } feature.projection = 'EPSG:4326';