Skip to content

Commit

Permalink
feat(edition): allow send config option / url call for dom / add, mod…
Browse files Browse the repository at this point in the history
…ify, 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
  • Loading branch information
PhilippeLafreniere18 authored Jun 13, 2022
1 parent dddfe7a commit 31c57f8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/lib/entity/shared/entity.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface EntityTableColumn {
renderer?: EntityTableColumnRenderer;
valueAccessor?: (entity: object, record: EntityRecord<object>) => any;
visible?: boolean;
linkColumnForce?: string;
sort?: boolean;
type?: string;
multiple?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface SourceFieldsOptionsParams {
primary?: boolean;
visible?: boolean;
validation?: SourceFieldsValidationParams;
linkColumnForce?: string;
multiple?: boolean;
tooltip?: string;
}
Expand All @@ -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;
}
Expand All @@ -82,6 +87,7 @@ export interface SourceFieldsValidationParams {
maxLength?: number;
minLength?: number;
readonly?: boolean;
send?: boolean;
}

export interface Legend {
Expand Down
20 changes: 14 additions & 6 deletions packages/geo/src/lib/workspace/shared/edition-workspace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
},
{
Expand Down Expand Up @@ -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,
Expand All @@ -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;
});
Expand Down Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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();

Expand All @@ -607,14 +611,18 @@ export class EditionWorkspaceService {
}
}

getDomainValues(table: string): Observable<any> {
let url = this.configService.getConfig('edition.url') + table;
getDomainValues(relation: RelationOptions): Observable<any> {
let url = relation.url;
if (!url) {
url = this.configService.getConfig('edition.url') + relation.table;
}

return this.http.get<any>(url).pipe(
map(result => {
return result;
}),
catchError((err: HttpErrorResponse) => {
err.error.caught = true;
return throwError(err);
})
);
Expand Down
14 changes: 11 additions & 3 deletions packages/geo/src/lib/workspace/shared/edition-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ export class EditionWorkspace extends Workspace {
})
});

private filterClauseFunc = (record: EntityRecord<object>) => {
private newFeaturefilterClauseFunc = (record: EntityRecord<object>) => {
return record.state.newFeature === true;
};

private editFeaturefilterClauseFunc = (record: EntityRecord<object>) => {
return record.state.edit === true;
};

public fillColor: string;
public strokeColor: string;
public strokeWidth: number;
Expand Down Expand Up @@ -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;
});
}
Expand All @@ -180,14 +184,16 @@ 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
if (!feature.newFeature && editionOpt.geomType) {
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);
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 31c57f8

Please sign in to comment.