Class: Mio::Model::Workflow
- Inherits:
-
Mio::Model
show all
- Defined in:
- lib/mio/model/workflow.rb,
lib/mio/model/workflow/node.rb,
lib/mio/model/workflow/transition.rb
Defined Under Namespace
Classes: Node, Transition
Instance Attribute Summary
Attributes inherited from Mio::Model
#args, #client, #search
Instance Method Summary
collapse
Methods inherited from Mio::Model
#configure, #create, field, #initialize, mappings, nested, #set_enable, set_resource, #set_start, #validate
Constructor Details
This class inherits a constructor from Mio::Model
Instance Method Details
#create_hash ⇒ Object
13
14
15
16
|
# File 'lib/mio/model/workflow.rb', line 13
def create_hash
{name: @args.name,
visibilityIds: @args.visibility}
end
|
#go ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/mio/model/workflow.rb', line 66
def go
if @args.nodes.empty? or @args.transitions.empty?
raise Mio::Model::EmptyField, 'Field nodes to Mio::Model::Workflow must contain at least one node and one transition'
end
@width = 900
@height = 1024
@icon_width = 120
@icon_height = 45
@spacing = 100
unless look_up
@object = create
else
@object = look_up
set_start :stop
end
@structure_path = "#{self.class.resource_name}/#{@object['id']}/structure"
laid_out_nodes = set_node_layouts
structure = @client.update @structure_path, structure_hash(laid_out_nodes)
@client.update @structure_path, structure_hash(laid_out_nodes, transition_lookup(structure))
set_enable
return @object
end
|
#normalize_node(n) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/mio/model/workflow.rb', line 18
def normalize_node n
{
id: n['id'],
name: n['name'],
path: n['path']
}
end
|
#set_node_layouts ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/mio/model/workflow.rb', line 26
def set_node_layouts
x = @spacing
y = @spacing
@args.nodes.map do |n|
n[:layout] = {
width: @icon_width,
height: @icon_height,
x: x,
y: y
}
x += (@icon_width + @spacing)
if x > @width - (@icon_width + @spacing)
x = 0
y += (@icon_height + @spacing)
end
n
end
end
|
#structure_hash(nodes, transitions = []) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/mio/model/workflow.rb', line 59
def structure_hash nodes, transitions=[]
{nodes: nodes,
transitions: transitions,
width: @width,
height: @height}
end
|
#transition_lookup(structure) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/mio/model/workflow.rb', line 46
def transition_lookup structure
@args.transitions.map do |t|
from = structure['nodes'].find{|n| n['name'] == t[:from]}
to = structure['nodes'].find{|n| n['name'] == t[:to]}
raise Mio::Model::DataValueError, "#{t[:from]} to #{t[:to]} is an invalid transition" if from.nil? or to.nil?
{ name: t[:name],
from: normalize_node(from),
to: normalize_node(to)}
end
end
|