-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add edit multi relation features (#140)
* ✨ Start to develop edit multi relation feature from multi parent feature layer * ✨ Start to develop edit multi relation feature from multi parent feature layer * ✨ Add reset method step * Clean code - spaces * 🐛 Add user message to copy paste from other layer * Clean code - spaces * Use steps message to address user to follow right flow * ♻️ Use class instead base or inherit * Remove setModal false * ✨ Show modal select window to choose whild features of select relation you want edit * 🐛 get relation only editable, not also visible * 🌐translation * 💄 run Once * Remove copy feature form external layer tool. Unused * ♻️ Handle start toolbox session uniform * Comment getEditingMediaFields to copy also attach (media, pdf,etcc.) of clone of feature * 🐛 In case of no relations, show user message and stop * ✨ Referred to g3w-suite/g3w-admin#991 * 🐛 Unlock relations layers in case of editing relation by parent layer * Remove return Promise.reject because cause a vue error * Remove unusefull new
- Loading branch information
1 parent
45f9e28
commit 55afa24
Showing
18 changed files
with
354 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,7 +396,7 @@ | |
const is_vector = (external || layer.isGeoLayer()) | ||
this.runAddRelationWorkflow({ | ||
workflow: is_vector | ||
? new this._add_link_workflow.selectandcopy({ | ||
? this._add_link_workflow.selectandcopy({ | ||
copyLayer: layer, | ||
isVector: true, | ||
help: 'editing.steps.help.copy', | ||
|
@@ -421,7 +421,7 @@ | |
*/ | ||
addVectorRelation() { | ||
this.runAddRelationWorkflow({ | ||
workflow: new this._add_link_workflow.add(), | ||
workflow: this._add_link_workflow.add(), | ||
isVector: Layer.LayerTypes.VECTOR === this._layerType, | ||
}); | ||
this.show_vector_tools = false; | ||
|
@@ -473,7 +473,7 @@ | |
this.resize(); | ||
} else { | ||
this.runAddRelationWorkflow({ | ||
workflow: new this._add_link_workflow.add(), | ||
workflow: this._add_link_workflow.add(), | ||
isVector: Layer.LayerTypes.VECTOR === this._layerType, | ||
}); | ||
} | ||
|
@@ -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 })) | ||
] | ||
} | ||
}, | ||
|
@@ -906,11 +906,10 @@ | |
await promise; | ||
} catch (e) { | ||
console.trace('START TOOL FAILED', e); | ||
return Promise.reject(e); | ||
} finally { | ||
relationtool.state.active = false; | ||
} | ||
} catch (e) { | ||
} catch(e) { | ||
console.warn(e); | ||
} | ||
}, | ||
|
@@ -1029,7 +1028,7 @@ | |
this.disabled = true; | ||
|
||
const is_vector = Layer.LayerTypes.VECTOR === this._layerType; | ||
const workflow = new this._add_link_workflow.link( is_vector ? { | ||
const workflow = this._add_link_workflow.link( is_vector ? { | ||
selectStyle: SELECTED_STYLES[this.getLayer().getGeometryType()] | ||
} : {}); | ||
const options = this._createWorkflowOptions(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,97 @@ | ||
import { promisify } from '../../utils/promisify'; | ||
|
||
class Queque { | ||
constructor() { this.tasks = []; } | ||
addTask(task) { this.tasks.push(task); } | ||
run(reverse = false) { while (this.tasks.length) { const task = reverse ? this.tasks.pop() : this.tasks.shift(); task(); } } | ||
flush() { return this.tasks.splice(0); } | ||
getLength() { return this.tasks.length; } | ||
clear() { this.run(); this.tasks = []; } | ||
} | ||
|
||
|
||
/** | ||
* Class Flow of workflow step by step | ||
* | ||
* ORIGINAL SOURCE: g3w-client/src/core/workflow/[email protected] | ||
* ORIGINAL SOURCE: g3w-client/src/core/workflow/[email protected] | ||
*/ | ||
export function Flow() { | ||
console.warn('[G3W-CLIENT] g3wsdk.core.workflow.Flow is deprecated'); | ||
|
||
class Queque { | ||
constructor() { this.tasks = []; } | ||
addTask(task) { this.tasks.push(task); } | ||
run(reverse = false) { while (this.tasks.length) { const task = reverse ? this.tasks.pop() : this.tasks.shift(); task(); } } | ||
flush() { return this.tasks.splice(0); } | ||
getLength() { return this.tasks.length; } | ||
clear() { this.run(); this.tasks = []; } | ||
export class Flow extends g3wsdk.core.G3WObject { | ||
constructor() { | ||
super(); | ||
console.warn('[G3W-CLIENT] g3wsdk.core.workflow.Flow is deprecated'); | ||
this.steps = []; | ||
this.counter = 0; | ||
this.context = null; | ||
this.queques = { | ||
end: new Queque(), | ||
micro: new Queque() | ||
}; | ||
this.inputs; | ||
this.d; | ||
this._workflow; | ||
} | ||
|
||
let steps = []; | ||
let inputs; | ||
let counter = 0; | ||
let context = null; | ||
let d; | ||
let _workflow; | ||
this.queques = { | ||
end: new Queque(), | ||
micro: new Queque() | ||
}; | ||
//start workflow | ||
this.start = function(workflow) { | ||
d = $.Deferred(); | ||
if (counter > 0) { | ||
start(workflow) { | ||
this.d = $.Deferred(); | ||
if (this.counter > 0) { | ||
console.log("reset workflow before restarting"); | ||
} | ||
_workflow = workflow; | ||
inputs = workflow.getInputs(); | ||
context = workflow.getContext(); | ||
steps = workflow.getSteps(); | ||
this._workflow = workflow; | ||
this.inputs = workflow.getInputs(); | ||
this.context = workflow.getContext(); | ||
this.steps = workflow.getSteps(); | ||
// check if there are steps | ||
if (steps && steps.length) { | ||
if (this.steps && this.steps.length) { | ||
//run step (first) | ||
this.runStep(steps[0], inputs, context); | ||
this.runStep(this.steps[0], this.inputs, this.context); | ||
} | ||
// return a promise that will be reolved if all step go right | ||
return d.promise(); | ||
return this.d.promise(); | ||
}; | ||
|
||
//run step | ||
this.runStep = function(step, inputs) { | ||
runStep(step, inputs) { | ||
//run step that run task | ||
_workflow.setMessages({ | ||
this._workflow.setMessages({ | ||
help: step.state.help | ||
}); | ||
const runMicroTasks = this.queques.micro.getLength(); | ||
step.run(inputs, context, this.queques) | ||
step.run(inputs, this.context, this.queques) | ||
.then(outputs => { | ||
runMicroTasks && this.queques.micro.run(); | ||
this.onDone(outputs); | ||
}) | ||
.fail(error => this.onError(error)); | ||
.fail(e => this.onError(e)); | ||
}; | ||
|
||
//check if all step are resolved | ||
this.onDone = function(outputs) { | ||
counter++; | ||
if (counter === steps.length) { | ||
counter = 0; | ||
d.resolve(outputs); | ||
onDone(outputs) { | ||
this.counter++; | ||
if (this.counter === this.steps.length) { | ||
this.counter = 0; | ||
this.d.resolve(outputs); | ||
return; | ||
} | ||
this.runStep(steps[counter], outputs); | ||
this.runStep(this.steps[this.counter], outputs); | ||
}; | ||
|
||
// in case of error | ||
this.onError = function(err) { | ||
counter = 0; | ||
onError(e) { | ||
this.counter = 0; | ||
this.clearQueques(); | ||
d.reject(err); | ||
this.d.reject(e); | ||
}; | ||
|
||
// stop flow | ||
this.stop = function() { | ||
stop() { | ||
const d = $.Deferred(); | ||
steps[counter].isRunning() ? steps[counter].stop() : null; | ||
this.steps[counter].isRunning() ? this.steps[this.counter].stop() : null; | ||
this.clearQueques(); | ||
if (counter > 0) { | ||
if (this.counter > 0) { | ||
// set counter to 0 | ||
counter = 0; | ||
this.counter = 0; | ||
// reject flow | ||
d.reject(); | ||
} else { | ||
|
@@ -97,15 +101,13 @@ export function Flow() { | |
return d.promise(); | ||
}; | ||
|
||
this.clearQueques = function(){ | ||
clearQueques(){ | ||
this.queques.micro.clear(); | ||
this.queques.end.clear(); | ||
} | ||
|
||
g3wsdk.core.utils.base(this) | ||
} | ||
|
||
g3wsdk.core.utils.inherit(Flow, g3wsdk.core.G3WObject); | ||
|
||
/** | ||
* ORIGINAL SOURCE: g3w-client/src/services/[email protected] | ||
|
@@ -812,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 | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.