flexite 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/flexite/configs_controller.rb +2 -2
- data/app/controllers/flexite/entries_controller.rb +15 -11
- data/app/helpers/flexite/entries_helper.rb +1 -1
- data/app/services/flexite/action_service/result.rb +2 -0
- data/app/services/flexite/action_service.rb +13 -8
- data/app/services/flexite/config/create_service.rb +1 -1
- data/app/services/flexite/config/update_service.rb +1 -1
- data/app/services/flexite/entry/array_create_service.rb +16 -28
- data/app/services/flexite/entry/array_update_service.rb +34 -48
- data/app/services/flexite/entry/create_service.rb +1 -5
- data/app/services/flexite/entry/inner_processable.rb +32 -0
- data/app/services/flexite/entry/update_service.rb +1 -0
- data/app/views/flexite/entries/new_array_entry.js.haml +1 -1
- data/app/views/flexite/entries/update.js.haml +1 -0
- data/lib/flexite/version.rb +1 -1
- data/test/dummy/config/initializers/flexite.rb +1 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +34804 -0
- data/test/dummy/tmp/cache/assets/C67/060/sprockets%2Ffaf176441f0544dd2b51901280044b40 +0 -0
- data/test/dummy/tmp/cache/assets/C9D/530/sprockets%2Fdcd49c063327c12052812f41c20a8e74 +0 -0
- data/test/dummy/tmp/cache/assets/CA3/270/sprockets%2F502b740063f8ec15e7e12811da71c772 +0 -0
- data/test/dummy/tmp/cache/assets/CDC/060/sprockets%2F8ff1d307d1b36810549d0829722b7aea +0 -0
- data/test/dummy/tmp/cache/assets/CDE/120/sprockets%2F5fd8b3fa3724451579552aed373410ce +0 -0
- data/test/dummy/tmp/cache/assets/CF8/980/sprockets%2F4e5077b95460dc34d7c9d7d9880e7b47 +0 -0
- data/test/dummy/tmp/cache/assets/D00/4C0/sprockets%2F603c6d7b825c2f4a6422b3d4af4e6203 +0 -0
- data/test/dummy/tmp/cache/assets/D00/C40/sprockets%2F999847c008fb4ce26fff5607c39d8358 +0 -0
- data/test/dummy/tmp/cache/assets/D09/A30/sprockets%2F2a71e20a2f3544acb51956504cd8d8e9 +0 -0
- data/test/dummy/tmp/cache/assets/D0D/E60/sprockets%2F90ea9eaa4671ec2d76703bae31972634 +0 -0
- data/test/dummy/tmp/cache/assets/D2A/160/sprockets%2Fbe17d4d0be4b381500e2824bbe273d70 +0 -0
- data/test/dummy/tmp/cache/assets/D2E/700/sprockets%2Fb21f85e0940bbcb3a8914c9cb0b07218 +0 -0
- data/test/dummy/tmp/cache/assets/D39/CD0/sprockets%2F0e8f6981475e49ea9fe14698fa57e4e9 +0 -0
- data/test/dummy/tmp/cache/assets/D40/590/sprockets%2F181dd5673b58f1ec4c89e50028bfad60 +0 -0
- data/test/dummy/tmp/cache/assets/D46/870/sprockets%2Fd880bdf72c5d0009b88fda8521439dc8 +0 -0
- data/test/dummy/tmp/cache/assets/D48/5F0/sprockets%2Fe6a83afb2d92f4692ffb391b5285a518 +0 -0
- data/test/dummy/tmp/cache/assets/D4B/A20/sprockets%2Febde89014596e655c35df9c4a01ee636 +0 -0
- data/test/dummy/tmp/cache/assets/D54/A50/sprockets%2Ff49839d906f69fd92904ebac07a3a38e +0 -0
- data/test/dummy/tmp/cache/assets/D69/B50/sprockets%2F4186e2787004e19ceb0c4afed46cf04b +0 -0
- data/test/dummy/tmp/cache/assets/D6D/C20/sprockets%2F112e96fea93f5f1e31d2077f1cdaf283 +0 -0
- data/test/dummy/tmp/cache/assets/D7A/8F0/sprockets%2F8eefc5f9824d950317a5c4a2e68b3c4e +0 -0
- data/test/dummy/tmp/cache/assets/DB3/360/sprockets%2F24b1f98ad736884b91d6ebeb2fc68ed8 +0 -0
- data/test/dummy/tmp/cache/assets/DD2/E90/sprockets%2Ff01f48c96ba588d15b20dd57ed3ccb7f +0 -0
- data/test/dummy/tmp/cache/assets/DEE/0C0/sprockets%2Feedcd74856542eedb5ea3ab1b1502ca4 +0 -0
- data/test/dummy/tmp/cache/assets/DF1/210/sprockets%2Ff4fe7dba1445ba1b668aaa1bd34ca984 +0 -0
- data/test/dummy/tmp/cache/assets/E44/790/sprockets%2Fefb8d8ea9e97da9d675a8bfa1d5de343 +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63dfd3a5a6e385f71c19663ad3baa5638e8fc29e
|
4
|
+
data.tar.gz: 189ee657807f3b2d7e502a542252c57b6993db85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12025176c14c3c4ef1559e9cfc385181fc37e319c7732ddc07319ed6101932e4062684038106257df654d19cce3709d7527da1faf81719441b895f958b38c4b0
|
7
|
+
data.tar.gz: 6b712735f3a2e606f2ca5ee2a20fc5de1de6dfbed5a4edb248b23f3d8a17f1af3fddf610d4a41e5fb3a930e516b545754b97e29394e947403715255dafd9e7ec
|
@@ -18,7 +18,7 @@ module Flexite
|
|
18
18
|
result = ServiceFactory.instance.get(:config_create, Config::Form.new(config_params)).call
|
19
19
|
|
20
20
|
if result.succeed?
|
21
|
-
@node = result.
|
21
|
+
@node = result.record.to_tree_node
|
22
22
|
@parent_id = config_params[:config_id]
|
23
23
|
end
|
24
24
|
|
@@ -34,7 +34,7 @@ module Flexite
|
|
34
34
|
result = ServiceFactory.instance.get(:update_config, Config::Form.new(config_params)).call
|
35
35
|
|
36
36
|
if result.succeed?
|
37
|
-
@node = result.
|
37
|
+
@node = result.record.to_tree_node
|
38
38
|
end
|
39
39
|
|
40
40
|
service_flash(result)
|
@@ -10,12 +10,10 @@ module Flexite
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def create
|
13
|
-
|
14
|
-
form = klass.form(entry_params)
|
15
|
-
result = ServiceFactory.instance.get(klass.service(:create), form).call
|
13
|
+
result = call_service_for(:create, entry_params)
|
16
14
|
|
17
15
|
if result.succeed?
|
18
|
-
@entry = result.
|
16
|
+
@entry = result.record
|
19
17
|
@entry_form = @entry.class.form(@entry.form_attributes)
|
20
18
|
end
|
21
19
|
|
@@ -29,16 +27,18 @@ module Flexite
|
|
29
27
|
end
|
30
28
|
|
31
29
|
def update
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
result = call_service_for(:update, entry_params)
|
31
|
+
@entry = Entry.find(entry_params[:id])
|
32
|
+
@entry_form = @entry.class.form(@entry.form_attributes)
|
35
33
|
service_flash(result)
|
36
34
|
service_response(result)
|
37
35
|
end
|
38
36
|
|
39
37
|
def new_array_entry
|
40
38
|
klass = params[:type].constantize
|
41
|
-
|
39
|
+
|
40
|
+
@prefix = params[:prefix]
|
41
|
+
@form_options = [@prefix]
|
42
42
|
|
43
43
|
if (@form_index = params[:form_index]).present?
|
44
44
|
@form_options << { index: @form_index }
|
@@ -57,9 +57,7 @@ module Flexite
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def destroy
|
60
|
-
|
61
|
-
form = klass.form(id: params[:id])
|
62
|
-
result = ServiceFactory.instance.get(klass.service(:destroy), form).call
|
60
|
+
result = call_service_for(:destroy, params)
|
63
61
|
|
64
62
|
if result.succeed?
|
65
63
|
@parent_id = result.data[:parent_id]
|
@@ -78,5 +76,11 @@ module Flexite
|
|
78
76
|
def entry_params
|
79
77
|
params[:entry]
|
80
78
|
end
|
79
|
+
|
80
|
+
def call_service_for(type, entry)
|
81
|
+
klass = entry[:type].constantize
|
82
|
+
form = klass.form(entry)
|
83
|
+
ServiceFactory.instance.get(klass.service(type), form).call
|
84
|
+
end
|
81
85
|
end
|
82
86
|
end
|
@@ -9,7 +9,7 @@ module Flexite
|
|
9
9
|
].freeze
|
10
10
|
|
11
11
|
def render_entries(entries, form)
|
12
|
-
content_tag :div, id: "array-entries-#{form.options[:index]}" do
|
12
|
+
content_tag :div, id: "#{form.object_name}-array-entries-#{form.options[:index]}" do
|
13
13
|
entries.each_with_index do |entry, index|
|
14
14
|
concat render_entry(entry, form, index)
|
15
15
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class Flexite::ActionService
|
2
|
-
|
3
|
-
|
4
|
-
end
|
2
|
+
extend ActiveSupport::Autoload
|
3
|
+
autoload :Result
|
5
4
|
|
6
5
|
def initialize(form, params = {})
|
7
6
|
@form = form
|
@@ -14,12 +13,9 @@ class Flexite::ActionService
|
|
14
13
|
|
15
14
|
protected
|
16
15
|
|
17
|
-
def success
|
18
|
-
raise NotImplementedError
|
19
|
-
end
|
20
|
-
|
21
16
|
def failure
|
22
|
-
|
17
|
+
save_errors
|
18
|
+
Result.new(success: false, endpoint: { status: 400 })
|
23
19
|
end
|
24
20
|
|
25
21
|
def save_errors(result)
|
@@ -27,4 +23,13 @@ class Flexite::ActionService
|
|
27
23
|
result.add_errors(key, values)
|
28
24
|
end
|
29
25
|
end
|
26
|
+
|
27
|
+
def save_inner_service_errors(result, inner_result)
|
28
|
+
return if inner_result.errors.blank?
|
29
|
+
result.options[:succeed] = false if result.succeed?
|
30
|
+
|
31
|
+
inner_result.errors.each do |name, values|
|
32
|
+
result.add_errors(name, values)
|
33
|
+
end
|
34
|
+
end
|
30
35
|
end
|
@@ -3,6 +3,8 @@ require_dependency 'flexite/action_service'
|
|
3
3
|
module Flexite
|
4
4
|
class Entry
|
5
5
|
class ArrayCreateService < ActionService
|
6
|
+
include InnerProcessable
|
7
|
+
|
6
8
|
def call
|
7
9
|
if @form.invalid?
|
8
10
|
return failure
|
@@ -19,51 +21,37 @@ module Flexite
|
|
19
21
|
record.parent_type = @form.parent_type
|
20
22
|
end
|
21
23
|
|
22
|
-
Entry.transaction do
|
23
|
-
create_entries(@form.new_entries
|
24
|
+
Entry.transaction(requires_new: true) do
|
25
|
+
create_entries(@form.new_entries)
|
26
|
+
end
|
27
|
+
|
28
|
+
if @process_result.succeed?
|
29
|
+
@process_result.options[:data] = @record
|
24
30
|
end
|
25
31
|
|
26
|
-
|
27
|
-
rescue => exc
|
28
|
-
exc_failure(exc)
|
32
|
+
process_result('Entry was created')
|
29
33
|
end
|
30
34
|
|
31
|
-
def create_entries(new_entries
|
35
|
+
def create_entries(new_entries)
|
32
36
|
return if new_entries.blank?
|
33
37
|
|
34
38
|
new_entries.each do |_, entry|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
save_entry(entry, parent_id)
|
39
|
-
end
|
39
|
+
entry[:parent_id] = @record.id
|
40
|
+
entry[:parent_type] = @form.type.constantize.base_class.sti_name
|
41
|
+
save_entry(entry)
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
def
|
44
|
-
|
45
|
-
record = klass.create({ parent_id: parent_id, parent_type: klass.base_class.sti_name }, without_protection: true)
|
46
|
-
create_entries(entry[:new_entries], record.id)
|
47
|
-
end
|
48
|
-
|
49
|
-
def save_entry(entry, parent_id)
|
50
|
-
klass = entry[:type].constantize
|
51
|
-
klass.create({ parent_id: parent_id, parent_type: klass.base_class.sti_name, value: entry[:value] }, without_protection: true)
|
45
|
+
def save_entry(entry)
|
46
|
+
call_service_for(:create, entry)
|
52
47
|
end
|
53
48
|
|
54
49
|
protected
|
55
50
|
|
56
51
|
def failure
|
52
|
+
save_errors
|
57
53
|
Result.new(success: false, endpoint: { status: 400 })
|
58
54
|
end
|
59
|
-
|
60
|
-
def exc_failure(exc)
|
61
|
-
Result.new(success: false, message: exc.message, endpoint: { status: 500 })
|
62
|
-
end
|
63
|
-
|
64
|
-
def success
|
65
|
-
Result.new(flash: { type: :success, message: 'Entry was created!' }, data: { record: @record })
|
66
|
-
end
|
67
55
|
end
|
68
56
|
end
|
69
57
|
end
|
@@ -1,69 +1,55 @@
|
|
1
1
|
require_dependency 'flexite/action_service'
|
2
2
|
|
3
3
|
module Flexite
|
4
|
-
class Entry
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class Entry
|
5
|
+
class ArrayUpdateService < ActionService
|
6
|
+
include InnerProcessable
|
7
|
+
|
8
|
+
def call
|
9
|
+
if @form.invalid?
|
10
|
+
return failure
|
11
|
+
end
|
12
|
+
|
13
|
+
process_entry
|
8
14
|
end
|
9
15
|
|
10
|
-
|
11
|
-
end
|
16
|
+
private
|
12
17
|
|
13
|
-
|
18
|
+
def process_entry
|
19
|
+
Entry.transaction(requires_new: true) do
|
20
|
+
update_entries(@form.entries)
|
21
|
+
create_entries
|
22
|
+
end
|
14
23
|
|
15
|
-
|
16
|
-
Entry.transaction do
|
17
|
-
update_entries(@form.entries)
|
18
|
-
create_entries(@form.new_entries, @form.id)
|
24
|
+
process_result('Entry was updated')
|
19
25
|
end
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
exc_failure(exc)
|
24
|
-
end
|
25
|
-
|
26
|
-
def update_entries(entries)
|
27
|
-
entries.each do |_, entry|
|
28
|
-
if respond_to?("save_#{entry[:type].demodulize.underscore}", true)
|
29
|
-
send("save_#{entry[:type].demodulize.underscore}", entry)
|
30
|
-
else
|
27
|
+
def update_entries(entries)
|
28
|
+
entries.each do |_, entry|
|
31
29
|
save_entry(entry)
|
32
30
|
end
|
33
31
|
end
|
34
|
-
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
new_entries.each do |_, entry|
|
40
|
-
klass = entry[:type].constantize
|
41
|
-
klass.create({parent_id: parent_id, parent_type: klass.base_class.sti_name, value: entry[:value]}, without_protection: true)
|
33
|
+
def save_entry(entry)
|
34
|
+
call_service_for(:update, entry)
|
42
35
|
end
|
43
|
-
end
|
44
36
|
|
37
|
+
def create_entries
|
38
|
+
return if @form.new_entries.blank?
|
45
39
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
entry[:type].constantize.update(entry[:id], value: entry[:value])
|
53
|
-
end
|
54
|
-
|
55
|
-
protected
|
56
|
-
|
57
|
-
def failure
|
58
|
-
Result.new(success: false, endpoint: { status: 400 })
|
59
|
-
end
|
40
|
+
@form.new_entries.each do |_, entry|
|
41
|
+
entry[:parent_id] = @form.id
|
42
|
+
entry[:parent_type] = @form.type.constantize.base_class.sti_name
|
43
|
+
call_service_for(:create, entry)
|
44
|
+
end
|
45
|
+
end
|
60
46
|
|
61
|
-
|
62
|
-
Result.new(success: false, message: exc.message, endpoint: { status: 500 })
|
63
|
-
end
|
47
|
+
protected
|
64
48
|
|
65
|
-
|
66
|
-
|
49
|
+
def failure
|
50
|
+
save_errors
|
51
|
+
Result.new(success: false, endpoint: { status: 400 })
|
52
|
+
end
|
67
53
|
end
|
68
54
|
end
|
69
55
|
end
|
@@ -20,11 +20,7 @@ module Flexite
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def success
|
23
|
-
Result.new(flash: { type: :success, message: 'Entry was created!' }, data:
|
24
|
-
end
|
25
|
-
|
26
|
-
def failure
|
27
|
-
Result.new(success: false, endpoint: { status: 400 })
|
23
|
+
Result.new(flash: { type: :success, message: 'Entry was created!' }, data: @record)
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Flexite
|
2
|
+
class Entry
|
3
|
+
module InnerProcessable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def initialize(*)
|
7
|
+
super
|
8
|
+
@process_result = ActionService::Result.new
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def call_service_for(type, entry)
|
14
|
+
klass = entry[:type].constantize
|
15
|
+
form = klass.form(entry)
|
16
|
+
result = ServiceFactory.instance.get(klass.service(type), form).call
|
17
|
+
|
18
|
+
if result.failed?
|
19
|
+
save_inner_service_errors(@process_result, result)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_result(success_message)
|
24
|
+
if @process_result.succeed?
|
25
|
+
@process_result.options[:flash] = { type: :success, message: success_message }
|
26
|
+
end
|
27
|
+
|
28
|
+
@process_result
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
$flexite("#array-entries-#{@form_index}").append("#{j render 'new_array_entry_form'}");
|
1
|
+
$flexite("[id='#{@prefix}-array-entries-#{@form_index}']").append("#{j render 'new_array_entry_form'}");
|
data/lib/flexite/version.rb
CHANGED
Binary file
|