rails_workflow 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/concerns/rails_workflow/operation_status.rb +2 -50
- data/app/concerns/rails_workflow/operation_templates/default_builder.rb +14 -0
- data/app/concerns/rails_workflow/operation_templates/dependencies.rb +7 -8
- data/app/concerns/rails_workflow/operations/default_runner.rb +19 -6
- data/app/concerns/rails_workflow/operations/dependencies.rb +12 -12
- data/app/concerns/rails_workflow/processes/default_runner.rb +1 -1
- data/app/concerns/rails_workflow/processes/dependency_resolver.rb +12 -17
- data/app/concerns/rails_workflow/status.rb +63 -0
- data/app/concerns/rails_workflow/user/assignment.rb +11 -5
- data/app/controllers/rails_workflow/errors_controller.rb +1 -1
- data/app/controllers/rails_workflow/operation_templates_controller.rb +45 -34
- data/app/controllers/rails_workflow/operations_controller.rb +37 -31
- data/app/controllers/rails_workflow/process_templates_controller.rb +41 -14
- data/app/controllers/rails_workflow/processes_controller.rb +53 -32
- data/app/decorators/rails_workflow/context_decorator.rb +6 -1
- data/app/decorators/rails_workflow/operation_decorator.rb +7 -15
- data/app/decorators/rails_workflow/operation_template_decorator.rb +1 -1
- data/app/decorators/rails_workflow/process_decorator.rb +1 -2
- data/app/decorators/rails_workflow/status_decorator.rb +17 -18
- data/app/models/rails_workflow/error.rb +5 -3
- data/app/models/rails_workflow/operation_template.rb +11 -22
- data/app/models/rails_workflow/process.rb +1 -1
- data/app/views/application/_context.html.slim +11 -0
- data/app/views/rails_workflow/operation_templates/_default_form.html.slim +12 -6
- data/app/views/rails_workflow/operation_templates/_user_group_form.html.slim +10 -5
- data/app/views/rails_workflow/operation_templates/_user_role_form.html.slim +10 -5
- data/app/views/rails_workflow/operation_templates/edit.html.slim +10 -10
- data/app/views/rails_workflow/operation_templates/index.html.slim +9 -9
- data/app/views/rails_workflow/operation_templates/new.html.slim +10 -10
- data/app/views/rails_workflow/operation_templates/show.html.slim +12 -12
- data/app/views/rails_workflow/operations/index.html.slim +1 -1
- data/app/views/rails_workflow/operations/show.html.slim +24 -33
- data/app/views/rails_workflow/process_templates/_form.html.slim +3 -3
- data/app/views/rails_workflow/process_templates/edit.html.slim +5 -5
- data/app/views/rails_workflow/process_templates/index.html.slim +2 -2
- data/app/views/rails_workflow/process_templates/new.html.slim +2 -2
- data/app/views/rails_workflow/process_templates/show.html.slim +9 -9
- data/app/views/rails_workflow/processes/index.html.slim +2 -2
- data/app/views/rails_workflow/processes/show.html.slim +16 -25
- data/app/workers/rails_workflow/error_worker.rb +1 -8
- data/db/migrate/20150215164401_add_partial_name_to_context.rb +6 -0
- data/db/migrate/20150217161051_change_dependencies_to_json.rb +6 -0
- data/lib/generators/rails_workflow/install/templates/create_workflow_processes.rb +132 -99
- data/lib/rails_workflow/version.rb +1 -1
- data/lib/rails_workflow.rb +20 -8
- data/spec/controllers/rails_workflow/operation_templates_controller_spec.rb +1 -2
- data/spec/controllers/rails_workflow/operations_controller_spec.rb +0 -1
- data/spec/controllers/rails_workflow/process_templates_controller_spec.rb +0 -1
- data/spec/controllers/rails_workflow/processes_controller_spec.rb +0 -1
- data/spec/core/rails_workflow/process_manager_spec.rb +17 -1
- data/spec/dummy/app/controllers/application_controller.rb +7 -1
- data/spec/dummy/app/models/user.rb +5 -5
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/{database.sample.yml → database.yml.sample} +0 -0
- data/spec/dummy/config/database.yml.semaphore +16 -0
- data/spec/dummy/config/routes.rb +0 -1
- data/spec/dummy/db/schema.rb +14 -12
- data/spec/dummy/log/development.log +23189 -0
- data/spec/dummy/log/test.log +86228 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0e4b210a8dc7adf45911c7c4ba8f7420 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1616e4e42ff5363173d1d39e6e2a03d4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/22bb4a1009f389151658be54233630d8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/310eee609d7bb0cabf2f8e68b83998b6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/31922eca362eb4de37a5021cccef630d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4de81d9fc089c3a5ba8d42b0056a9865 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5a73175a9ff8699c8927d3a0a876d868 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/68446d3bc756b2b4ac2b1844f17db53b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6a733df9ba21863060bf032f05171bfa +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8227b2b943e2ea911b543eb82228c432 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/94b7a81dd8f8ff07304196359c39ab38 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/94d08b6a05042055bc46262852b983ce +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/96232456037b81cdd1370e99ec2dcc02 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9a2014c7524f2e0958daed330fb0e02e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9b7130a48df56ce8511f3fd6ef903c95 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a2fe1c22fbe6c6a7cb9b8f02a6acf646 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ab0c70eaae03da94a23f832513ff652b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ab2060acff429fdb2590db736072bc0c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b1add619756a502780e48fb4677d62d4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b60aa6e3697ec580ac86be62a6f625f6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c36f232ed7926598f96095a8cc300c3e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ca09843ddbf5238fe84bc305118283ba +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cb0e266c16c56852a172fc789b601cba +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cb6ceea5ffc8a15e06b98ee6e1312290 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d0897c7c9960a927f82986088379f93e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d46bdc6254b6d822735475e06f2e7100 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d8f3150c250e5b7c730f1c8b883bf033 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e4ffa3e3b8053576aae12c9bdb64a075 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e9f705ee81f399edce42ea0b96f52f3b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/eda59a87268a2b4353ab0f5d8cf6bf97 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ef1957bb05e4fcd673c473e82a72e49a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f036d4fc72ce4649ae8186f985e60612 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f3664d9ecf05e354e7668dc11a76044a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f794c7b05987535f7000622afe6630d1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/fc4a9cfb03faaeb5136786c085d7a289 +0 -0
- data/spec/models/rails_workflow/operation_spec.rb +11 -13
- data/spec/models/rails_workflow/operation_template_spec.rb +1 -1
- data/spec/rails_helper.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/controller_macros.rb +0 -7
- metadata +83 -18
- data/app/concerns/rails_workflow/process_status.rb +0 -66
- data/app/controllers/application_controller.rb +0 -3
- data/config/initializers/will_paginate.rb +0 -29
- data/spec/dummy/tmp/pids/server.pid +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 893a6a3e14e7217742d45741be44769220f99871
|
4
|
+
data.tar.gz: 31a32021e3f545687726f713ee34b0302e2e29be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43979534a048ffaca99fa76e71bbe5f513857ebc2f65d05142433fcb0235bae5a3855164f775e6141339ffd6d41bb3d3471c4ad871067bd1a116b75c14e6764c
|
7
|
+
data.tar.gz: 7ba7700fd44f0feb760c86f36cdf3ef6ce818f5ae9e839121cb003a15fdb5591c0abc8ef872449f33bcd7f00d693ae0245b10566e221ec823487e201d8d888ad
|
@@ -3,62 +3,14 @@ require 'active_support/concern'
|
|
3
3
|
module RailsWorkflow
|
4
4
|
module OperationStatus
|
5
5
|
extend ActiveSupport::Concern
|
6
|
+
include Status
|
6
7
|
|
7
8
|
included do
|
8
|
-
NOT_STARTED = 0
|
9
|
-
IN_PROGRESS = 1
|
10
|
-
DONE = 2
|
11
9
|
|
12
|
-
WAITING = 3
|
13
|
-
ERROR = 4
|
14
|
-
|
15
|
-
#operation was in progress and canceled
|
16
|
-
CANCELED = 5
|
17
|
-
|
18
|
-
#operation was build but not started and not need to start
|
19
|
-
SKIPPED = 6
|
20
|
-
|
21
|
-
#current operation was in progress or complete
|
22
|
-
#when process restart or rollback to some previous operation happened
|
23
|
-
#this operation is moved to rollback so that rollback operation
|
24
|
-
#can be added to template.
|
25
|
-
#rollback operation can be used to cancel all changes
|
26
|
-
#done by current operation before restart happened
|
27
|
-
ROLLBACK = 7
|
28
|
-
|
29
|
-
def incomplete_statuses
|
30
|
-
[NOT_STARTED, IN_PROGRESS,]
|
31
|
-
end
|
32
|
-
|
33
|
-
def completed_statuses
|
34
|
-
[DONE, CANCELED, SKIPPED]
|
35
|
-
end
|
36
|
-
|
37
|
-
#in which user can pickup operation and complete it etc.
|
38
10
|
def self.user_ready_statuses
|
39
|
-
[WAITING]
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.ready_to_assign
|
43
|
-
[WAITING]
|
11
|
+
[Status::WAITING]
|
44
12
|
end
|
45
13
|
|
46
|
-
def self.all_statuses
|
47
|
-
(NOT_STARTED..ROLLBACK).to_a
|
48
|
-
end
|
49
|
-
|
50
|
-
def get_status_values
|
51
|
-
[
|
52
|
-
[NOT_STARTED, 'Not Started'],
|
53
|
-
[IN_PROGRESS, 'In Progress'],
|
54
|
-
[DONE, 'Done'],
|
55
|
-
[WAITING, 'Waiting'],
|
56
|
-
[ERROR, 'Error'],
|
57
|
-
[CANCELED, 'Canceled'],
|
58
|
-
[SKIPPED, 'Skipped'],
|
59
|
-
[ROLLBACK, 'Rollback']
|
60
|
-
]
|
61
|
-
end
|
62
14
|
end
|
63
15
|
|
64
16
|
end
|
@@ -45,6 +45,20 @@ module RailsWorkflow
|
|
45
45
|
|
46
46
|
end
|
47
47
|
|
48
|
+
module ClassMethods
|
49
|
+
|
50
|
+
def build_context dependencies
|
51
|
+
dependencies.first.try(:context).try(:data)
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_context! operation, dependencies
|
55
|
+
RailsWorkflow::Context.new(
|
56
|
+
parent: operation,
|
57
|
+
data: build_context(dependencies) || operation.process.data)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
48
62
|
end
|
49
63
|
end
|
50
64
|
end
|
@@ -18,17 +18,16 @@ module RailsWorkflow
|
|
18
18
|
included do
|
19
19
|
scope :independent_only, -> { where(dependencies: nil) }
|
20
20
|
|
21
|
-
def
|
22
|
-
|
21
|
+
def resolve_dependency operation
|
22
|
+
true
|
23
23
|
end
|
24
24
|
|
25
|
+
# def dependencies=(dependencies)
|
26
|
+
# write_attribute(:dependencies, dependencies.to_json.to_s)
|
27
|
+
# end
|
28
|
+
#
|
25
29
|
def dependencies
|
26
|
-
|
27
|
-
if value.present?
|
28
|
-
JSON.parse(value)
|
29
|
-
else
|
30
|
-
[]
|
31
|
-
end
|
30
|
+
read_attribute(:dependencies) || []
|
32
31
|
end
|
33
32
|
|
34
33
|
end
|
@@ -97,13 +97,16 @@ module RailsWorkflow
|
|
97
97
|
true
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
def complete
|
100
|
+
def complete to_status = nil
|
102
101
|
if can_complete?
|
103
|
-
|
102
|
+
|
103
|
+
if to_status.blank? && respond_to?(:on_complete)
|
104
|
+
on_complete
|
105
|
+
end
|
106
|
+
|
104
107
|
update_attributes(
|
105
108
|
{
|
106
|
-
status: self.class::DONE,
|
109
|
+
status: to_status || self.class::DONE,
|
107
110
|
completed_at: Time.zone.now
|
108
111
|
})
|
109
112
|
manager.operation_complete self
|
@@ -113,12 +116,22 @@ module RailsWorkflow
|
|
113
116
|
exception, {
|
114
117
|
parent: self,
|
115
118
|
target: self,
|
116
|
-
method: :complete
|
117
|
-
|
119
|
+
method: :complete,
|
120
|
+
args: [to_status]
|
118
121
|
}
|
119
122
|
)
|
120
123
|
end
|
121
124
|
|
125
|
+
def cancel
|
126
|
+
on_cancel if respond_to? :on_cancel
|
127
|
+
complete self.class::CANCELED
|
128
|
+
end
|
129
|
+
|
130
|
+
def skip
|
131
|
+
on_cancel if respond_to? :on_skip
|
132
|
+
complete self.class::SKIPPED
|
133
|
+
end
|
134
|
+
|
122
135
|
end
|
123
136
|
|
124
137
|
end
|
@@ -17,18 +17,18 @@ module RailsWorkflow
|
|
17
17
|
|
18
18
|
included do
|
19
19
|
|
20
|
-
def dependencies=(dependencies)
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def dependencies
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
20
|
+
# def dependencies=(dependencies)
|
21
|
+
# write_attribute(:dependencies, dependencies.to_json.to_s)
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# def dependencies
|
25
|
+
# value = read_attribute(:dependencies)
|
26
|
+
# if value.present?
|
27
|
+
# JSON.parse(value)
|
28
|
+
# else
|
29
|
+
# []
|
30
|
+
# end
|
31
|
+
# end
|
32
32
|
|
33
33
|
end
|
34
34
|
end
|
@@ -29,7 +29,7 @@ module RailsWorkflow
|
|
29
29
|
# Process can be completed if all sync operations is complete.
|
30
30
|
|
31
31
|
def can_complete?
|
32
|
-
if
|
32
|
+
if incomplete_statuses.include? status
|
33
33
|
incompleted_operations.size == 0 &&
|
34
34
|
workflow_errors.unresolved.size == 0
|
35
35
|
else
|
@@ -17,31 +17,25 @@ module RailsWorkflow
|
|
17
17
|
# dependencies on process and operation level
|
18
18
|
#
|
19
19
|
def build_dependencies operation
|
20
|
-
# template operations that depends on that given operation and it's status
|
21
|
-
template_operations = template.dependent_operations(operation)
|
22
20
|
|
23
21
|
new_operations = []
|
24
|
-
# default implementation is not allowing to have few operations in process
|
25
|
-
# having same operation template. One operation template = one operation in process.
|
26
|
-
# Only error task's restart or process restart allowing to re-create operation few times.
|
27
|
-
|
28
|
-
(template_operations - operations.map(&:template)).each do |operation_template|
|
29
|
-
# this is templates that depends on given operation and
|
30
|
-
# not yet added to process.
|
31
22
|
|
23
|
+
matched_templates(operation).each do |operation_template|
|
32
24
|
completed_dependencies = [operation]
|
33
|
-
|
25
|
+
|
26
|
+
if operation_template.resolve_dependency operation
|
34
27
|
new_operations << operation_template.build_operation!(self, completed_dependencies)
|
35
28
|
end
|
36
29
|
|
37
30
|
end
|
38
31
|
|
39
|
-
new_operations.
|
40
|
-
if
|
32
|
+
new_operations.each do |new_operation|
|
33
|
+
if incomplete_statuses.include?(status)
|
41
34
|
self.operations << new_operation
|
42
35
|
new_operation.start
|
43
36
|
end
|
44
37
|
end
|
38
|
+
|
45
39
|
rescue => exception
|
46
40
|
RailsWorkflow::Error.create_from(
|
47
41
|
exception, {
|
@@ -54,11 +48,12 @@ module RailsWorkflow
|
|
54
48
|
|
55
49
|
end
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
private
|
52
|
+
|
53
|
+
def matched_templates operation
|
54
|
+
template.dependent_operations(operation) - operations.map(&:template)
|
55
|
+
end
|
56
|
+
|
62
57
|
|
63
58
|
|
64
59
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module RailsWorkflow
|
4
|
+
module Status
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def all_statuses
|
9
|
+
(NOT_STARTED..ROLLBACK).to_a
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_status_code status
|
13
|
+
case status
|
14
|
+
when "in_progress"
|
15
|
+
IN_PROGRESS
|
16
|
+
when "done"
|
17
|
+
DONE
|
18
|
+
when "not_started"
|
19
|
+
NOT_STARTED
|
20
|
+
when "waiting"
|
21
|
+
WAITING
|
22
|
+
when "error"
|
23
|
+
ERROR
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
included do
|
30
|
+
|
31
|
+
NOT_STARTED = 0
|
32
|
+
IN_PROGRESS = 1
|
33
|
+
DONE = 2
|
34
|
+
WAITING = 3
|
35
|
+
ERROR = 4
|
36
|
+
CANCELED = 5
|
37
|
+
SKIPPED = 6
|
38
|
+
ROLLBACK = 7
|
39
|
+
|
40
|
+
def incomplete_statuses
|
41
|
+
[NOT_STARTED, IN_PROGRESS, WAITING]
|
42
|
+
end
|
43
|
+
|
44
|
+
def completed_statuses
|
45
|
+
[DONE, CANCELED, SKIPPED, ROLLBACK]
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_status_values
|
49
|
+
[
|
50
|
+
[NOT_STARTED, 'Not Started'],
|
51
|
+
[IN_PROGRESS, 'In Progress'],
|
52
|
+
[DONE, 'Done'],
|
53
|
+
[WAITING, 'Waiting'],
|
54
|
+
[ERROR, 'Error'],
|
55
|
+
[CANCELED, 'Canceled'],
|
56
|
+
[SKIPPED, 'Skipped'],
|
57
|
+
[ROLLBACK, 'Rollback']
|
58
|
+
]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -6,22 +6,28 @@ module RailsWorkflow
|
|
6
6
|
included do
|
7
7
|
has_many :operations, class: RailsWorkflow::Operation, as: :assignment
|
8
8
|
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
9
12
|
|
10
|
-
def
|
13
|
+
def role_text role
|
11
14
|
if role.present?
|
12
|
-
get_role_values
|
15
|
+
get_rassoc get_role_values, role
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
def
|
19
|
+
def group_text group
|
17
20
|
if group.present?
|
18
|
-
get_group_values
|
21
|
+
get_rassoc get_group_values, group
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
|
-
|
25
|
+
def get_rassoc values, value
|
26
|
+
(values.rassoc(value.to_s) || values.rassoc(value.to_sym)).try(:[], 0)
|
27
|
+
end
|
23
28
|
|
24
29
|
end
|
30
|
+
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
@@ -1,39 +1,46 @@
|
|
1
|
-
require 'rails_workflow/application_controller'
|
2
1
|
module RailsWorkflow
|
3
|
-
class OperationTemplatesController < ::
|
2
|
+
class OperationTemplatesController < ::ActionController::Base
|
4
3
|
layout 'rails_workflow/application'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
belongs_to :process_template
|
4
|
+
before_action :set_operation_template, only: [:show, :edit, :update, :destroy]
|
5
|
+
before_action :set_process_template
|
6
|
+
respond_to :html
|
9
7
|
|
10
8
|
before_filter do
|
11
9
|
@config_section_active = true
|
12
10
|
end
|
13
11
|
|
12
|
+
def index
|
13
|
+
@operation_templates = OperationTemplateDecorator.
|
14
|
+
decorate_collection(operation_templates_collection)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
14
18
|
def new
|
15
|
-
@operation_template = OperationTemplate.new(permitted_params
|
16
|
-
@operation_template.process_template =
|
17
|
-
new!
|
19
|
+
@operation_template = OperationTemplate.new(permitted_params).decorate
|
20
|
+
@operation_template.process_template = @process_template
|
18
21
|
end
|
19
22
|
|
23
|
+
|
20
24
|
def create
|
21
|
-
|
25
|
+
@operation_template = OperationTemplate.create(permitted_params)
|
26
|
+
redirect_to process_template_operation_templates_url
|
22
27
|
end
|
23
28
|
|
24
29
|
def update
|
25
|
-
@operation_template
|
26
|
-
|
30
|
+
@operation_template.update(permitted_params)
|
31
|
+
redirect_to process_template_operation_templates_url
|
27
32
|
end
|
28
33
|
|
29
34
|
def destroy
|
30
|
-
destroy
|
35
|
+
@operation_template.destroy
|
36
|
+
redirect_to process_template_operation_templates_url
|
31
37
|
end
|
32
38
|
|
33
39
|
|
34
40
|
protected
|
35
41
|
def permitted_params
|
36
|
-
|
42
|
+
parameters =
|
43
|
+
params.permit(
|
37
44
|
operation_template: [
|
38
45
|
:kind,
|
39
46
|
:type,
|
@@ -42,6 +49,7 @@ module RailsWorkflow
|
|
42
49
|
:child_process_id,
|
43
50
|
:operation_class,
|
44
51
|
:role,
|
52
|
+
:partial_name,
|
45
53
|
:async,
|
46
54
|
:is_background,
|
47
55
|
:group,
|
@@ -50,37 +58,40 @@ module RailsWorkflow
|
|
50
58
|
statuses: []
|
51
59
|
]
|
52
60
|
])
|
53
|
-
|
54
|
-
|
61
|
+
|
62
|
+
if parameters[:operation_template].present?
|
63
|
+
parameters[:operation_template][:dependencies] =
|
64
|
+
prepare_dependencies parameters[:operation_template]
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
parameters[:operation_template]
|
55
69
|
end
|
56
70
|
|
57
|
-
def prepare_dependencies
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
dep['statuses'] = (dep['statuses'] ||
|
62
|
-
RailsWorkflow::OperationTemplate.all_statuses
|
63
|
-
).map(&:to_i)
|
64
|
-
end
|
71
|
+
def prepare_dependencies parameters
|
72
|
+
parameters[:dependencies] &&
|
73
|
+
parse_dependencies(parameters[:dependencies].to_hash)
|
74
|
+
end
|
65
75
|
|
66
|
-
|
76
|
+
def parse_dependencies hash
|
77
|
+
hash.values.each do |dep|
|
78
|
+
dep['id'] = dep['id'].to_i
|
79
|
+
dep['statuses'] = dep['statuses'].map(&:to_i) || RailsWorkflow::OperationTemplate.all_statuses
|
67
80
|
end
|
68
81
|
end
|
69
82
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
set_collection_ivar collection_scope.order(id: :asc)
|
83
|
+
def operation_templates_collection
|
84
|
+
|
85
|
+
@operation_templates = @process_template.try(:operations) || OperationTemplate.
|
86
|
+
order(id: :asc)
|
75
87
|
|
76
|
-
end
|
77
88
|
end
|
78
89
|
|
79
|
-
def
|
80
|
-
|
90
|
+
def set_process_template
|
91
|
+
@process_template = ProcessTemplate.find(params[:process_template_id]).decorate
|
81
92
|
end
|
82
93
|
|
83
|
-
def
|
94
|
+
def set_operation_template
|
84
95
|
@operation_template ||= OperationTemplate::find(params[:id]).decorate
|
85
96
|
end
|
86
97
|
end
|
@@ -1,11 +1,12 @@
|
|
1
|
-
require_dependency "rails_workflow/application_controller"
|
2
|
-
|
3
1
|
module RailsWorkflow
|
4
|
-
class OperationsController < ::
|
2
|
+
class OperationsController < ::ActionController::Base
|
5
3
|
layout 'rails_workflow/application'
|
4
|
+
respond_to :html
|
5
|
+
|
6
|
+
before_action :set_operation, only: [:show, :edit, :pickup, :update, :destroy]
|
6
7
|
|
7
8
|
before_filter do
|
8
|
-
if
|
9
|
+
if @process.present?
|
9
10
|
@processes_section_active = true
|
10
11
|
else
|
11
12
|
@operations_section_active = true
|
@@ -14,26 +15,32 @@ module RailsWorkflow
|
|
14
15
|
@current_operation = current_operation
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
defaults collection_name: 'operations', resource_class: Operation
|
19
|
-
belongs_to :process, optional: true
|
20
|
-
|
21
18
|
def create
|
22
|
-
|
19
|
+
@operation = Operation.create(permitted_params)
|
20
|
+
redirect_to process_operation_url
|
23
21
|
end
|
24
22
|
|
23
|
+
def index
|
24
|
+
@operations = OperationDecorator.decorate_collection(
|
25
|
+
parent.try(:operations) || Operation.waiting.order(created_at: :desc)
|
26
|
+
)
|
27
|
+
|
28
|
+
respond_with @operations
|
29
|
+
end
|
25
30
|
|
26
31
|
def update
|
27
|
-
@operation
|
28
|
-
|
32
|
+
@operation.update(permitted_params)
|
33
|
+
redirect_to process_operation_url
|
29
34
|
end
|
30
35
|
|
31
36
|
def pickup
|
32
|
-
@operation = RailsWorkflow::Operation.find(params[:id])
|
33
|
-
|
34
37
|
if @operation.assign(current_user)
|
38
|
+
|
35
39
|
set_current_operation
|
36
|
-
redirect_to main_app.send(
|
40
|
+
redirect_to main_app.send(
|
41
|
+
@operation.data[:url_path],
|
42
|
+
*@operation.data[:url_params]
|
43
|
+
)
|
37
44
|
else
|
38
45
|
redirect_to operations_path
|
39
46
|
end
|
@@ -46,37 +53,36 @@ module RailsWorkflow
|
|
46
53
|
operation.complete
|
47
54
|
clear_current_operation
|
48
55
|
|
49
|
-
|
56
|
+
redirect_to main_app.root_path
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
53
60
|
def destroy
|
54
|
-
destroy
|
61
|
+
@operation.destroy
|
62
|
+
redirect_to process_operation_url
|
55
63
|
end
|
56
64
|
|
57
65
|
|
58
66
|
protected
|
59
67
|
def permitted_params
|
60
|
-
params.permit(
|
68
|
+
params.permit(
|
69
|
+
operation: [
|
70
|
+
:title,
|
71
|
+
:source,
|
72
|
+
:operation_class,
|
73
|
+
:async,
|
74
|
+
:is_background,
|
75
|
+
dependencies: [:id, statuses: []]
|
76
|
+
]
|
77
|
+
)[:operation]
|
61
78
|
end
|
62
79
|
|
63
|
-
def operations_collection
|
64
|
-
get_collection_ivar ||
|
65
|
-
set_collection_ivar(
|
66
|
-
end_of_association_chain.waiting.order(created_at: :desc)
|
67
|
-
)
|
68
|
-
end
|
69
80
|
|
70
|
-
def
|
71
|
-
|
72
|
-
OperationDecorator.decorate_collection(super)
|
73
|
-
else
|
74
|
-
scope = operations_collection
|
75
|
-
OperationDecorator.decorate_collection(scope)
|
76
|
-
end
|
81
|
+
def parent
|
82
|
+
@parent ||= params[:process_id] && Process.find(params[:process_id])
|
77
83
|
end
|
78
84
|
|
79
|
-
def
|
85
|
+
def set_operation
|
80
86
|
@operation ||= Operation::find(params[:id]).decorate
|
81
87
|
end
|
82
88
|
|