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