manage 1.3.35 → 1.3.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -20
  3. data/Rakefile +31 -31
  4. data/app/assets/javascripts/manage/collection_actions.js.coffee +30 -30
  5. data/app/assets/javascripts/manage/handlers.js.coffee +46 -46
  6. data/app/assets/javascripts/manage/table_checkboxes.js.coffee +11 -11
  7. data/app/controllers/manage/application_controller.rb +13 -13
  8. data/app/controllers/manage/dashboards_controller.rb +4 -4
  9. data/app/controllers/manage/responder.rb +11 -11
  10. data/app/controllers/manage/sessions_controller.rb +11 -11
  11. data/app/helpers/manage/application_helper.rb +42 -42
  12. data/app/helpers/manage/form_helper.rb +21 -21
  13. data/app/helpers/manage/resource_helper.rb +77 -77
  14. data/app/models/admin_user.rb +4 -4
  15. data/app/views/layouts/manage/_main_menu.html.slim +52 -52
  16. data/app/views/layouts/manage/sign_in.html.slim +30 -30
  17. data/app/views/manage/resource/_form.html.slim +4 -4
  18. data/app/views/manage/resource/index/_collection_actions.html.slim +2 -2
  19. data/app/views/manage/resource/index/_count.html.slim +6 -6
  20. data/app/views/manage/resource/show.html.slim +10 -10
  21. data/app/views/manage/sessions/new.html.slim +10 -10
  22. data/config/initializers/devise.rb +247 -247
  23. data/config/initializers/session_store.rb +3 -3
  24. data/config/initializers/simple_form.rb +145 -145
  25. data/config/initializers/simple_form_foundation.rb +26 -26
  26. data/config/locales/devise.en.yml +59 -59
  27. data/config/locales/en.yml +20 -20
  28. data/config/routes.rb +10 -10
  29. data/db/migrate/20131204142720_create_admin_users.rb +24 -24
  30. data/lib/manage/engine.rb +21 -21
  31. data/lib/manage/fields.rb +6 -6
  32. data/lib/manage/version.rb +1 -1
  33. data/lib/manage.rb +5 -5
  34. data/lib/tasks/manage_tasks.rake +15 -15
  35. data/lib/templates/erb/scaffold/_form.html.erb +13 -13
  36. data/spec/controllers/manage/resource_controller_spec.rb +29 -29
  37. data/spec/dummy/README.rdoc +28 -28
  38. data/spec/dummy/Rakefile +6 -6
  39. data/spec/dummy/app/assets/javascripts/application.js +13 -13
  40. data/spec/dummy/app/assets/stylesheets/application.css +13 -13
  41. data/spec/dummy/app/controllers/application_controller.rb +5 -5
  42. data/spec/dummy/app/controllers/manage/posts_controller.rb +4 -4
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  44. data/spec/dummy/app/models/post.rb +3 -3
  45. data/spec/dummy/app/models/user.rb +5 -5
  46. data/spec/dummy/app/views/layouts/application.html.erb +14 -14
  47. data/spec/dummy/bin/bundle +3 -3
  48. data/spec/dummy/bin/rails +4 -4
  49. data/spec/dummy/bin/rake +4 -4
  50. data/spec/dummy/config/application.rb +24 -24
  51. data/spec/dummy/config/boot.rb +5 -5
  52. data/spec/dummy/config/database.yml +25 -25
  53. data/spec/dummy/config/environment.rb +5 -5
  54. data/spec/dummy/config/environments/development.rb +29 -29
  55. data/spec/dummy/config/environments/production.rb +80 -80
  56. data/spec/dummy/config/environments/test.rb +36 -36
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  59. data/spec/dummy/config/initializers/inflections.rb +16 -16
  60. data/spec/dummy/config/initializers/mime_types.rb +5 -5
  61. data/spec/dummy/config/initializers/secret_token.rb +12 -12
  62. data/spec/dummy/config/initializers/session_store.rb +3 -3
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  64. data/spec/dummy/config/locales/en.yml +23 -23
  65. data/spec/dummy/config/routes.rb +10 -10
  66. data/spec/dummy/config.ru +4 -4
  67. data/spec/dummy/db/migrate/20130716083410_init_migration.rb +21 -21
  68. data/spec/dummy/db/schema.rb +53 -53
  69. data/spec/dummy/log/test.log +0 -0
  70. data/spec/dummy/public/404.html +58 -58
  71. data/spec/dummy/public/422.html +58 -58
  72. data/spec/dummy/public/500.html +57 -57
  73. data/spec/fields/reader_spec.rb +79 -79
  74. data/spec/spec_helper.rb +24 -24
  75. metadata +84 -82
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8178a03ad541ed28b70573ee49c15e8a6e26b5a
4
- data.tar.gz: 764fd98392495d8771a5fa7a7f0d20d62f04459a
3
+ metadata.gz: 27a8e7c0b8caab1f43a8d14cfd9a2c10b5768a99
4
+ data.tar.gz: 3d193a64dbaa17582b5849515228f720fc0a1008
5
5
  SHA512:
6
- metadata.gz: 274a400e0b37be708b608fda11a89ce83e5503735a014596bb698d473c2e486ca5b216f0755b4d326d7976333ab1839acf08ff8b3d4c7c50ba997f7a727ebe69
7
- data.tar.gz: 93a49f01b13d22cc96733353aefb615aaefcf7872241969f8a03d26a72e798de778dad35602f8ad142f977c65386fd6599402607de09dcd60798a73a4b3a6390
6
+ metadata.gz: 29f73f067ae0f309e03e2d79b63408deb673a567a3a2b2bbd73a33de1fc220d54a732cd414a3aaee2bd1c069ff59b500e35260931c329adb4c2e9148a585362c
7
+ data.tar.gz: 6ce1245b19d20d08cc336ab2f745ae37d5d8765386e7e078c5388aa7c6aad97d5e2c1cdbfaf7a2cc5a66ae9d6d5f9901af02f904f86397f72cf6aeb834d4f838
data/MIT-LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright 2013 YOURNAME
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,31 +1,31 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Manage'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
- load 'rails/tasks/engine.rake'
19
-
20
-
21
- Bundler::GemHelper.install_tasks
22
-
23
- Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
24
-
25
- require 'rspec/core'
26
- require 'rspec/core/rake_task'
27
-
28
- desc "Run all specs in spec directory (excluding plugin specs)"
29
- RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
30
-
31
- task default: :spec
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Manage'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ Bundler::GemHelper.install_tasks
22
+
23
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
24
+
25
+ require 'rspec/core'
26
+ require 'rspec/core/rake_task'
27
+
28
+ desc "Run all specs in spec directory (excluding plugin specs)"
29
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
30
+
31
+ task default: :spec
@@ -1,30 +1,30 @@
1
- class CollectionActions
2
- constructor: (el) ->
3
- $el = $(el)
4
-
5
- $form = $el.closest('form')
6
-
7
- $el.on 'click', (e) ->
8
- e.stopPropagation()
9
- e.preventDefault()
10
-
11
- checkedCheckboxes = $('.rs:checked')
12
- unless checkedCheckboxes.length
13
- alert 'Select Items'
14
- return false
15
-
16
- # clear all hidden fields with class .hidden_selected_ids
17
- $form.find('input[type="hidden"]').remove()
18
-
19
- checkedCheckboxes.each ->
20
- # create a new hidden
21
- hidden_input = $('<input>').attr({
22
- type: 'hidden',
23
- name: 'selected_ids[]',
24
- value: $(@).val()
25
- }).appendTo($form)
26
-
27
- $form.submit()
28
-
29
-
30
- Handlers.register 'CollectionActions', CollectionActions
1
+ class CollectionActions
2
+ constructor: (el) ->
3
+ $el = $(el)
4
+
5
+ $form = $el.closest('form')
6
+
7
+ $el.on 'click', (e) ->
8
+ e.stopPropagation()
9
+ e.preventDefault()
10
+
11
+ checkedCheckboxes = $('.rs:checked')
12
+ unless checkedCheckboxes.length
13
+ alert 'Select Items'
14
+ return false
15
+
16
+ # clear all hidden fields with class .hidden_selected_ids
17
+ $form.find('input[type="hidden"]').remove()
18
+
19
+ checkedCheckboxes.each ->
20
+ # create a new hidden
21
+ hidden_input = $('<input>').attr({
22
+ type: 'hidden',
23
+ name: 'selected_ids[]',
24
+ value: $(@).val()
25
+ }).appendTo($form)
26
+
27
+ $form.submit()
28
+
29
+
30
+ Handlers.register 'CollectionActions', CollectionActions
@@ -1,46 +1,46 @@
1
- class @Handlers
2
- @handlers = {}
3
-
4
- @register: (handler, registeredClass) ->
5
- throw "No constructor on " + handler unless registeredClass.constructor
6
- @handlers[handler] = registeredClass
7
-
8
- @instantiate: (handlers, element) ->
9
- handlers = handlers.replace(/\s/g, '').split(',')
10
- element.handlers = []
11
- $.each handlers, (index, handler) =>
12
- if @handlers[handler]
13
- instance = new @handlers[handler](element)
14
- element.handlers.push instance
15
- else
16
- throw "Unknown handler " + handler
17
-
18
- @destroy: (instances) ->
19
- $.each instances, (index, instance) ->
20
- instance.destroy() if instance.destroy
21
-
22
- @unregisterAll: ->
23
- @handlers = {}
24
-
25
- $(document).on 'handlers:pageChanged', ->
26
- $('[data-handler]').each ->
27
- Handlers.instantiate $(this).attr('data-handler'), this
28
-
29
- $(document).on 'handlers:pageUpdated', (event, scope) ->
30
- $(scope).find('[data-handler]').each ->
31
- Handlers.instantiate $(this).attr('data-handler'), this
32
-
33
- $(document).on 'handlers:pageUpdating', (event, scope) ->
34
- $(scope).find('[data-handler]').each ->
35
- Handlers.destroy @handlers if @handlers
36
- delete @handlers if @handlers
37
-
38
- if typeof(Turbolinks) != undefined
39
- $(document).on 'page:fetch', ->
40
- $(document).trigger 'handlers:pageUpdating', 'body'
41
-
42
- $(document).on 'page:change', ->
43
- $(document).trigger 'handlers:pageUpdated', 'body'
44
-
45
- $ ->
46
- $(document).trigger 'handlers:pageChanged'
1
+ class @Handlers
2
+ @handlers = {}
3
+
4
+ @register: (handler, registeredClass) ->
5
+ throw "No constructor on " + handler unless registeredClass.constructor
6
+ @handlers[handler] = registeredClass
7
+
8
+ @instantiate: (handlers, element) ->
9
+ handlers = handlers.replace(/\s/g, '').split(',')
10
+ element.handlers = []
11
+ $.each handlers, (index, handler) =>
12
+ if @handlers[handler]
13
+ instance = new @handlers[handler](element)
14
+ element.handlers.push instance
15
+ else
16
+ throw "Unknown handler " + handler
17
+
18
+ @destroy: (instances) ->
19
+ $.each instances, (index, instance) ->
20
+ instance.destroy() if instance.destroy
21
+
22
+ @unregisterAll: ->
23
+ @handlers = {}
24
+
25
+ $(document).on 'handlers:pageChanged', ->
26
+ $('[data-handler]').each ->
27
+ Handlers.instantiate $(this).attr('data-handler'), this
28
+
29
+ $(document).on 'handlers:pageUpdated', (event, scope) ->
30
+ $(scope).find('[data-handler]').each ->
31
+ Handlers.instantiate $(this).attr('data-handler'), this
32
+
33
+ $(document).on 'handlers:pageUpdating', (event, scope) ->
34
+ $(scope).find('[data-handler]').each ->
35
+ Handlers.destroy @handlers if @handlers
36
+ delete @handlers if @handlers
37
+
38
+ if typeof(Turbolinks) != undefined
39
+ $(document).on 'page:fetch', ->
40
+ $(document).trigger 'handlers:pageUpdating', 'body'
41
+
42
+ $(document).on 'page:change', ->
43
+ $(document).trigger 'handlers:pageUpdated', 'body'
44
+
45
+ $ ->
46
+ $(document).trigger 'handlers:pageChanged'
@@ -1,12 +1,12 @@
1
- class TableCheckboxes
2
- constructor: (el) ->
3
- $el = $(el)
4
- $mainContainer = $el.closest('table')
5
-
6
- $el.on 'click', (event, element)->
7
- check = if $el.is(':checked') then true else false
8
-
9
- $mainContainer.find('.rs').each ->
10
- $(@).prop('checked', check)
11
-
1
+ class TableCheckboxes
2
+ constructor: (el) ->
3
+ $el = $(el)
4
+ $mainContainer = $el.closest('table')
5
+
6
+ $el.on 'click', (event, element)->
7
+ check = if $el.is(':checked') then true else false
8
+
9
+ $mainContainer.find('.rs').each ->
10
+ $(@).prop('checked', check)
11
+
12
12
  Handlers.register 'TableCheckboxes', TableCheckboxes
@@ -1,13 +1,13 @@
1
- class Manage::ApplicationController < ActionController::Base
2
- before_filter :auth_user!
3
-
4
- def auth_user!
5
- redirect_to new_admin_user_session_path unless admin_user_signed_in?
6
- end
7
-
8
- helper_method :current_user
9
- def current_user
10
- current_admin_user
11
- end
12
-
13
- end
1
+ class Manage::ApplicationController < ActionController::Base
2
+ before_filter :auth_user!
3
+
4
+ def auth_user!
5
+ redirect_to new_admin_user_session_path unless admin_user_signed_in?
6
+ end
7
+
8
+ helper_method :current_user
9
+ def current_user
10
+ current_admin_user
11
+ end
12
+
13
+ end
@@ -1,4 +1,4 @@
1
- class Manage::DashboardsController < Manage::ApplicationController
2
- def index
3
- end
4
- end
1
+ class Manage::DashboardsController < Manage::ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -1,12 +1,12 @@
1
- # app/controllers/backend/responder.rb
2
- class Manage::Responder < ::ActionController::Responder
3
-
4
- include Responders::FlashResponder
5
- include Responders::HttpCacheResponder
6
-
7
- def initialize(*)
8
- super
9
- @flash_now = :on_failure
10
- end
11
-
1
+ # app/controllers/backend/responder.rb
2
+ class Manage::Responder < ::ActionController::Responder
3
+
4
+ include Responders::FlashResponder
5
+ include Responders::HttpCacheResponder
6
+
7
+ def initialize(*)
8
+ super
9
+ @flash_now = :on_failure
10
+ end
11
+
12
12
  end
@@ -1,11 +1,11 @@
1
- module Manage
2
- class SessionsController < ::Devise::SessionsController
3
- layout "manage/sign_in"
4
-
5
- def destroy
6
- p 'what?'
7
- super
8
- end
9
- end
10
- end
11
-
1
+ module Manage
2
+ class SessionsController < ::Devise::SessionsController
3
+ layout "manage/sign_in"
4
+
5
+ def destroy
6
+ p 'what?'
7
+ super
8
+ end
9
+ end
10
+ end
11
+
@@ -1,42 +1,42 @@
1
- module Manage
2
- module ApplicationHelper
3
-
4
- def collection_table collection, resource_class, no_items_text
5
-
6
- if collection.empty?
7
- return content_tag(:h3, resource_class.model_name.human(count: 2)) + content_tag(:p, no_items_text)
8
- else
9
- rows = []
10
-
11
- ths = resource_class.attribute_names.collect do |attr|
12
- content_tag(:td, truncate(resource_class.human_attribute_name(attr).to_s, length: 50))
13
- end.join('').html_safe
14
- rows << content_tag(:tr, ths)
15
-
16
- collection.each do |item|
17
- tds = resource_class.attribute_names.collect do |attr|
18
- content_tag(:td, truncate(item.public_send(attr).to_s, length: 50))
19
- end.join('').html_safe
20
-
21
- rows << content_tag(:tr, tds)
22
- end
23
- content_tag(:h3, resource_class.model_name.human(count: 2)) +
24
- content_tag(:table, rows.join('').html_safe)
25
- end
26
- end
27
-
28
- def condensed_table resource_class, cols=2
29
- rows = []
30
- resource_class.attribute_names.each_slice(cols).each do |slice|
31
- row = slice.collect do |attr|
32
- content_tag(:td, resource_class.human_attribute_name(attr)) +
33
- content_tag(:td, resource.public_send(attr))
34
- end
35
- rows << content_tag(:tr, row.join('').html_safe)
36
- end
37
-
38
- content_tag :table, rows.join('').html_safe
39
- end
40
-
41
- end
42
- end
1
+ module Manage
2
+ module ApplicationHelper
3
+
4
+ def collection_table collection, resource_class, no_items_text
5
+
6
+ if collection.empty?
7
+ return content_tag(:h3, resource_class.model_name.human(count: 2)) + content_tag(:p, no_items_text)
8
+ else
9
+ rows = []
10
+
11
+ ths = resource_class.attribute_names.collect do |attr|
12
+ content_tag(:td, truncate(resource_class.human_attribute_name(attr).to_s, length: 50))
13
+ end.join('').html_safe
14
+ rows << content_tag(:tr, ths)
15
+
16
+ collection.each do |item|
17
+ tds = resource_class.attribute_names.collect do |attr|
18
+ content_tag(:td, truncate(item.public_send(attr).to_s, length: 50))
19
+ end.join('').html_safe
20
+
21
+ rows << content_tag(:tr, tds)
22
+ end
23
+ content_tag(:h3, resource_class.model_name.human(count: 2)) +
24
+ content_tag(:table, rows.join('').html_safe)
25
+ end
26
+ end
27
+
28
+ def condensed_table resource_class, cols=2
29
+ rows = []
30
+ resource_class.attribute_names.each_slice(cols).each do |slice|
31
+ row = slice.collect do |attr|
32
+ content_tag(:td, resource_class.human_attribute_name(attr)) +
33
+ content_tag(:td, resource.public_send(attr))
34
+ end
35
+ rows << content_tag(:tr, row.join('').html_safe)
36
+ end
37
+
38
+ content_tag :table, rows.join('').html_safe
39
+ end
40
+
41
+ end
42
+ end
@@ -1,21 +1,21 @@
1
- module Manage
2
-
3
- module FormHelper
4
- include SimpleForm::ActionViewExtensions::FormHelper
5
-
6
- OPTIONS = {
7
- wrapper: :foundation,
8
- class: 'custom'
9
- }
10
-
11
- def manage_form_for(record, options={}, &block)
12
- simple_form_for(record, options.merge(Manage::FormHelper::OPTIONS), &block)
13
- end
14
-
15
- def manage_fields_for(record_name, record_object = nil, options = {}, &block)
16
- simple_fields_for(record_name, record_object = nil, options.merge(Manage::FormHelper::OPTIONS), &block)
17
- end
18
-
19
- end
20
-
21
- end
1
+ module Manage
2
+
3
+ module FormHelper
4
+ include SimpleForm::ActionViewExtensions::FormHelper
5
+
6
+ OPTIONS = {
7
+ wrapper: :foundation,
8
+ class: 'custom'
9
+ }
10
+
11
+ def manage_form_for(record, options={}, &block)
12
+ simple_form_for(record, options.merge(Manage::FormHelper::OPTIONS), &block)
13
+ end
14
+
15
+ def manage_fields_for(record_name, record_object = nil, options = {}, &block)
16
+ simple_fields_for(record_name, record_object = nil, options.merge(Manage::FormHelper::OPTIONS), &block)
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -1,77 +1,77 @@
1
- module Manage
2
- module ResourceHelper
3
- def index_fields
4
- list_index_fields
5
- end
6
-
7
- def edit_fields
8
- list_edit_fields
9
- end
10
-
11
- def attributes
12
- resource_class.attribute_names - %w(id created_at updated_at)
13
- end
14
-
15
- def field_value(scope, field_data)
16
- Fields::Reader.field_value(scope, field_data).to_s
17
- end
18
-
19
- def field_title(resource_class, field_data)
20
- Fields::Reader.field_title(resource_class, field_data)
21
- end
22
-
23
-
24
- #
25
- # to customise the actions for a resource define a list of actions
26
- #
27
- # example:
28
- # action_links :posts, :tickets, ->(resource) {link_to "#{resource.name}"}
29
- #
30
- # @param scope [type] [description]
31
- # @param link_data [type] [description]
32
- #
33
- # @return [type] [description]
34
- def action_link(scope, link_data)
35
- value = nil
36
- case link_data
37
-
38
- when Proc
39
- value = link_data.call(scope)
40
-
41
- when Hash
42
- relation = link_data.keys.first
43
- entity = Fields::Reader.field_value(scope, relation)
44
- unless entity.present?
45
- return ''
46
- end
47
- if link_data[relation][:label_field].present?
48
- value = field_value(scope, link_data[relation][:label_field])
49
- elsif link_data[relation][:label].present?
50
- value = link_data[relation][:label]
51
- end
52
-
53
- path = entity.class.name.dasherize.pluralize.downcase
54
- return link_to value, [scope.public_send(relation)]
55
-
56
- when *[Symbol, String]
57
- relation = link_data.to_s
58
- assocation = scope.class.reflect_on_association(link_data.to_sym)
59
- raise "assocation #{link_data} not found on #{scope.class}" unless assocation
60
- if assocation.options[:class_name].present?
61
- rel_name = scope.class.reflect_on_association(link_data.to_sym).options[:class_name]
62
- relation = rel_name.downcase.dasherize.pluralize
63
- end
64
- if scope.class.reflect_on_association(link_data.to_sym).options[:as].present?
65
- key = scope.class.reflect_on_association(link_data.to_sym).options[:as].to_s + '_id'
66
- else
67
- key = scope.class.name.downcase.dasherize + '_id'
68
- end
69
- return "<a href=\"#{relation}?f%5B#{key}%5D=#{scope.id}\">#{resource_class.human_attribute_name(link_data.to_s)}</a>".html_safe
70
- else
71
- raise 'Unsupported link data'
72
- end
73
-
74
- end
75
-
76
- end
77
- end
1
+ module Manage
2
+ module ResourceHelper
3
+ def index_fields
4
+ list_index_fields
5
+ end
6
+
7
+ def edit_fields
8
+ list_edit_fields
9
+ end
10
+
11
+ def attributes
12
+ resource_class.attribute_names - %w(id created_at updated_at)
13
+ end
14
+
15
+ def field_value(scope, field_data)
16
+ Fields::Reader.field_value(scope, field_data).to_s
17
+ end
18
+
19
+ def field_title(resource_class, field_data)
20
+ Fields::Reader.field_title(resource_class, field_data)
21
+ end
22
+
23
+
24
+ #
25
+ # to customise the actions for a resource define a list of actions
26
+ #
27
+ # example:
28
+ # action_links :posts, :tickets, ->(resource) {link_to "#{resource.name}"}
29
+ #
30
+ # @param scope [type] [description]
31
+ # @param link_data [type] [description]
32
+ #
33
+ # @return [type] [description]
34
+ def action_link(scope, link_data)
35
+ value = nil
36
+ case link_data
37
+
38
+ when Proc
39
+ value = link_data.call(scope)
40
+
41
+ when Hash
42
+ relation = link_data.keys.first
43
+ entity = Fields::Reader.field_value(scope, relation)
44
+ unless entity.present?
45
+ return ''
46
+ end
47
+ if link_data[relation][:label_field].present?
48
+ value = field_value(scope, link_data[relation][:label_field])
49
+ elsif link_data[relation][:label].present?
50
+ value = link_data[relation][:label]
51
+ end
52
+
53
+ path = entity.class.name.dasherize.pluralize.downcase
54
+ return link_to value, [scope.public_send(relation)]
55
+
56
+ when *[Symbol, String]
57
+ relation = link_data.to_s
58
+ assocation = scope.class.reflect_on_association(link_data.to_sym)
59
+ raise "assocation #{link_data} not found on #{scope.class}" unless assocation
60
+ if assocation.options[:class_name].present?
61
+ rel_name = scope.class.reflect_on_association(link_data.to_sym).options[:class_name]
62
+ relation = rel_name.downcase.dasherize.pluralize
63
+ end
64
+ if scope.class.reflect_on_association(link_data.to_sym).options[:as].present?
65
+ key = scope.class.reflect_on_association(link_data.to_sym).options[:as].to_s + '_id'
66
+ else
67
+ key = scope.class.name.downcase.dasherize + '_id'
68
+ end
69
+ return "<a href=\"#{relation}?f%5B#{key}%5D=#{scope.id}\">#{resource_class.human_attribute_name(link_data.to_s)}</a>".html_safe
70
+ else
71
+ raise 'Unsupported link data'
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+ end