Commit 78a95a7e authored by iv's avatar iv

ERP5Workflow: add links on erp5_graph_editor for transitions and states

parent 9810eed5
......@@ -15,38 +15,39 @@ def getWorkflowGraph(workflow):
graph = {'node': {}, 'edge': {}}
for state in workflow.getStateValueList():
is_initial_state = state.getId() == workflow.getSourceId()
transition_id_list = []
transition_list = []
graph['node'][state.getId()] = {
'_class':'workflow.state',
'name': state.getTitleOrId(),
'is_initial_state': 1 if is_initial_state else 0
'is_initial_state': is_initial_state,
'path': state.getPath()
}
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.
))
graph['edge']["%s_%s" % (state.getId(), transition.getId())] = ({
'_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.
'path': transition.getPath()
})
else:
# user action
transition_id_list.append(transition_id)
transition_list.append(transition)
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 transition_list != []:
graph['edge']['transition_to_%s' % (state.getId())] = {
'_class':'workflow.transition',
'source':state.getId(),
'destination': state.getId(),
'name_path_dict': {transition.getTitleOrId(): transition.getPath() for transition in transition_list}
}
if position_graph:
......@@ -55,52 +56,4 @@ def getWorkflowGraph(workflow):
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)
return json.dumps(dict(graph=getWorkflowGraph(context), class_definition={}), indent=2)
......@@ -22,7 +22,7 @@
<div class="window {{class}}"
id="{{element_id}}"
title="{{title}}">
{{name}}
<a href="{{name_href}}">{{name}}</a>
<div class="ep"></div>
</div>
</script>
......
......@@ -335,12 +335,26 @@
function addEdge(gadget, edge_id, edge_data) {
var overlays = [],
connection;
connection,
label = '';
if (edge_data.name) {
label = edge_data.name;
if (edge_data.path) {
label = label.link(edge_data.path)
}
}
if (edge_data.name_path_dict) {
var linked_name_list = []
for (var name in edge_data.name_path_dict) {
linked_name_list.push(name.link(edge_data.name_path_dict[name]));
}
label = linked_name_list.join(', ');
}
if (label) {
overlays = [
["Label", {
cssClass: "l1 component label",
label: edge_data.name
label: label
}]
];
}
......@@ -497,7 +511,8 @@
"class": node_data._class.replace(".", "-"),
element_id: dom_element_id,
title: node_data.name || node_data.id,
name: node_data.name || node_data.id
name: node_data.name || node_data.id,
name_href: node_data.path
}), "text/html").querySelector(".window");
render_element.append(domElement);
box = $(gadget.props.element).find("#" + dom_element_id);
......
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