flexite 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +12 -0
- data/Rakefile +40 -0
- data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.svg +288 -0
- data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/app/assets/images/flexite/glyphicons-halflings-white.png +0 -0
- data/app/assets/images/flexite/glyphicons-halflings.png +0 -0
- data/app/assets/javascripts/flexite/application.js +18 -0
- data/app/assets/javascripts/flexite/bootstrap.min.js +7 -0
- data/app/assets/javascripts/flexite/common.js.erb +2 -0
- data/app/assets/javascripts/flexite/jquery.min.js +2 -0
- data/app/assets/javascripts/flexite/tree.js.erb +83 -0
- data/app/assets/javascripts/flexite/treeview.js +1335 -0
- data/app/assets/stylesheets/flexite/application.css +29 -0
- data/app/assets/stylesheets/flexite/bootstrap-treeview.min.css +1 -0
- data/app/assets/stylesheets/flexite/bootstrap.min.css +5 -0
- data/app/assets/stylesheets/flexite/configs.css +8 -0
- data/app/assets/stylesheets/flexite/entries.css +4 -0
- data/app/assets/stylesheets/flexite/tree.css +21 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/flexite/application_controller.rb +25 -0
- data/app/controllers/flexite/configs_controller.rb +61 -0
- data/app/controllers/flexite/entries_controller.rb +82 -0
- data/app/factories/flexite/base_factory.rb +7 -0
- data/app/factories/flexite/service_factory.rb +19 -0
- data/app/forms/flexite/base_form.rb +24 -0
- data/app/forms/flexite/config/form.rb +12 -0
- data/app/forms/flexite/entry/array_form.rb +11 -0
- data/app/forms/flexite/entry/form.rb +16 -0
- data/app/helpers/flexite/application_helper.rb +15 -0
- data/app/helpers/flexite/configs_helper.rb +4 -0
- data/app/helpers/flexite/entries_helper.rb +46 -0
- data/app/models/flexite/arr_entry.rb +35 -0
- data/app/models/flexite/bool_entry.rb +19 -0
- data/app/models/flexite/config.rb +64 -0
- data/app/models/flexite/entry.rb +30 -0
- data/app/models/flexite/int_entry.rb +13 -0
- data/app/models/flexite/str_entry.rb +2 -0
- data/app/models/flexite/sym_entry.rb +17 -0
- data/app/services/flexite/action_service/result.rb +44 -0
- data/app/services/flexite/action_service.rb +30 -0
- data/app/services/flexite/config/create_service.rb +25 -0
- data/app/services/flexite/config/update_service.rb +28 -0
- data/app/services/flexite/data/hash.rb +17 -0
- data/app/services/flexite/data/migrators/yaml.rb +62 -0
- data/app/services/flexite/data/new.rb +87 -0
- data/app/services/flexite/entry/array_create_service.rb +69 -0
- data/app/services/flexite/entry/array_update_service.rb +69 -0
- data/app/services/flexite/entry/create_service.rb +31 -0
- data/app/services/flexite/entry/destroy_array_entry_service.rb +25 -0
- data/app/services/flexite/entry/destroy_service.rb +22 -0
- data/app/services/flexite/entry/update_service.rb +26 -0
- data/app/simple_form/array_input.rb +13 -0
- data/app/views/flexite/application/index.html.haml +14 -0
- data/app/views/flexite/configs/_form.html.haml +7 -0
- data/app/views/flexite/configs/create.js.haml +3 -0
- data/app/views/flexite/configs/edit.js.haml +1 -0
- data/app/views/flexite/configs/index.json.erb +10 -0
- data/app/views/flexite/configs/new.js.haml +1 -0
- data/app/views/flexite/configs/update.js.haml +2 -0
- data/app/views/flexite/entries/_form.html.haml +11 -0
- data/app/views/flexite/entries/_new_array_entry_form.html.haml +7 -0
- data/app/views/flexite/entries/_popup.html.haml +18 -0
- data/app/views/flexite/entries/_types_dropdown.html.haml +8 -0
- data/app/views/flexite/entries/create.js.haml +4 -0
- data/app/views/flexite/entries/destroy.js.haml +4 -0
- data/app/views/flexite/entries/destroy_array_entry.js.haml +6 -0
- data/app/views/flexite/entries/edit.js.haml +1 -0
- data/app/views/flexite/entries/new.js.haml +1 -0
- data/app/views/flexite/entries/new_array_entry.js.haml +1 -0
- data/app/views/flexite/entries/select_type.js.haml +1 -0
- data/app/views/flexite/entries/types/_arr_entry.html.haml +19 -0
- data/app/views/flexite/entries/types/_bool_entry.html.haml +4 -0
- data/app/views/flexite/entries/types/_int_entry.html.haml +4 -0
- data/app/views/flexite/entries/types/_str_entry.html.haml +4 -0
- data/app/views/flexite/entries/types/_sym_entry.html.haml +1 -0
- data/app/views/flexite/entries/update.js.haml +1 -0
- data/app/views/flexite/shared/_messages.html.haml +5 -0
- data/app/views/flexite/shared/_show_flash.js.haml +5 -0
- data/app/views/layouts/flexite/application.html.haml +11 -0
- data/config/initializers/simple_form.rb +143 -0
- data/config/initializers/simple_form_bootstrap.rb +43 -0
- data/config/locales/simple_form.en.yml +26 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20180503102555_create_flexite_configs.rb +14 -0
- data/db/migrate/20180503103109_create_flexite_entries.rb +14 -0
- data/lib/flexite/cached_node.rb +19 -0
- data/lib/flexite/configuration.rb +24 -0
- data/lib/flexite/engine.rb +18 -0
- data/lib/flexite/flexy.rb +13 -0
- data/lib/flexite/nodes_hash.rb +5 -0
- data/lib/flexite/version.rb +3 -0
- data/lib/flexite.rb +44 -0
- data/lib/tasks/flexite_tasks.rake +20 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/application.yml +599 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +40 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/flexite.rb +5 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +39 -0
- data/test/dummy/db/seeds.rb +3 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +86588 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -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
- data/test/fixtures/flexite/configs.yml +7 -0
- data/test/fixtures/flexite/entries.yml +13 -0
- data/test/flexite_test.rb +7 -0
- data/test/functional/flexite/configs_controller_test.rb +51 -0
- data/test/functional/flexite/entries_controller_test.rb +51 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/flexite/config_test.rb +9 -0
- data/test/unit/flexite/entry_test.rb +9 -0
- data/test/unit/helpers/flexite/configs_helper_test.rb +6 -0
- data/test/unit/helpers/flexite/entries_helper_test.rb +6 -0
- metadata +366 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require_dependency 'flexite/action_service'
|
2
|
+
|
3
|
+
module Flexite
|
4
|
+
class Entry::ArrayUpdateService < ActionService
|
5
|
+
def call
|
6
|
+
if @form.invalid?
|
7
|
+
return failure
|
8
|
+
end
|
9
|
+
|
10
|
+
process_entries
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def process_entries
|
16
|
+
Entry.transaction do
|
17
|
+
update_entries(@form.entries)
|
18
|
+
create_entries(@form.new_entries, @form.id)
|
19
|
+
end
|
20
|
+
|
21
|
+
success
|
22
|
+
rescue => exc
|
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
|
31
|
+
save_entry(entry)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_entries(new_entries, parent_id)
|
37
|
+
return if new_entries.blank?
|
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)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def save_arr_entry(entry)
|
47
|
+
update_entries(entry[:entries])
|
48
|
+
create_entries(entry[:new_entries], entry[:id])
|
49
|
+
end
|
50
|
+
|
51
|
+
def save_entry(entry)
|
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
|
60
|
+
|
61
|
+
def exc_failure(exc)
|
62
|
+
Result.new(success: false, message: exc.message, endpoint: { status: 500 })
|
63
|
+
end
|
64
|
+
|
65
|
+
def success
|
66
|
+
Result.new(flash: { type: :success, message: 'Entry was updated!' })
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_dependency 'flexite/action_service'
|
2
|
+
|
3
|
+
module Flexite
|
4
|
+
class Entry
|
5
|
+
class CreateService < ActionService
|
6
|
+
def call
|
7
|
+
if @form.invalid?
|
8
|
+
return failure
|
9
|
+
end
|
10
|
+
|
11
|
+
@record = @form.type.constantize.create do |record|
|
12
|
+
record.value = @form.value
|
13
|
+
record.parent_id = @form.parent_id
|
14
|
+
record.parent_type = @form.parent_type
|
15
|
+
end
|
16
|
+
|
17
|
+
success
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def success
|
23
|
+
Result.new(flash: { type: :success, message: 'Entry was created!' }, data: { record: @record })
|
24
|
+
end
|
25
|
+
|
26
|
+
def failure
|
27
|
+
Result.new(success: false, endpoint: { status: 400 })
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_dependency 'flexite/action_service'
|
2
|
+
|
3
|
+
module Flexite
|
4
|
+
class Entry
|
5
|
+
class DestroyArrayEntryService < ActionService
|
6
|
+
def call
|
7
|
+
if @form.id.present?
|
8
|
+
Entry.destroy(@form.id)
|
9
|
+
end
|
10
|
+
|
11
|
+
success
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def failure
|
17
|
+
Result.new(success: false, endpoint: { status: 400 })
|
18
|
+
end
|
19
|
+
|
20
|
+
def success
|
21
|
+
Result.new(flash: { type: :success, message: 'Entry was deleted!' })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_dependency 'flexite/action_service'
|
2
|
+
|
3
|
+
module Flexite
|
4
|
+
class Entry
|
5
|
+
class DestroyService < ActionService
|
6
|
+
def call
|
7
|
+
@record = Entry.destroy(@form.id)
|
8
|
+
success
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def failure
|
14
|
+
Result.new(success: false, endpoint: { status: 400 })
|
15
|
+
end
|
16
|
+
|
17
|
+
def success
|
18
|
+
Result.new(flash: { type: :success, message: 'Entry was deleted!' }, data: { parent_id: @record.parent_id })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_dependency 'flexite/action_service'
|
2
|
+
|
3
|
+
module Flexite
|
4
|
+
class Entry::UpdateService < ActionService
|
5
|
+
def call
|
6
|
+
if @form.invalid?
|
7
|
+
return failure
|
8
|
+
end
|
9
|
+
|
10
|
+
@form.type.constantize.update(@form.id, value: @form.value)
|
11
|
+
success
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def failure
|
19
|
+
Result.new(success: false, endpoint: { status: 400 })
|
20
|
+
end
|
21
|
+
|
22
|
+
def success
|
23
|
+
Result.new(flash: { type: :success, message: 'Entry was updated!' })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ArrayInput < SimpleForm::Inputs::StringInput
|
2
|
+
def input
|
3
|
+
input_html_options[:type] ||= input_type
|
4
|
+
|
5
|
+
Array(object.public_send(attribute_name)).map do |array_el|
|
6
|
+
@builder.text_field(nil, input_html_options.merge(value: array_el, name: "#{object_name}[#{attribute_name}][]"))
|
7
|
+
end.join.html_safe
|
8
|
+
end
|
9
|
+
|
10
|
+
def input_type
|
11
|
+
:text
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#tree-buttons.row
|
2
|
+
.col-md-4.pos-fixed
|
3
|
+
%button#new-node-btn.btn.btn-success New node
|
4
|
+
%button#edit-node-btn.btn.btn-success Edit node
|
5
|
+
%button#delete-node-btn.btn.btn-danger Delete
|
6
|
+
= link_to 'Reload cache', reload_configs_path, remote: true, class: 'btn btn-info'
|
7
|
+
= back_to_app
|
8
|
+
.row#tree-container
|
9
|
+
.col-md-4
|
10
|
+
#tree
|
11
|
+
.col-md-4
|
12
|
+
#section-2.pos-fixed
|
13
|
+
.col-md-4
|
14
|
+
#section-3.pos-fixed
|
@@ -0,0 +1,7 @@
|
|
1
|
+
= simple_form_for @config_form, remote: true do |f|
|
2
|
+
= f.input :id, as: :hidden
|
3
|
+
= f.input :name, as: :string, input_html: { class: 'form-control', placeholder: 'Name' }, label: false
|
4
|
+
= f.input :config_id, collection: Flexite::Config.not_selectable, label_method: :name, value_method: :id,
|
5
|
+
input_html: { class: 'form-control', placeholder: 'Parent' }, label: false, prompt: 'Select parent'
|
6
|
+
= f.input :selectable, as: :boolean, label: false, wrapper_html: { class: 'checkbox' }
|
7
|
+
= f.button :submit, class: 'btn btn-success'
|
@@ -0,0 +1 @@
|
|
1
|
+
$flexite("#section-2").html("#{j render 'form'}")
|
@@ -0,0 +1 @@
|
|
1
|
+
$flexite("#section-2").html("#{j render 'form'}")
|
@@ -0,0 +1,11 @@
|
|
1
|
+
= simple_form_for @entry_form, remote: true do |f|
|
2
|
+
- if @entry_form.type.present?
|
3
|
+
= render "types/#{@entry_form.view_type}", f: f
|
4
|
+
= f.input :id, as: :hidden
|
5
|
+
= f.input :type, as: :hidden
|
6
|
+
= f.input :parent_id, as: :hidden
|
7
|
+
= f.input :parent_type, as: :hidden
|
8
|
+
= f.button :submit, class: 'btn btn-success'
|
9
|
+
|
10
|
+
- if @entry_form.persisted?
|
11
|
+
= link_to 'Delete', entry_path(f.object, type: @entry_form.type), method: :delete, remote: true, class: 'btn btn-danger'
|
@@ -0,0 +1,7 @@
|
|
1
|
+
= simple_fields_for *@form_options do |f|
|
2
|
+
= f.simple_fields_for :new_entries, @entry_form, index: @index do |f|
|
3
|
+
%div{ id: "#{f.object_name}-#{@index}" }
|
4
|
+
= f.input :type, as: :hidden
|
5
|
+
= render "types/#{@entry_form.view_type}", f: f,
|
6
|
+
delete_link: link_to('Delete', destroy_array_entries_path(id: nil, type: @entry_form.type, selector: "#{f.object_name}-#{@index}"),
|
7
|
+
remote: true, method: :delete, class: 'btn btn-danger')
|
@@ -0,0 +1,18 @@
|
|
1
|
+
.modal.fade#edit-entry{ role: :dialog, aria: { hidden: 'true' } }
|
2
|
+
.modal-dialog
|
3
|
+
.modal-content
|
4
|
+
.modal-header
|
5
|
+
%button.close{ type: :button, data: { dismiss: :modal }, aria: { label: 'Close' } }
|
6
|
+
%span{ aria: { hidden: 'true' } }
|
7
|
+
×
|
8
|
+
%h4.modal-title#edit-entry-title
|
9
|
+
.modal-body#edit-entry-body
|
10
|
+
.modal-footer
|
11
|
+
%button.btn.btn-primary{ onclick: "$flexite('form[id^=edit_entry]').submit();" } Save
|
12
|
+
%button.btn.btn-secondary{ data: { dismiss: :modal } } Close
|
13
|
+
|
14
|
+
:javascript
|
15
|
+
$flexite("#edit-entry").on("hidden.bs.modal", function () {
|
16
|
+
$flexite("#edit-entry #edit-entry-title").text("");
|
17
|
+
$flexite("#edit-entry-body").html("");
|
18
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
= form_for :entry, url: new_entry_path, remote: true, method: 'GET' do |f|
|
2
|
+
= f.hidden_field :parent_id, value: @config.id
|
3
|
+
= f.hidden_field :parent_type, value: @config.class.name
|
4
|
+
.form-inline
|
5
|
+
= entry_type_select(f)
|
6
|
+
= f.submit 'Add entry', class: 'btn btn-success'
|
7
|
+
|
8
|
+
#new-entry
|
@@ -0,0 +1 @@
|
|
1
|
+
$flexite("#section-2").html("#{j render 'form'}")
|
@@ -0,0 +1 @@
|
|
1
|
+
$flexite("#section-2 #new-entry").html("#{j render 'form'}")
|
@@ -0,0 +1 @@
|
|
1
|
+
$flexite("#array-entries-#{@form_index}").append("#{j render 'new_array_entry_form'}");
|
@@ -0,0 +1 @@
|
|
1
|
+
$flexite("#section-2").html("#{j render 'types_dropdown'}")
|
@@ -0,0 +1,19 @@
|
|
1
|
+
= render_entries(f.object.entries, f)
|
2
|
+
|
3
|
+
.form-group.form-inline
|
4
|
+
= entry_type_select
|
5
|
+
= f.button :button, 'Add entry', type: :button, class: 'btn btn-success', id: "add_array_entry-#{f.object.id}"
|
6
|
+
- if local_assigns[:delete_link].present?
|
7
|
+
= delete_link
|
8
|
+
|
9
|
+
-# TODO: fix index population related to array entry vs simple entry
|
10
|
+
:javascript
|
11
|
+
$flexite("#add_array_entry-#{f.object.id}").on("click", function () {
|
12
|
+
$flexite.get("#{new_array_entries_path}", {
|
13
|
+
parent_id: "#{f.object.id}",
|
14
|
+
form_index: "#{f.options[:index]}",
|
15
|
+
prefix: "#{f.object_name}",
|
16
|
+
index: $flexite("[id^='entry_new_entries_'][id$='_value']").size(),
|
17
|
+
type: $flexite(this).parent().find("#new_entry_type").val()
|
18
|
+
});
|
19
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
= render 'types/str_entry', f: f, delete_link: local_assigns[:delete_link]
|
@@ -0,0 +1 @@
|
|
1
|
+
= render 'flexite/shared/show_flash'
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'simple_form'
|
2
|
+
# Use this setup block to configure all options available in SimpleForm.
|
3
|
+
SimpleForm.setup do |config|
|
4
|
+
# Wrappers are used by the form builder to generate a
|
5
|
+
# complete input. You can remove any component from the
|
6
|
+
# wrapper, change the order or even add your own to the
|
7
|
+
# stack. The options given below are used to wrap the
|
8
|
+
# whole input.
|
9
|
+
config.wrappers :default, :class => :input,
|
10
|
+
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
|
11
|
+
## Extensions enabled by default
|
12
|
+
# Any of these extensions can be disabled for a
|
13
|
+
# given input by passing: `f.input EXTENSION_NAME => false`.
|
14
|
+
# You can make any of these extensions optional by
|
15
|
+
# renaming `b.use` to `b.optional`.
|
16
|
+
|
17
|
+
# Determines whether to use HTML5 (:email, :url, ...)
|
18
|
+
# and required attributes
|
19
|
+
b.use :html5
|
20
|
+
|
21
|
+
# Calculates placeholders automatically from I18n
|
22
|
+
# You can also pass a string as f.input :placeholder => "Placeholder"
|
23
|
+
b.use :placeholder
|
24
|
+
|
25
|
+
## Optional extensions
|
26
|
+
# They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
|
27
|
+
# to the input. If so, they will retrieve the values from the model
|
28
|
+
# if any exists. If you want to enable the lookup for any of those
|
29
|
+
# extensions by default, you can change `b.optional` to `b.use`.
|
30
|
+
|
31
|
+
# Calculates maxlength from length validations for string inputs
|
32
|
+
b.optional :maxlength
|
33
|
+
|
34
|
+
# Calculates pattern from format validations for string inputs
|
35
|
+
b.optional :pattern
|
36
|
+
|
37
|
+
# Calculates min and max from length validations for numeric inputs
|
38
|
+
b.optional :min_max
|
39
|
+
|
40
|
+
# Calculates readonly automatically from readonly attributes
|
41
|
+
b.optional :readonly
|
42
|
+
|
43
|
+
## Inputs
|
44
|
+
b.use :label_input
|
45
|
+
b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
|
46
|
+
b.use :error, :wrap_with => { :tag => :span, :class => :error }
|
47
|
+
end
|
48
|
+
|
49
|
+
# The default wrapper to be used by the FormBuilder.
|
50
|
+
config.default_wrapper = :default
|
51
|
+
|
52
|
+
# Define the way to render check boxes / radio buttons with labels.
|
53
|
+
# Defaults to :nested for bootstrap config.
|
54
|
+
# :inline => input + label
|
55
|
+
# :nested => label > input
|
56
|
+
config.boolean_style = :nested
|
57
|
+
|
58
|
+
# Default class for buttons
|
59
|
+
config.button_class = 'btn'
|
60
|
+
|
61
|
+
# Method used to tidy up errors. Specify any Rails Array method.
|
62
|
+
# :first lists the first message for each field.
|
63
|
+
# Use :to_sentence to list all errors for each field.
|
64
|
+
# config.error_method = :first
|
65
|
+
|
66
|
+
# Default tag used for error notification helper.
|
67
|
+
config.error_notification_tag = :div
|
68
|
+
|
69
|
+
# CSS class to add for error notification helper.
|
70
|
+
config.error_notification_class = 'alert alert-error'
|
71
|
+
|
72
|
+
# ID to add for error notification helper.
|
73
|
+
# config.error_notification_id = nil
|
74
|
+
|
75
|
+
# Series of attempts to detect a default label method for collection.
|
76
|
+
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
|
77
|
+
|
78
|
+
# Series of attempts to detect a default value method for collection.
|
79
|
+
# config.collection_value_methods = [ :id, :to_s ]
|
80
|
+
|
81
|
+
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
|
82
|
+
# config.collection_wrapper_tag = nil
|
83
|
+
|
84
|
+
# You can define the class to use on all collection wrappers. Defaulting to none.
|
85
|
+
# config.collection_wrapper_class = nil
|
86
|
+
|
87
|
+
# You can wrap each item in a collection of radio/check boxes with a tag,
|
88
|
+
# defaulting to :span. Please note that when using :boolean_style = :nested,
|
89
|
+
# SimpleForm will force this option to be a label.
|
90
|
+
# config.item_wrapper_tag = :span
|
91
|
+
|
92
|
+
# You can define a class to use in all item wrappers. Defaulting to none.
|
93
|
+
# config.item_wrapper_class = nil
|
94
|
+
|
95
|
+
# How the label text should be generated altogether with the required text.
|
96
|
+
# config.label_text = lambda { |label, required| "#{required} #{label}" }
|
97
|
+
|
98
|
+
# You can define the class to use on all labels. Default is nil.
|
99
|
+
config.label_class = 'control-label'
|
100
|
+
|
101
|
+
# You can define the class to use on all forms. Default is simple_form.
|
102
|
+
# config.form_class = :simple_form
|
103
|
+
|
104
|
+
# You can define which elements should obtain additional classes
|
105
|
+
# config.generate_additional_classes_for = [:wrapper, :label, :input]
|
106
|
+
|
107
|
+
# Whether attributes are required by default (or not). Default is true.
|
108
|
+
# config.required_by_default = true
|
109
|
+
|
110
|
+
# Tell browsers whether to use default HTML5 validations (novalidate option).
|
111
|
+
# Default is enabled.
|
112
|
+
config.browser_validations = false
|
113
|
+
|
114
|
+
# Collection of methods to detect if a file type was given.
|
115
|
+
# config.file_methods = [ :mounted_as, :file?, :public_filename ]
|
116
|
+
|
117
|
+
# Custom mappings for input types. This should be a hash containing a regexp
|
118
|
+
# to match as key, and the input type that will be used when the field name
|
119
|
+
# matches the regexp as value.
|
120
|
+
# config.input_mappings = { /count/ => :integer }
|
121
|
+
|
122
|
+
# Custom wrappers for input types. This should be a hash containing an input
|
123
|
+
# type as key and the wrapper that will be used for all inputs with specified type.
|
124
|
+
# config.wrapper_mappings = { :string => :prepend }
|
125
|
+
|
126
|
+
# Default priority for time_zone inputs.
|
127
|
+
# config.time_zone_priority = nil
|
128
|
+
|
129
|
+
# Default priority for country inputs.
|
130
|
+
# config.country_priority = nil
|
131
|
+
|
132
|
+
# Default size for text inputs.
|
133
|
+
# config.default_input_size = 50
|
134
|
+
|
135
|
+
# When false, do not use translations for labels.
|
136
|
+
# config.translate_labels = true
|
137
|
+
|
138
|
+
# Automatically discover new inputs in Rails' autoload path.
|
139
|
+
# config.inputs_discovery = true
|
140
|
+
|
141
|
+
# Cache SimpleForm inputs discovery
|
142
|
+
# config.cache_discovery = !Rails.env.development?
|
143
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Use this setup block to configure all options available in SimpleForm.
|
2
|
+
SimpleForm.setup do |config|
|
3
|
+
config.wrappers :bootstrap, :tag => 'div', :class => 'form-group', :error_class => 'error' do |b|
|
4
|
+
b.use :html5
|
5
|
+
b.use :placeholder
|
6
|
+
b.use :label
|
7
|
+
b.use :input
|
8
|
+
b.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
|
9
|
+
b.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
|
10
|
+
end
|
11
|
+
|
12
|
+
config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
|
13
|
+
b.use :html5
|
14
|
+
b.use :placeholder
|
15
|
+
b.use :label
|
16
|
+
b.wrapper :tag => 'div', :class => 'controls' do |input|
|
17
|
+
input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
|
18
|
+
prepend.use :input
|
19
|
+
end
|
20
|
+
input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
|
21
|
+
input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
|
26
|
+
b.use :html5
|
27
|
+
b.use :placeholder
|
28
|
+
b.use :label
|
29
|
+
b.wrapper :tag => 'div', :class => 'controls' do |input|
|
30
|
+
input.wrapper :tag => 'div', :class => 'input-append' do |append|
|
31
|
+
append.use :input
|
32
|
+
end
|
33
|
+
input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
|
34
|
+
input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Wrappers for forms and inputs using the Bootstrap toolkit.
|
39
|
+
# Check the Bootstrap docs (http://getbootstrap.com/2.3.2/)
|
40
|
+
# to learn about the different styles for forms and inputs,
|
41
|
+
# buttons and other elements.
|
42
|
+
config.default_wrapper = :bootstrap
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
en:
|
2
|
+
simple_form:
|
3
|
+
"yes": 'Yes'
|
4
|
+
"no": 'No'
|
5
|
+
required:
|
6
|
+
text: 'required'
|
7
|
+
mark: '*'
|
8
|
+
# You can uncomment the line below if you need to overwrite the whole required html.
|
9
|
+
# When using html, text and mark won't be used.
|
10
|
+
# html: '<abbr title="required">*</abbr>'
|
11
|
+
error_notification:
|
12
|
+
default_message: "Please review the problems below:"
|
13
|
+
# Labels and hints examples
|
14
|
+
# labels:
|
15
|
+
# defaults:
|
16
|
+
# password: 'Password'
|
17
|
+
# user:
|
18
|
+
# new:
|
19
|
+
# email: 'E-mail to sign in.'
|
20
|
+
# edit:
|
21
|
+
# email: 'E-mail.'
|
22
|
+
# hints:
|
23
|
+
# defaults:
|
24
|
+
# username: 'User name to sign in.'
|
25
|
+
# password: 'No special characters, please.'
|
26
|
+
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Flexite::Engine.routes.draw do
|
2
|
+
resources :entries do
|
3
|
+
collection do
|
4
|
+
get 'new_array' => 'entries#new_array_entry'
|
5
|
+
delete 'destroy_array' => 'entries#destroy_array_entry'
|
6
|
+
get ':parent_id/select_type' => 'entries#select_type', as: :select_type
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
resources :configs do
|
11
|
+
resources :entries
|
12
|
+
resources :configs, only: [:index, :new]
|
13
|
+
get :reload, on: :collection
|
14
|
+
end
|
15
|
+
|
16
|
+
root to: 'application#index'
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateFlexiteConfigs < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :flexite_configs do |t|
|
4
|
+
t.string :name
|
5
|
+
t.integer :created_by
|
6
|
+
t.boolean :selectable, default: true
|
7
|
+
t.references :config
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :flexite_configs, :config_id
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateFlexiteEntries < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :flexite_entries do |t|
|
4
|
+
t.string :value
|
5
|
+
t.string :type
|
6
|
+
t.references :parent, polymorphic: true
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :flexite_entries, :parent_id
|
12
|
+
add_index :flexite_entries, :parent_type
|
13
|
+
end
|
14
|
+
end
|