Skip to content

Commit

Permalink
✨ Referred to g3w-suite/g3w-admin#991
Browse files Browse the repository at this point in the history
  • Loading branch information
volterra79 committed Dec 12, 2024
1 parent b733b10 commit 29fa953
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
6 changes: 3 additions & 3 deletions components/FormRelation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,14 @@
*
* @since [email protected]
*/
onCommit({ new_relations = {} }) {
onCommit({ relations = {} }) {
const relationLayer = getEditingLayerById(this.relation.child);

// there is a new relation saved on server
if (new_relations[relationLayer.getId()] && Array.isArray(new_relations[relationLayer.getId()].new)) {
if (relations[relationLayer.getId()] && Array.isArray(relations[relationLayer.getId()].new)) {
this._new_relations_ids = [
...(this._new_relations_ids || []),
...new_relations[relationLayer.getId()].new.map(({ clientid, id }) => ({ clientid, id }))
...relations[relationLayer.getId()].new.map(({ clientid, id }) => ({ clientid, id }))
]
}
},
Expand Down
6 changes: 3 additions & 3 deletions deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,15 +814,15 @@ export class Session extends g3wsdk.core.G3WObject {
return;
}

const { new_relations = {} } = response.response; // check if new relations are saved on server
const { relations = {} } = response.response; // check if new relations are saved on server

// sync server data with local data
for (const id in new_relations) {
for (const id in relations) {
Session.Registry
.getSession(id) // get session of relation by id
.getEditor()
.applyCommitResponse({ // apply commit response to current editing relation layer
response: new_relations[id],
response: relations[id],
result: true
});
}
Expand Down
37 changes: 33 additions & 4 deletions g3wsdk/editing/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import { ToolBox } from '../../toolboxes/toolbox';
import { promisify, $promisify } from '../../utils/promisify';
import { getRelationsInEditing } from "../../utils/getRelationsInEditing";
import {getRelationId} from "editing/utils/getRelationId";

const { ApplicationState, G3WObject } = g3wsdk.core;
const { FeaturesStore } = g3wsdk.core.layer.features;
Expand Down Expand Up @@ -320,7 +322,7 @@ export default class Editor extends G3WObject {
// 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);
const feature = this.getEditingSource().getFeatureById(clientid);
// set new id
feature.setId(id);
//set properties
Expand All @@ -346,6 +348,33 @@ export default class Editor extends G3WObject {

});

//@since 3.9.0 take in account update properties returned by server (Useful in case of media input changes)
(response.response.update || []).forEach(({ id, properties } = {}) => {
//get feature from current layer in editing
const feature = this.getEditingSource().getFeatureById(id);
//set properties
feature.setProperties(properties);
//Loop on eventual relation updated or created
relations.forEach(r => { // handle relations (if provided)
Object
.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
(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`
})
}
})
});
});

});

const features = this.readEditingFeatures();

features.forEach(f => f.clearState()); // reset state of the editing features (update, new etc..)
Expand Down Expand Up @@ -439,10 +468,10 @@ export default class Editor extends G3WObject {
*/
stop() {
return $promisify(async () => {
const response = await promisify(this._layer.unlock());
const { result } = await promisify(this._layer.unlock());
this.clear();
return response;
});
return result;
})
}

/**
Expand Down

0 comments on commit 29fa953

Please sign in to comment.