Skip to content

Commit

Permalink
🔙 from #127 - Save new relation after saved new parent feature with S…
Browse files Browse the repository at this point in the history
…ave All (#128)

* Save new relation after saved new parent feature with Save All (#127)

* 🐛 Save all relation

* 🐛 Fix show error message when commit get an error

* Comments

* Filter field unique

* comment and refactor handle of unique input fields

* Comments

* Comments and push Promise to await purpose

* Comments

* ♻️ Unique fields

* 🐛 In case of current_values has null

* Misspelling uniqueFieldsValue instead of uniqueFieldsValue

* 🐛 uniqueFieldsValues set empty value for each layer only

* 🐛 set selected false whe close editing panel - resetDefault

* Set TOC_ORDER to true to CatalogRegistry.getLayers
  • Loading branch information
volterra79 authored Sep 26, 2024
1 parent 9b7e17e commit e03e52e
Show file tree
Hide file tree
Showing 11 changed files with 454 additions and 510 deletions.
9 changes: 3 additions & 6 deletions components/Editing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@

/**
* Start tool of toolbox
*
*
* @param toolId
* @param toolboxId
*/
Expand Down Expand Up @@ -330,7 +330,7 @@
* ORIGINAL SOURCE: g3w-client-plugin-editing/services/[email protected]
*
* Called by Editing Panel on creation time
*
*
* @since [email protected]
*/
registerOnLineOffLineEvent() {
Expand Down Expand Up @@ -359,7 +359,7 @@

/**
* ORIGINAL SOURCE: g3w-client-plugin-editing/services/[email protected]
*
*
* Check if alread have off lines changes
*
* @param { Object } opts
Expand Down Expand Up @@ -591,9 +591,6 @@

this.service.getToolBoxes().forEach(toolbox => toolbox.resetDefault());

// clear all unique values fields related to layer (after a closing editing panel).
this.state.uniqueFieldsValues = {};

this._enableQueryMapControl();
},

Expand Down
219 changes: 97 additions & 122 deletions components/FormRelation.vue

Large diffs are not rendered by default.

53 changes: 30 additions & 23 deletions g3wsdk/editing/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export default class Editor extends G3WObject {
/** @TODO simplfy nested promises */
if (doRequest) {
const features = await promisify(this._layer.getFeatures(options));
// add features from server
// add features from server to editing features store (cloned from original)
this._featuresstore.addFeatures((features || []).map(f => f.clone()));
//set all features to true if no filter is set (e.g., Table layer)
this._allfeatures = !options.filter;
return features;
}
Expand All @@ -93,7 +94,7 @@ export default class Editor extends G3WObject {
};

/**
* @FIXME add description
* { Boolean } true, mean all features of layer are get (e.g. Table layer)
*/
this._allfeatures = false;

Expand Down Expand Up @@ -192,7 +193,7 @@ export default class Editor extends G3WObject {

/**
* Apply response data from server in case of new inserted feature
*
* @param { Object } response
* @param response.response.new array of new ids
* @param response.response.new.clientid temporary id created by client __new__
* @param response.response.new.id the new id created and stored on server
Expand All @@ -206,27 +207,33 @@ export default class Editor extends G3WObject {
// skip when no response and response.result is false
if (!(response && response.result)) { return }

//Loop on new features saved on server
// clientid - temporary id of new feature
// id - id saved on server (autogenerate, next value) to subtituite to clientid feature id
// properties - properties of feature returned by server
response.response.new.forEach(({ clientid, id, properties } = {}) => {

//get feature from current layer in editing
const feature = this._featuresstore.getFeatureById(clientid);

feature.setId(id); // set new id
// set new id
feature.setId(id);
//set properties
feature.setProperties(properties);

relations.forEach(relation => { // handle relations (if provided)
//Loop on eventual relation updated or created
relations.forEach(r => { // handle relations (if provided)
Object
.entries(relation)
.forEach(([ relationId, options = {}]) => {
const is_pk = options.fatherField.find(d => this._layer.isPkField(d)); // check if parent field is a Primary Key
.entries(r)
.forEach(([ id, opts = {}]) => { // id - relation layer id, opts - Object contain relation properties
//get the editing source of relation layer
const source = ToolBox.get(id).getSession().getEditor().getEditingSource();
// handle value to relation field saved on server
if (is_pk) {
const field = options.childField[options.fatherField.indexOf(is_pk)]; // relation field to overwrite
const source = ToolBox.get(relationId).getSession().getEditor().getEditingSource(); // get source of editing layer.
(options.ids || []).forEach(id => { // loop relation ids
const feature = source.getFeatureById(id);
if (feature) { feature.set(field.name, field.value) } // set father feature `value` and `name`
})
}
(opts.ids || []).forEach(id => {
const rFeature = source.getFeatureById(id);
if (rFeature) {
opts.fatherField.forEach((ff, i) => {// loop relation ids
rFeature.set(opts.childField[i], feature.get(ff)) // set father feature `value` and `name`
})
}
})
});
});

Expand Down Expand Up @@ -281,12 +288,12 @@ export default class Editor extends G3WObject {
...commit.relations[relationId].update.map(r => r.id) // updated
],
fatherField: relation.getFatherField(), // father Fields <Array>
childField: relation.getChildField() // child Fields <Array>
childField: relation.getChildField() // child Fields <Array>
}
};
});
}

/** @TODO simplfy nested promises */
const r = await promisify(this._layer.commit(commit));
this.applyCommitResponse(r, relations);
Expand Down Expand Up @@ -339,7 +346,7 @@ export default class Editor extends G3WObject {
}

/**
* Method to clear all filled variable
* Method to clear all filled variables
*/
clear() {
this._started = false;
Expand All @@ -350,7 +357,7 @@ export default class Editor extends G3WObject {
this._layer.getFeaturesStore().clear();

// vector layer
if (this._layer.getType() === Layer.LayerTypes.VECTOR) {
if (Layer.LayerTypes.VECTOR === this._layer.getType()) {
this._layer.resetEditingSource(this._featuresstore.getFeaturesCollection());
}
}
Expand Down
2 changes: 1 addition & 1 deletion g3wsdk/workflow/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Step extends G3WObject {
this._outputs = options.outputs || null;

/**
* Dynamic state of step
* Dynamic state of a step
*/
this.state = {
id: options.id || null,
Expand Down
Loading

0 comments on commit e03e52e

Please sign in to comment.