Skip to content

Commit

Permalink
✨ Add copy feature in relations tables tools (#139)
Browse files Browse the repository at this point in the history
* ✨ Add copy feature in relations tables tools

* Add copy feature tool from relation table only if relation later is a table layer
  • Loading branch information
volterra79 authored Dec 3, 2024
1 parent e59fd9e commit 45f9e28
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions components/FormRelation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion utils/addTableFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { $promisify } from './promisify';
* @since [email protected]
*/
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();

Expand Down

0 comments on commit 45f9e28

Please sign in to comment.