Skip to content
Snippets Groups Projects
Commit 212140bf authored by S.Listl's avatar S.Listl
Browse files

Workflow hide actions if workflow engine is not enabled

parent 209fdb37
No related branches found
No related tags found
No related merge requests found
Showing
with 200 additions and 130 deletions
......@@ -962,6 +962,7 @@
<title>Start workflow</title>
<onActionProcess>%aditoprj%/entity/Offer_entity/entityfields/startworkflow/onActionProcess.js</onActionProcess>
<iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/Offer_entity/entityfields/startworkflow/stateProcess.js</stateProcess>
</entityActionField>
</entityFields>
<recordContainers>
......
import("system.neon");
import("Workflow_lib");
import("system.result");
result.string(WorkflowUtils.engineIsEnabled()
? neon.COMPONENTSTATE_EDITABLE
: neon.COMPONENTSTATE_INVISIBLE
);
\ No newline at end of file
......@@ -1024,6 +1024,7 @@
<title>Start workflow</title>
<onActionProcess>%aditoprj%/entity/Organisation_entity/entityfields/startworkflow/onActionProcess.js</onActionProcess>
<iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/Organisation_entity/entityfields/startworkflow/stateProcess.js</stateProcess>
</entityActionField>
<entityField>
<name>STANDARD_ADDRESS</name>
......
import("system.neon");
import("Workflow_lib");
import("system.result");
result.string(WorkflowUtils.engineIsEnabled()
? neon.COMPONENTSTATE_EDITABLE
: neon.COMPONENTSTATE_INVISIBLE
);
\ No newline at end of file
......@@ -1035,6 +1035,7 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact
<isObjectAction v="false" />
<isSelectionAction v="true" />
<iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/stateProcess.js</stateProcess>
</entityActionField>
</children>
</entityActionGroup>
......@@ -1106,6 +1107,7 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact
<title>Start workflow</title>
<onActionProcess>%aditoprj%/entity/Person_entity/entityfields/startworkflow/onActionProcess.js</onActionProcess>
<iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/Person_entity/entityfields/startworkflow/stateProcess.js</stateProcess>
</entityActionField>
<entityActionField>
<name>openAdminView</name>
......
import("system.neon");
import("Workflow_lib");
import("system.result");
result.string(WorkflowUtils.engineIsEnabled()
? neon.COMPONENTSTATE_EDITABLE
: neon.COMPONENTSTATE_INVISIBLE
);
\ No newline at end of file
import("system.neon");
import("Workflow_lib");
import("system.result");
result.string(WorkflowUtils.engineIsEnabled()
? neon.COMPONENTSTATE_EDITABLE
: neon.COMPONENTSTATE_INVISIBLE
);
\ No newline at end of file
......@@ -735,6 +735,7 @@
<title>Start workflow</title>
<onActionProcess>%aditoprj%/entity/Salesproject_entity/entityfields/startworkflow/onActionProcess.js</onActionProcess>
<iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/Salesproject_entity/entityfields/startworkflow/stateProcess.js</stateProcess>
</entityActionField>
</entityFields>
<recordContainers>
......
import("system.neon");
import("Workflow_lib");
import("system.result");
result.string(WorkflowUtils.engineIsEnabled()
? neon.COMPONENTSTATE_EDITABLE
: neon.COMPONENTSTATE_INVISIBLE
);
\ No newline at end of file
......@@ -3,6 +3,7 @@
<name>WorkflowDefinition_entity</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<title>Workflow definition</title>
<grantCreateProcess>%aditoprj%/entity/WorkflowDefinition_entity/grantCreateProcess.js</grantCreateProcess>
<grantDelete v="false" />
<contentTitleProcess>%aditoprj%/entity/WorkflowDefinition_entity/contentTitleProcess.js</contentTitleProcess>
<iconId>VAADIN:DROP</iconId>
......
import("Workflow_lib");
import("system.result");
result.object(WorkflowUtils.engineIsEnabled());
\ No newline at end of file
......@@ -5,87 +5,94 @@ import("Workflow_lib");
import("system.workflow");
import("JditoFilter_lib");
var workflowKey = vars.get("$param.ProcessDefinitionKey_param");
var excludeVersion = vars.get("$param.CurrentVersion_param");
var context = vars.get("$param.Context_param");
var idvalues = vars.get("$local.idvalues");
var workflowDefs;
if (idvalues)
//immediately invoked function is used so that a return statement can be utilized to end the function at any point
result.object((function ()
{
var loadConfig = workflow.createConfigForLoadingProcessDefinitions()
.processDefinitionIds(idvalues);
workflowDefs = JSON.parse(workflow.getProcessDefinitions(loadConfig));
if (!WorkflowUtils.engineIsEnabled())
return [];
//after new-mode, the given uid is not the actual id, but the key, so if
//no workflow definitions were found, try it again with the key
if (workflowDefs.length === 0)
workflowDefs = _getDefinitionsByKey(idvalues[0]);
}
else
{
workflowDefs = _getDefinitionsByKey(workflowKey);
}
var workflowKey = vars.get("$param.ProcessDefinitionKey_param");
var excludeVersion = vars.get("$param.CurrentVersion_param");
var context = vars.get("$param.Context_param");
var idvalues = vars.get("$local.idvalues");
//structure = {processDefinitionKey : highest_version}
var newestVersions = {};
var workflowDefs;
workflowDefs = workflowDefs.map(function (def)
{
//determine the most recent version of every definition
if (def.version > (newestVersions[def.key] || 0))
newestVersions[def.key] = def.version;
return [
def.id,
def.name,
def.category,
def.key,
def.version,
def.active,
def.description || ""
];
});
if (idvalues)
{
var loadConfig = workflow.createConfigForLoadingProcessDefinitions()
.processDefinitionIds(idvalues);
workflowDefs = JSON.parse(workflow.getProcessDefinitions(loadConfig));
var possibleKeysMap = null;
if (context)
{
possibleKeysMap = {};
WorkflowUtils.getPossibleWorkflowDefinitions(context, $KeywordRegistry.workflowTrigger$manual()).forEach(function (key)
//after new-mode, the given uid is not the actual id, but the key, so if
//no workflow definitions were found, try it again with the key
if (workflowDefs.length === 0)
workflowDefs = _getDefinitionsByKey(idvalues[0]);
}
else
{
this[key] = true;
}, possibleKeysMap);
}
workflowDefs = _getDefinitionsByKey(workflowKey);
}
var filterFn;
//if excludeVersion is set -> all definitions versions with a specific key are loaded
//if not -> load just the newest versions of all definitions
if (!excludeVersion)
{
filterFn = function (currDef)
//structure = {processDefinitionKey : highest_version}
var newestVersions = {};
workflowDefs = workflowDefs.map(function (def)
{
return newestVersions[currDef[3]] == currDef[4] && (possibleKeysMap ? possibleKeysMap[currDef[3]] : true);
};
}
else
{
filterFn = function (currDef)
//determine the most recent version of every definition
if (def.version > (newestVersions[def.key] || 0))
newestVersions[def.key] = def.version;
return [
def.id,
def.name,
def.category,
def.key,
def.version,
def.active,
def.description || ""
];
});
var possibleKeysMap = null;
if (context)
{
possibleKeysMap = {};
WorkflowUtils.getPossibleWorkflowDefinitions(context, $KeywordRegistry.workflowTrigger$manual()).forEach(function (key)
{
this[key] = true;
}, possibleKeysMap);
}
var filterFn;
//if excludeVersion is set -> all definitions versions with a specific key are loaded
//if not -> load just the newest versions of all definitions
if (!excludeVersion)
{
filterFn = function (currDef)
{
return newestVersions[currDef[3]] == currDef[4] && (possibleKeysMap ? possibleKeysMap[currDef[3]] : true);
};
}
else
{
return excludeVersion != currDef[4];
};
}
filterFn = function (currDef)
{
return excludeVersion != currDef[4];
};
}
workflowDefs = workflowDefs.filter(filterFn);
workflowDefs = workflowDefs.filter(filterFn);
workflowDefs = JditoFilterUtils.filterRecords(["UID", "NAME", "CATEGORY", "KEY", "VERSION", "ISACTIVE"], workflowDefs, vars.get("$local.filter").filter);
workflowDefs = JditoFilterUtils.filterRecords(["UID", "NAME", "CATEGORY", "KEY", "VERSION", "ISACTIVE"], workflowDefs, vars.get("$local.filter").filter);
result.object(workflowDefs);
return workflowDefs;
function _getDefinitionsByKey (pKey)
{
var config = workflow.createConfigForLoadingProcessDefinitions();
if (pKey)
config.processDefinitionKey(pKey);
return JSON.parse(workflow.getProcessDefinitions(config));
}
\ No newline at end of file
function _getDefinitionsByKey (pKey)
{
var config = workflow.createConfigForLoadingProcessDefinitions();
if (pKey)
config.processDefinitionKey(pKey);
return JSON.parse(workflow.getProcessDefinitions(config));
}
})());
\ No newline at end of file
......@@ -11,70 +11,74 @@ import("Workflow_lib");
import("system.vars");
import("system.workflow");
var isOnlyForCurrentUser = vars.exists("$param.OnlyForCurrentUser_param") && vars.get("$param.OnlyForCurrentUser_param") == "true";
//immediately invoked function is used so that a return statement can be utilized to end the function at any point
result.object((function ()
{
if (!WorkflowUtils.engineIsEnabled())
return [];
var isOnlyForCurrentUser = vars.exists("$param.OnlyForCurrentUser_param") && vars.get("$param.OnlyForCurrentUser_param") == "true";
var loadConfig = workflow.createConfigForLoadingTasks();
var tasks, dummyTask;
var loadConfig = workflow.createConfigForLoadingTasks();
var tasks;
if (vars.get("$local.idvalues") && vars.get("$local.idvalues")[0])
{
var taskId = vars.get("$local.idvalues")[0];
loadConfig = workflow.createConfigForLoadingTask()
.taskId(taskId);
//TODO: there shouldn't be an error
try {
tasks = [JSON.parse(workflow.getTask(loadConfig))];
}
catch (err)
if (vars.get("$local.idvalues") && vars.get("$local.idvalues")[0])
{
//This can happen if the task is done, then it can't be loaded. If that's the case, return a dummy row
tasks = [];
var taskTitle = vars.exists("$param.TaskTitle_param") && vars.get("$param.TaskTitle_param") || "";
dummyTask = [taskId, translate.text("Task done"), taskTitle, "", vars.get("$sys.date"), "", "", "", "", "", "", "", "", "", "", "", ""];
var taskId = vars.get("$local.idvalues")[0];
loadConfig = workflow.createConfigForLoadingTask()
.taskId(taskId);
//TODO: there shouldn't be an error
try {
tasks = [JSON.parse(workflow.getTask(loadConfig))];
}
catch (err)
{
//This can happen if the task is done, then it can't be loaded. If that's the case, return a dummy row
var taskTitle = vars.exists("$param.TaskTitle_param") && vars.get("$param.TaskTitle_param") || "";
return [[taskId, translate.text("Task done"), taskTitle, "", vars.get("$sys.date"), "", "", "", "", "", "", "", "", "", "", "", ""]];
}
}
else
{
// if (isOnlyForCurrentUser)
// loadConfig.candidateIdentifier(EmployeeUtils.getCurrentUserId());
tasks = JSON.parse(workflow.getTasks(loadConfig));
}
}
else
{
// if (isOnlyForCurrentUser)
// loadConfig.candidateIdentifier(EmployeeUtils.getCurrentUserId());
tasks = JSON.parse(workflow.getTasks(loadConfig));
}
tasks = tasks.map(function (task)
{
var variables = JSON.parse(workflow.getTaskVariables(task.id));
var targetTitle = "";
if (variables.targetId && variables.targetContext)
targetTitle = ContextUtils.loadContentTitle(project.getContextStructure(variables.targetContext).entity, variables.targetId);
var assigneeName = task.assignee ? ContextUtils.loadContentTitle("Employee_entity", task.assignee) : "";
return [
task.id,
task.name,
task.processDefinitionId,
task.processInstanceId,
Date.parse(task.createTime).toString(),
workflow.getFormProperties(task.id),
"",
variables.USER_ID,
task.description || "",
task.category || "",
task.assignee || "",
assigneeName,
task.dueDate ? Date.parse(task.dueDate).toString() : "",
task.owner || "",
variables.targetContext || "",
variables.targetId || "",
targetTitle
];
});
tasks = tasks.map(function (task)
{
var variables = JSON.parse(workflow.getTaskVariables(task.id));
var targetTitle = "";
if (variables.targetId && variables.targetContext)
targetTitle = ContextUtils.loadContentTitle(project.getContextStructure(variables.targetContext).entity, variables.targetId);
var assigneeName = task.assignee ? ContextUtils.loadContentTitle("Employee_entity", task.assignee) : "";
return [
task.id,
task.name,
task.processDefinitionId,
task.processInstanceId,
Date.parse(task.createTime).toString(),
workflow.getFormProperties(task.id),
"",
variables.USER_ID,
task.description || "",
task.category || "",
task.assignee || "",
assigneeName,
task.dueDate ? Date.parse(task.dueDate).toString() : "",
task.owner || "",
variables.targetContext || "",
variables.targetId || "",
targetTitle
];
});
tasks = JditoFilterUtils.filterRecords(["UID", "NAME", "PROCESSDEFINITION_ID", "PROCESSINSTANCE_ID",
"CREATE_TIME", "FORMDEFINITION", "USER", "DESCRIPTION", "CATEGORY", "ASSIGNEE", "", "DUEDATE", "OWNER"], tasks, vars.get("$local.filter").filter);
tasks = JditoFilterUtils.filterRecords(["UID", "NAME", "PROCESSDEFINITION_ID", "PROCESSINSTANCE_ID",
"CREATE_TIME", "FORMDEFINITION", "USER", "DESCRIPTION", "CATEGORY", "ASSIGNEE", "", "DUEDATE", "OWNER"], tasks, vars.get("$local.filter").filter);
if (dummyTask)
tasks = [dummyTask];
result.object(tasks);
\ No newline at end of file
return tasks;
})());
\ No newline at end of file
import("system.project");
import("Sql_lib");
import("system.neon");
import("Context_lib");
......@@ -71,6 +72,14 @@ WorkflowUtils.appendMandatoryVariables = function (pVariables, pTargetId, pTarge
return pVariables;
}
/**
* @return {boolean} if the workflow engine is enabled
*/
WorkflowUtils.engineIsEnabled = function ()
{
return project.getInstanceConfigValue("workflowEngineEnabled", "false") == "true";
}
function WorkflowStarter () {}
WorkflowStarter.TRIGGER_INSERT = function ()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment