Skip to content

Commit 3f42eb0

Browse files
committed
process templates export /import
1 parent 797d786 commit 3f42eb0

File tree

23 files changed

+522
-13
lines changed

23 files changed

+522
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
## Unreleased:
1+
## 0.3.0:
2+
* configuration export / import
23
* Custom context view for operations (can be specified on operaiton templates)
34
* removed dependency from inherited_resources
45
* removed dependency from devise

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ gem "slim-rails"
66
gem "jquery-rails"
77
gem "jquery-ui-rails"
88
gem "draper"
9+
gem "active_model_serializers"
10+
gem 'guid'
911
gem "will_paginate"
1012
gem "sidekiq"
1113

Gemfile.lock

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
PATH
22
remote: .
33
specs:
4-
rails_workflow (0.2.2)
4+
rails_workflow (0.3.0)
5+
active_model_serializers
56
bootstrap-rails-engine
67
draper
8+
guid
79
jquery-rails
810
pg
911
rails (>= 4.1.0)
@@ -33,6 +35,8 @@ GEM
3335
erubis (~> 2.7.0)
3436
rails-dom-testing (~> 1.0, >= 1.0.5)
3537
rails-html-sanitizer (~> 1.0, >= 1.0.1)
38+
active_model_serializers (0.8.3)
39+
activemodel (>= 3.0)
3640
activejob (4.2.0)
3741
activesupport (= 4.2.0)
3842
globalid (>= 0.3.0)
@@ -84,7 +88,7 @@ GEM
8488
railties (>= 3.0.0)
8589
globalid (0.3.3)
8690
activesupport (>= 4.1.0)
87-
hike (1.2.3)
91+
guid (0.1.1)
8892
hitimes (1.2.2)
8993
i18n (0.7.0)
9094
jquery-rails (4.0.3)
@@ -101,7 +105,6 @@ GEM
101105
mime-types (2.4.3)
102106
mini_portile (0.6.2)
103107
minitest (5.5.1)
104-
multi_json (1.11.0)
105108
nokogiri (1.6.6.2)
106109
mini_portile (~> 0.6.0)
107110
orm_adapter (0.5.0)
@@ -178,12 +181,9 @@ GEM
178181
activesupport (>= 3.1, < 5.0)
179182
railties (>= 3.1, < 5.0)
180183
slim (~> 3.0)
181-
sprockets (2.12.3)
182-
hike (~> 1.2)
183-
multi_json (~> 1.0)
184+
sprockets (3.2.0)
184185
rack (~> 1.0)
185-
tilt (~> 1.1, != 1.3.0)
186-
sprockets-rails (2.2.4)
186+
sprockets-rails (2.3.1)
187187
actionpack (>= 3.0)
188188
activesupport (>= 3.0)
189189
sprockets (>= 2.8, < 4.0)
@@ -205,11 +205,13 @@ PLATFORMS
205205
ruby
206206

207207
DEPENDENCIES
208+
active_model_serializers
208209
bootstrap-rails-engine
209210
capybara
210211
devise
211212
draper
212213
factory_girl_rails
214+
guid
213215
jquery-rails
214216
jquery-ui-rails
215217
pg
@@ -219,3 +221,6 @@ DEPENDENCIES
219221
sinatra
220222
slim-rails
221223
will_paginate
224+
225+
BUNDLED WITH
226+
1.10.3

app/assets/stylesheets/rails_workflow/application.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,27 @@ body {
195195
.alert {
196196
border-radius: 4px;
197197
}
198+
199+
.btn-file {
200+
position: relative;
201+
overflow: hidden;
202+
}
203+
.btn-file input[type=file] {
204+
position: absolute;
205+
top: 0;
206+
right: 0;
207+
min-width: 100%;
208+
min-height: 100%;
209+
font-size: 100px;
210+
text-align: right;
211+
filter: alpha(opacity=0);
212+
opacity: 0;
213+
outline: none;
214+
background: white;
215+
cursor: inherit;
216+
display: block;
217+
}
218+
219+
.float-right {
220+
float: right;
221+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module RailsWorkflow::Uuid
2+
extend ActiveSupport::Concern
3+
4+
included do
5+
before_save :generate_guid
6+
end
7+
8+
def generate_guid
9+
if uuid.blank?
10+
self.uuid = Guid.new.to_s
11+
end
12+
13+
end
14+
end

app/controllers/rails_workflow/process_templates_controller.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
module RailsWorkflow
22
class ProcessTemplatesController < ::ActionController::Base
33
layout 'rails_workflow/application'
4-
respond_to :html
4+
respond_to :html, :json
55

66
before_action :set_process_template, only: [:show, :edit, :update, :destroy]
77

88
before_filter do
99
@config_section_active = true
1010
end
1111

12+
def upload
13+
uploaded = params[:import_file]
14+
15+
json = JSON.parse(uploaded.read)
16+
17+
importer = RailsWorkflow::ProcessImporter.new(json)
18+
importer.process
19+
20+
redirect_to process_templates_path
21+
end
22+
23+
def export
24+
template = ProcessTemplate.find(params[:id])
25+
send_data render_to_string(json: template, serializer: ProcessTemplateSerializer), filename: "#{template.title}.json"
26+
end
1227

1328
def index
1429
@process_templates = ProcessTemplateDecorator.

app/models/rails_workflow/operation_template.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module RailsWorkflow
22
class OperationTemplate < ActiveRecord::Base
33
include OperationStatus
4+
include RailsWorkflow::Uuid
45
include OperationTemplates::Dependencies
56
include OperationTemplates::Assignments
67
include OperationTemplates::DefaultBuilder

app/models/rails_workflow/process_template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module RailsWorkflow
22
class ProcessTemplate < ActiveRecord::Base
33
include ProcessTemplates::DefaultBuilder
4-
4+
include RailsWorkflow::Uuid
55
has_many :operations, :class_name => 'OperationTemplate'
66

77

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module RailsWorkflow
2+
class OperationTemplateSerializer < ActiveModel::Serializer
3+
attributes :uuid, :title, :source, :dependencies, :operation_class,
4+
:async, :assignment_id, :assignment_type, :kind, :role, :group, :instruction,
5+
:is_background, :type, :partial_name, :version, :tag
6+
7+
has_one :child_process, serializer: RailsWorkflow::OperationTemplateSerializer
8+
9+
def dependencies
10+
object.dependencies.each do |d|
11+
d['uuid'] = OperationTemplate.find(d['id']).uuid
12+
d.delete("id")
13+
end
14+
end
15+
16+
def operation_class
17+
object.read_attribute :operation_class
18+
end
19+
20+
end
21+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module RailsWorkflow
2+
class ProcessTemplateSerializer < ActiveModel::Serializer
3+
attributes :uuid, :title, :source,
4+
:manager_class, :process_class, :type,
5+
:partial_name, :version, :tag
6+
7+
has_many :operations, serializer: RailsWorkflow::OperationTemplateSerializer
8+
9+
10+
def process_class
11+
object.read_attribute :process_class
12+
end
13+
14+
def manager_class
15+
object.read_attribute :manager_class
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)