Commit 8c7e13f1 authored by iv's avatar iv

ERP5Workflow: change informations to transmit to jsplumb in Workflow_getGraph

+ separate python script from XML
parent 361e9a77
from Products.ERP5Type.Message import translateString
import json
portal = context.getPortalObject()
# if a graph has been saved, we use this info for node coordinates.
position_graph = context.getProperty('jsplumb_graph')
if position_graph:
position_graph = json.loads(position_graph)['graph']
# TODO:
# select after script in edge properties
# checked box for validation ? or at least select before script
def getWorkflowGraph(workflow):
graph = {'node': {}, 'edge': {}}
for state in workflow.getStateValueList():
is_initial_state = state.getId() == workflow.getSourceId()
transition_id_list = []
graph['node'][state.getId()] = {
'_class':'workflow.state',
'name': state.getTitleOrId(),
'is_initial_state': 1 if is_initial_state else 0
}
for transition in state.getDestinationValueList():
transition_id = transition.getReference()
if transition_id in workflow.getTransitionIdList():
if transition.getDestinationId():
graph['edge']["%s_%s" % (state.getId(), transition.getId())] = (
dict(_class='workflow.transition',
source=state.getId(),
destination=transition.getDestinationId(),
name=transition.getActionName() or transition.getTitleOrId(),
description=transition.getDescription(),
actbox_url=transition.getAction(),
transition_id=transition.getId() # used for edition.
))
else:
# user action
transition_id_list.append(transition_id)
if transition_id_list != []:
for transition in transition_id_list:
graph['edge'][state.getId()] = {
'_class':'workflow.transition',
'source':state.getId(),
'destination': state.getId(),
'name': str(transition_id_list)
}
if position_graph:
for state_id in graph['node'].keys():
if state_id in position_graph['node']:
graph['node'][state_id]['coordinate'] = position_graph['node'][state_id]['coordinate']
return graph
class_definition = {
'workflow.transition': {
'_class': 'edge',
'type': 'object',
'description': 'A Workflow Transition',
'properties': {
'name': {
'type': 'string',
'name': 'Name',
'description': 'Name of this transition, will be displayed in the document actions',
},
'description': {
'type': 'string',
'name': 'Description',
},
'actbox_url': {
'type': 'string',
'name': 'Action URL',
'description': 'URL of the action, variables will be substitued. XXX TODO: higher level ! just configure "script name" '
},
}
},
'workflow.state': {
'_class': 'node',
'type': 'object',
'description': 'A Workflow State',
'properties': {
'name': {
'type': 'string',
'name': 'Name',
'description': 'The name of the state, will be displayed in document view',
},
'id': {
'type': 'string',
'name': 'Id',
'description': 'Id of the state, will be used for catalog searches',
},
'is_initial_state': {
'type': 'string',
'enum': ['Yes', 'No'],
'name': 'Is initial State',
'description': 'Set to Yes if this state is the initial state for newly created documents',
},
}
}
}
return json.dumps(dict(graph=getWorkflowGraph(context), class_definition=class_definition), indent=2)
...@@ -48,116 +48,6 @@ ...@@ -48,116 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.ERP5Type.Message import translateString\n
import json\n
portal = context.getPortalObject()\n
\n
# if a graph has been saved, we use this info for node coordinates.\n
position_graph = context.getProperty(\'jsplumb_graph\')\n
if position_graph:\n
position_graph = json.loads(position_graph)[\'graph\']\n
\n
# TODO:\n
# select after script in edge properties\n
# checked box for validation ? or at least select before script\n
\n
def getWorkflowGraph(workflow):\n
graph = dict(node=dict(), edge=dict())\n
for state in workflow.getStateValueList():\n
is_initial_state = state.getId() == workflow.getSourceId()\n
transition_id_list = []\n
graph[\'node\'][state.getId()] = dict(\n
_class=\'workflow.state\',\n
name=state.getTitleOrId(),\n
is_initial_state="Yes" if is_initial_state else "No")\n
if is_initial_state:\n
graph[\'node\'][state.getId()][\'css\'] = { "color": "red" } # TODO: use different CSS for initial state\n
\n
for transition in state.getDestinationValueList():\n
transition_id = transition.getReference()\n
if transition_id in workflow.getTransitionIdList():\n
if transition.getDestinationId():\n
graph[\'edge\']["%s_%s" % (state.getId(), transition.getId())] = (\n
dict(_class=\'workflow.transition\',\n
source=state.getId(),\n
destination=transition.getDestinationId(),\n
name=transition.getActionName() or transition.getTitleOrId(),\n
description=transition.getDescription(),\n
actbox_url=transition.getAction(),\n
transition_id=transition.getId() # used for edition.\n
))\n
else:\n
# user action\n
transition_id_list.append(transition_id)\n
\n
if transition_id_list != []:\n
graph[\'edge\'][state.getId()] = (\n
dict(_class=\'workflow.transition\',\n
source=state.getId(),\n
destination=state.getId(),\n
name=str(transition_id_list)\n
))\n
\n
\n
if position_graph:\n
for state_id in graph[\'node\'].keys():\n
if state_id in position_graph[\'node\']:\n
graph[\'node\'][state_id][\'coordinate\'] = position_graph[\'node\'][state_id][\'coordinate\']\n
return graph\n
\n
\n
class_definition = {\n
\'workflow.transition\': {\n
\'_class\': \'edge\',\n
\'type\': \'object\',\n
\'description\': \'A Workflow Transition\',\n
\'properties\': {\n
\'name\': {\n
\'type\': \'string\',\n
\'name\': \'Name\',\n
\'description\': \'Name of this transition, will be displayed in the document actions\',\n
},\n
\'description\': {\n
\'type\': \'string\',\n
\'name\': \'Description\',\n
},\n
\'actbox_url\': {\n
\'type\': \'string\',\n
\'name\': \'Action URL\',\n
\'description\': \'URL of the action, variables will be substitued. XXX TODO: higher level ! just configure "script name" \'\n
},\n
}\n
},\n
\'workflow.state\': {\n
\'_class\': \'node\',\n
\'type\': \'object\',\n
\'description\': \'A Workflow State\',\n
\'properties\': {\n
\'name\': {\n
\'type\': \'string\',\n
\'name\': \'Name\',\n
\'description\': \'The name of the state, will be displayed in document view\',\n
},\n
\'id\': {\n
\'type\': \'string\',\n
\'name\': \'Id\',\n
\'description\': \'Id of the state, will be used for catalog searches\',\n
},\n
\'is_initial_state\': {\n
\'type\': \'string\',\n
\'enum\': [\'Yes\', \'No\'],\n
\'name\': \'Is initial State\',\n
\'description\': \'Set to Yes if this state is the initial state for newly created documents\',\n
},\n
}\n
}\n
}\n
\n
return json.dumps(dict(graph=getWorkflowGraph(context), class_definition=class_definition), indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment