From 45f9e28f207d9701b55b59c33aca90ad2046c0aa Mon Sep 17 00:00:00 2001 From: Francesco Boccacci Date: Tue, 3 Dec 2024 11:14:10 +0100 Subject: [PATCH] :sparkles: Add copy feature in relations tables tools (#139) * :sparkles: Add copy feature in relations tables tools * Add copy feature tool from relation table only if relation later is a table layer --- components/FormRelation.vue | 52 +++++++++++++++++++++++++++++++++++++ utils/addTableFeature.js | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/components/FormRelation.vue b/components/FormRelation.vue index 57076f6b..582afb10 100644 --- a/components/FormRelation.vue +++ b/components/FormRelation.vue @@ -258,6 +258,7 @@ import { Workflow } from '../g3wsdk/workflow/workflow'; import { Step } from '../g3wsdk/workflow/step'; + import { cloneFeature } from '../utils/cloneFeature'; import { setAndUnsetSelectedFeaturesStyle } from '../utils/setAndUnsetSelectedFeaturesStyle'; import { promisify, $promisify } from '../utils/promisify'; import { getRelationFieldsFromRelation } from '../utils/getRelationFieldsFromRelation'; @@ -633,6 +634,18 @@ type: 'editfeatureattributes', }, + // @since 3.9.0 copy featureonly for table layer + Layer.LayerTypes.TABLE === this._layerType && this.capabilities.includes('add_feature') && { + state: Vue.observable({ + icon: 'pasteFeaturesFromOtherLayers.png', + id: `${id}_copyfeature`, + name: 'editing.tools.copy', + enabled: true, + active: false, + }), + type: 'addfeature', + }, + // delete feature this.capabilities.includes('delete_feature') && { state: Vue.observable({ @@ -703,6 +716,45 @@ const selectStyle = is_vector && SELECTED_STYLES[this.getLayer().getGeometryType()]; // get selected vector style const options = this._createWorkflowOptions({ features: [relationfeature] }); + //@since 3.9.0 COPY FEATURE FROM ATTRIBUTE TABLE LAYER + if ('copyfeature' === toolId) { + await ( + new Promise(async (resolve, reject) => { + //replace current feature with clone + options.inputs.features = [cloneFeature(relationfeature, this.getLayer())]; + // //need to sett original layer + // options.inputs.layer = CatalogLayersStoresRegistry.getLayerById(this._relationLayerId); + const workflow = new Workflow({ + type: 'addtablefeature', + steps: [ + new Step({ help: 'editing.steps.help.new', run: addTableFeature }), + new OpenFormStep(), + ], + }); + try { + const outputs = await promisify(workflow.start(options)); + const feature = outputs.features[outputs.features.length - 1]; + this.relations.push({ id: feature.getId(), fields: this.getLayer().getFieldsWithValues(feature, { relation: true }) }); + resolve(feature); + } catch(e) { + console.warn(e); + //in case of seva all click + if (options.inputs && options.inputs.relationFeatures) { + this.relations.push( + ...(options.inputs.relationFeatures.newFeatures || []).map(f => ({ id: f.getId(), fields: this.getLayer().getFieldsWithValues(f, { relation: true }) })) + ) + } + reject(e); + + } finally { + workflow.stop(); + relationtool.state.active = false; + + } + }) + ); + } + // DELETE FEATURE RELATION if ('deletefeature' === toolId) { diff --git a/utils/addTableFeature.js b/utils/addTableFeature.js index c7cb1beb..0e1630b9 100644 --- a/utils/addTableFeature.js +++ b/utils/addTableFeature.js @@ -7,7 +7,7 @@ import { $promisify } from './promisify'; * @since g3w-client-plugin-editing@v3.8.0 */ export function addTableFeature(inputs, context) { - const feature = inputs.features.length > 0 ? inputs.features[inputs.features.length -1 ] : inputs.layer.createNewFeature(); + const feature = inputs.features.length > 0 ? inputs.features[inputs.features.length - 1 ] : inputs.layer.createNewFeature(); feature.setTemporaryId();