Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared entities: use target instead of actionableBy #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/plugins/std_workflow/js/std_workflow_entity_shared_role.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// pull tasks between theselves. Any change of user will be 'sticky' when the workflow
// returns to that entity later on in the process.

var USE_TARGET_FOR_ENTITIES = O.application.config["std_workflow:entity_shared_roles:use_target_for_entities"];

var sharedEntitiesForWorkflow = {};

// Database table to store the last selected entity
Expand All @@ -29,6 +31,17 @@ var tableSharedRolesSelect = function(M, entityName) {
return q.length ? q[0] : null;
};

var replaceActionableByMaybe = function(M, actionableBy) {
if(USE_TARGET_FOR_ENTITIES.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will throw an exception is the config isn't defined. You should default it to [] on line 14 above to avoid this

if(-1 !== USE_TARGET_FOR_ENTITIES.indexOf(actionableBy) && M.target) {
let tt = M.target.split('.');
if(tt.length === 2) {
return tt[1];
}
}
}
};

// --------------------------------------------------------------------------

P.registerWorkflowFeature("std:entities:entity_shared_roles", function(workflow, specification) {
Expand Down Expand Up @@ -92,6 +105,9 @@ P.registerWorkflowFeature("std:entities:entity_shared_roles", function(workflow,
if(M.workUnit.closed) { return; }
var stateDefinition = M.$states[M.state],
actionableBy = stateDefinition ? stateDefinition.actionableBy : undefined;
if(USE_TARGET_FOR_ENTITIES) {
actionableBy = replaceActionableByMaybe(M, actionableBy) || actionableBy;
}
if(-1 === sharedEntitiesForWorkflow[workflow.fullName].indexOf(actionableBy)) { return; }
var list = M.entities[actionableBy+"_refList"];
if(list.length > 1) {
Expand All @@ -117,6 +133,9 @@ P.registerWorkflowFeature("std:entities:entity_shared_roles", function(workflow,
workflow.notification({}, function(M, notify) {
var stateDefinition = M.$states[M.state],
actionableBy = stateDefinition ? stateDefinition.actionableBy : undefined;
if(USE_TARGET_FOR_ENTITIES) {
actionableBy = replaceActionableByMaybe(M, actionableBy) || actionableBy;
}
if(-1 === sharedEntitiesForWorkflow[workflow.fullName].indexOf(actionableBy)) { return; }
var row = tableSharedRolesSelect(M, actionableBy);
if(row) {
Expand Down Expand Up @@ -152,6 +171,9 @@ P.respond("GET,POST", "/do/workflow/shared-role", [
var stateDefinition = M.$states[M.state],
sharedEntities = sharedEntitiesForWorkflow[workflow.fullName] || [],
actionableBy = stateDefinition ? stateDefinition.actionableBy : undefined;
if(USE_TARGET_FOR_ENTITIES) {
actionableBy = replaceActionableByMaybe(M, actionableBy) || actionableBy;
}
if(-1 === sharedEntities.indexOf(actionableBy)) { return; }

var currentUserRef = O.currentUser.ref;
Expand Down