semantic-administrate 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +32 -0
  3. data/app/assets/fonts/administrate/semantic-ui/icons.eot +0 -0
  4. data/app/assets/fonts/administrate/semantic-ui/icons.otf +0 -0
  5. data/app/assets/fonts/administrate/semantic-ui/icons.svg +2671 -0
  6. data/app/assets/fonts/administrate/semantic-ui/icons.ttf +0 -0
  7. data/app/assets/fonts/administrate/semantic-ui/icons.woff +0 -0
  8. data/app/assets/fonts/administrate/semantic-ui/icons.woff2 +0 -0
  9. data/app/assets/images/administrate/semantic-ui/flags.png +0 -0
  10. data/app/assets/javascripts/administrate/application.js +7 -0
  11. data/app/assets/javascripts/administrate/components/date_time_picker.js +6 -0
  12. data/app/assets/javascripts/administrate/components/has_many_form.js +3 -0
  13. data/app/assets/javascripts/administrate/components/table.js +23 -0
  14. data/app/assets/javascripts/administrate/vendor/semantic-ui.js +22943 -0
  15. data/app/assets/stylesheets/administrate/application.scss +27 -0
  16. data/app/assets/stylesheets/administrate/base/_forms.scss +106 -0
  17. data/app/assets/stylesheets/administrate/base/_layout.scss +10 -0
  18. data/app/assets/stylesheets/administrate/base/_lists.scss +19 -0
  19. data/app/assets/stylesheets/administrate/base/_typography.scss +48 -0
  20. data/app/assets/stylesheets/administrate/components/_app-container.scss +27 -0
  21. data/app/assets/stylesheets/administrate/components/_attributes.scss +34 -0
  22. data/app/assets/stylesheets/administrate/components/_buttons.scss +43 -0
  23. data/app/assets/stylesheets/administrate/components/_cells.scss +59 -0
  24. data/app/assets/stylesheets/administrate/components/_field-unit.scss +36 -0
  25. data/app/assets/stylesheets/administrate/components/_flashes.scss +28 -0
  26. data/app/assets/stylesheets/administrate/components/_form-actions.scss +3 -0
  27. data/app/assets/stylesheets/administrate/components/_main-content.scss +42 -0
  28. data/app/assets/stylesheets/administrate/components/_pagination.scss +18 -0
  29. data/app/assets/stylesheets/administrate/components/_search.scss +45 -0
  30. data/app/assets/stylesheets/administrate/components/nav-drawer.scss +156 -0
  31. data/app/assets/stylesheets/administrate/library/_clearfix.scss +7 -0
  32. data/app/assets/stylesheets/administrate/library/_data-label.scss +8 -0
  33. data/app/assets/stylesheets/administrate/library/_variables.scss +65 -0
  34. data/app/assets/stylesheets/administrate/vendor/semantic-ui.scss +37123 -0
  35. data/app/assets/stylesheets/docs.scss +93 -0
  36. data/app/controllers/administrate/application_controller.rb +162 -0
  37. data/app/helpers/administrate/application_helper.rb +51 -0
  38. data/app/views/administrate/application/_collection.html.erb +92 -0
  39. data/app/views/administrate/application/_flashes.html.erb +20 -0
  40. data/app/views/administrate/application/_form.html.erb +42 -0
  41. data/app/views/administrate/application/_icons.erb +13 -0
  42. data/app/views/administrate/application/_javascript.html.erb +21 -0
  43. data/app/views/administrate/application/_navigation.html.erb +19 -0
  44. data/app/views/administrate/application/_navigation_extra_links.html.erb +13 -0
  45. data/app/views/administrate/application/_navigation_footer.html.erb +44 -0
  46. data/app/views/administrate/application/_navigation_links.html.erb +16 -0
  47. data/app/views/administrate/application/_search.html.erb +25 -0
  48. data/app/views/administrate/application/_stylesheet.html.erb +14 -0
  49. data/app/views/administrate/application/edit.html.erb +36 -0
  50. data/app/views/administrate/application/index.html.erb +63 -0
  51. data/app/views/administrate/application/new.html.erb +32 -0
  52. data/app/views/administrate/application/show.html.erb +49 -0
  53. data/app/views/fields/belongs_to/_form.html.erb +26 -0
  54. data/app/views/fields/belongs_to/_index.html.erb +27 -0
  55. data/app/views/fields/belongs_to/_show.html.erb +27 -0
  56. data/app/views/fields/boolean/_form.html.erb +23 -0
  57. data/app/views/fields/boolean/_index.html.erb +19 -0
  58. data/app/views/fields/boolean/_show.html.erb +19 -0
  59. data/app/views/fields/date_time/_form.html.erb +24 -0
  60. data/app/views/fields/date_time/_index.html.erb +21 -0
  61. data/app/views/fields/date_time/_show.html.erb +21 -0
  62. data/app/views/fields/email/_form.html.erb +23 -0
  63. data/app/views/fields/email/_index.html.erb +18 -0
  64. data/app/views/fields/email/_show.html.erb +18 -0
  65. data/app/views/fields/has_many/_form.html.erb +29 -0
  66. data/app/views/fields/has_many/_index.html.erb +19 -0
  67. data/app/views/fields/has_many/_show.html.erb +35 -0
  68. data/app/views/fields/has_one/_form.html.erb +28 -0
  69. data/app/views/fields/has_one/_index.html.erb +23 -0
  70. data/app/views/fields/has_one/_show.html.erb +40 -0
  71. data/app/views/fields/number/_form.html.erb +23 -0
  72. data/app/views/fields/number/_index.html.erb +19 -0
  73. data/app/views/fields/number/_show.html.erb +19 -0
  74. data/app/views/fields/polymorphic/_form.html.erb +32 -0
  75. data/app/views/fields/polymorphic/_index.html.erb +24 -0
  76. data/app/views/fields/polymorphic/_show.html.erb +28 -0
  77. data/app/views/fields/select/_form.html.erb +31 -0
  78. data/app/views/fields/select/_index.html.erb +16 -0
  79. data/app/views/fields/select/_show.html.erb +16 -0
  80. data/app/views/fields/string/_form.html.erb +23 -0
  81. data/app/views/fields/string/_index.html.erb +18 -0
  82. data/app/views/fields/string/_show.html.erb +18 -0
  83. data/app/views/fields/text/_form.html.erb +22 -0
  84. data/app/views/fields/text/_index.html.erb +18 -0
  85. data/app/views/fields/text/_show.html.erb +19 -0
  86. data/app/views/layouts/administrate/application.html.erb +43 -0
  87. data/config/i18n-tasks.yml +18 -0
  88. data/config/locales/administrate.ar.yml +26 -0
  89. data/config/locales/administrate.bs.yml +25 -0
  90. data/config/locales/administrate.ca.yml +26 -0
  91. data/config/locales/administrate.da.yml +26 -0
  92. data/config/locales/administrate.de.yml +26 -0
  93. data/config/locales/administrate.en.yml +26 -0
  94. data/config/locales/administrate.es.yml +26 -0
  95. data/config/locales/administrate.fr.yml +26 -0
  96. data/config/locales/administrate.it.yml +26 -0
  97. data/config/locales/administrate.ja.yml +26 -0
  98. data/config/locales/administrate.ko.yml +26 -0
  99. data/config/locales/administrate.nl.yml +26 -0
  100. data/config/locales/administrate.pl.yml +26 -0
  101. data/config/locales/administrate.pt-BR.yml +27 -0
  102. data/config/locales/administrate.pt.yml +27 -0
  103. data/config/locales/administrate.ru.yml +26 -0
  104. data/config/locales/administrate.sv.yml +26 -0
  105. data/config/locales/administrate.uk.yml +26 -0
  106. data/config/locales/administrate.vi.yml +26 -0
  107. data/config/locales/administrate.zh-CN.yml +26 -0
  108. data/config/locales/administrate.zh-TW.yml +26 -0
  109. data/config/routes.rb +2 -0
  110. data/config/unicorn.rb +30 -0
  111. data/docs/adding_custom_field_types.md +79 -0
  112. data/docs/authentication.md +61 -0
  113. data/docs/customizing_attribute_partials.md +53 -0
  114. data/docs/customizing_controller_actions.md +42 -0
  115. data/docs/customizing_dashboards.md +202 -0
  116. data/docs/customizing_page_views.md +78 -0
  117. data/docs/getting_started.md +115 -0
  118. data/lib/administrate.rb +4 -0
  119. data/lib/administrate/base_dashboard.rb +72 -0
  120. data/lib/administrate/engine.rb +44 -0
  121. data/lib/administrate/field/associative.rb +33 -0
  122. data/lib/administrate/field/base.rb +54 -0
  123. data/lib/administrate/field/belongs_to.rb +36 -0
  124. data/lib/administrate/field/boolean.rb +15 -0
  125. data/lib/administrate/field/date_time.rb +21 -0
  126. data/lib/administrate/field/deferred.rb +35 -0
  127. data/lib/administrate/field/email.rb +11 -0
  128. data/lib/administrate/field/has_many.rb +87 -0
  129. data/lib/administrate/field/has_one.rb +27 -0
  130. data/lib/administrate/field/number.rb +35 -0
  131. data/lib/administrate/field/polymorphic.rb +51 -0
  132. data/lib/administrate/field/select.rb +21 -0
  133. data/lib/administrate/field/string.rb +21 -0
  134. data/lib/administrate/field/text.rb +21 -0
  135. data/lib/administrate/generator_helpers.rb +13 -0
  136. data/lib/administrate/namespace.rb +31 -0
  137. data/lib/administrate/namespace/resource.rb +28 -0
  138. data/lib/administrate/order.rb +45 -0
  139. data/lib/administrate/page.rb +4 -0
  140. data/lib/administrate/page/base.rb +35 -0
  141. data/lib/administrate/page/collection.rb +33 -0
  142. data/lib/administrate/page/form.rb +28 -0
  143. data/lib/administrate/page/show.rb +24 -0
  144. data/lib/administrate/resource_resolver.rb +43 -0
  145. data/lib/administrate/search.rb +47 -0
  146. data/lib/administrate/version.rb +3 -0
  147. data/lib/administrate/view_generator.rb +36 -0
  148. data/lib/generators/administrate/assets/assets_generator.rb +12 -0
  149. data/lib/generators/administrate/assets/javascripts_generator.rb +17 -0
  150. data/lib/generators/administrate/assets/stylesheets_generator.rb +17 -0
  151. data/lib/generators/administrate/dashboard/USAGE +9 -0
  152. data/lib/generators/administrate/dashboard/dashboard_generator.rb +141 -0
  153. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +21 -0
  154. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +56 -0
  155. data/lib/generators/administrate/field/field_generator.rb +31 -0
  156. data/lib/generators/administrate/field/templates/_form.html.erb +6 -0
  157. data/lib/generators/administrate/field/templates/_index.html.erb +1 -0
  158. data/lib/generators/administrate/field/templates/_show.html.erb +1 -0
  159. data/lib/generators/administrate/field/templates/field_object.rb.erb +7 -0
  160. data/lib/generators/administrate/install/install_generator.rb +49 -0
  161. data/lib/generators/administrate/install/templates/application_controller.rb.erb +21 -0
  162. data/lib/generators/administrate/routes/routes_generator.rb +91 -0
  163. data/lib/generators/administrate/routes/templates/routes.rb.erb +5 -0
  164. data/lib/generators/administrate/views/edit_generator.rb +16 -0
  165. data/lib/generators/administrate/views/field_generator.rb +50 -0
  166. data/lib/generators/administrate/views/form_generator.rb +15 -0
  167. data/lib/generators/administrate/views/index_generator.rb +16 -0
  168. data/lib/generators/administrate/views/layout_generator.rb +23 -0
  169. data/lib/generators/administrate/views/navigation_generator.rb +15 -0
  170. data/lib/generators/administrate/views/new_generator.rb +16 -0
  171. data/lib/generators/administrate/views/show_generator.rb +15 -0
  172. data/lib/generators/administrate/views/views_generator.rb +14 -0
  173. data/lib/tasks/administrate_tasks.rake +4 -0
  174. metadata +388 -0
@@ -0,0 +1,78 @@
1
+ # Customizing page views
2
+
3
+ In order to change the appearance of any page,
4
+ you can write custom Rails views.
5
+
6
+ ## Customizing for all resources
7
+
8
+ The easiest way to get started is by using the built-in generators.
9
+ In order to change the appearance of views for all resource types,
10
+ call the generators with no arguments.
11
+
12
+ ```bash
13
+ rails generate administrate:views:index
14
+ # -> app/views/admin/application/index.html.erb
15
+ # -> app/views/admin/application/_collection.html.erb
16
+
17
+ rails generate administrate:views:show
18
+ # -> app/views/admin/application/show.html.erb
19
+
20
+ rails generate administrate:views:edit
21
+ # -> app/views/admin/application/edit.html.erb
22
+ # -> app/views/admin/application/_form.html.erb
23
+
24
+ rails generate administrate:views:new
25
+ # -> app/views/admin/application/new.html.erb
26
+ # -> app/views/admin/application/_form.html.erb
27
+
28
+ rails generate administrate:views
29
+ # -> all of the above
30
+ ```
31
+
32
+ The generators copy over the default views that Administrate uses,
33
+ so you have a good starting point for customizations.
34
+ Feel free to change up the file type,
35
+ add extra sections to the page,
36
+ or blow it all away for your own custom look.
37
+
38
+ ## Customizing for a specific resource
39
+
40
+ In order to change a dashboard page for a single type of resource,
41
+ pass in the resource name to the view generators.
42
+
43
+ ```bash
44
+ rails generate administrate:views:index User
45
+ # -> app/views/admin/users/index.html.erb
46
+ # -> app/views/admin/users/_collection.html.erb
47
+
48
+ rails generate administrate:views:show User
49
+ # -> app/views/admin/users/show.html.erb
50
+
51
+ rails generate administrate:views:edit User
52
+ # -> app/views/admin/users/edit.html.erb
53
+ # -> app/views/admin/users/_form.html.erb
54
+
55
+ rails generate administrate:views:new User
56
+ # -> app/views/admin/users/new.html.erb
57
+ # -> app/views/admin/users/_form.html.erb
58
+
59
+ rails generate administrate:views User
60
+ # -> all of the above
61
+ ```
62
+
63
+ Any changes to these template files
64
+ will *only* affect pages that display customers,
65
+ and will leave the show pages for other resources unchanged.
66
+
67
+ ## Customizing layouts
68
+
69
+ Many developers need to customize the layouts of their admin dashboard.
70
+ It's so easy that pass in the "layout" key word to the view generators.
71
+
72
+ ```bash
73
+ rails generate administrate:views:layout
74
+ # -> app/views/layouts/admin/application.html.erb
75
+ # -> app/views/admin/application/_navigation.html.erb
76
+ # -> app/views/admin/application/_javascript.html.erb
77
+ # -> app/views/admin/application/_flashes.html.erb
78
+ ```
@@ -0,0 +1,115 @@
1
+ # Getting Started
2
+
3
+ Administrate is released as a Ruby gem, and can be installed on Rails
4
+ applications version 4.2 or greater.
5
+
6
+ Add the following to your Gemfile:
7
+
8
+ ```ruby
9
+ # Gemfile
10
+ gem "administrate"
11
+ ```
12
+
13
+ Re-bundle, then run the installer:
14
+
15
+ ```bash
16
+ $ rails generate administrate:install
17
+ ```
18
+
19
+ The installer adds some new routes to your `config/routes.rb`,
20
+ and creates a controller at `app/controllers/admin/application_controller.rb`
21
+
22
+ In addition, the generator creates a `Dashboard` and a `Controller` for each of
23
+ your ActiveRecord resources:
24
+
25
+ - `app/controllers/admin/foos_controller.rb`
26
+ - `app/dashboards/foo_dashboard.rb`
27
+
28
+ The `Admin::ApplicationController` can be customized to add
29
+ authentication logic, authorization, pagination,
30
+ or other controller-level concerns.
31
+
32
+ You will also want to add a `root` route to show a dashboard when you go to `/admin`.
33
+
34
+ ```ruby
35
+ Rails.application.routes.draw do
36
+ namespace :admin do
37
+ # Add dashboard for your models here
38
+ resources :customers,
39
+ resources :orders
40
+
41
+ root to: "customers#index" # <--- Root route
42
+ end
43
+ end
44
+ ```
45
+
46
+ The routes can be customized to show or hide
47
+ different models on the dashboard.
48
+
49
+ Each `FooDashboard` specifies which attributes should be displayed
50
+ on the admin dashboard for the `Foo` resource.
51
+
52
+ Each `Admin::FooController` can be overwritten to specify custom behavior.
53
+
54
+ Once you have Administrate installed,
55
+ visit <http://localhost:3000/admin> to see your new dashboard in action.
56
+
57
+ ## Create Additional Dashboards
58
+
59
+ In order to create additional dashboards, pass in the resource name to
60
+ the dashboard generator. A dashboard and controller will be created.
61
+
62
+ ```bash
63
+ $ rails generate administrate:dashboard Foo
64
+ ```
65
+
66
+ Add a route for the new dashboard.
67
+
68
+ ```ruby
69
+ # config/routes.rb
70
+
71
+ namespace :admin do
72
+ resources :foos
73
+ end
74
+ ```
75
+
76
+ ## Rails API
77
+
78
+ Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
79
+ we still want to have an admin.
80
+
81
+ To get this working, we recommend updating this config:
82
+
83
+ ```ruby
84
+ # config/application.rb
85
+ config.api_only = false
86
+ ```
87
+
88
+ That means, when your app _boots_, we'll have access to flashes and such. We
89
+ also don't use your `ApplicationController`. Instead, Administrate provides its
90
+ own. Meaning you're free to specify `ActionController::API` as your parent
91
+ controller to make sure no flash, session, or cookie middleware is used by your
92
+ API.
93
+
94
+ Alternatively, if your application needs to have `config.api_only = true`, we recommend you add the following lines to your `config/application.rb`
95
+
96
+ ```ruby
97
+ # Enable Flash, Cookies, MethodOverride for Administrate Gem
98
+ config.middleware.use ActionDispatch::Flash
99
+ config.session_store :cookie_store
100
+ config.middleware.use ActionDispatch::Cookies
101
+ config.middleware.use ActionDispatch::Session::CookieStore, config.session_options
102
+ config.middleware.use ::Rack::MethodOverride
103
+ ```
104
+
105
+ You must also ensure that the all the required controller actions are available and accessible as routes since generators in API-only applications only generate some of the required actions. Here is an example:
106
+
107
+ ```ruby
108
+ # routes.rb
109
+ namespace :admin do
110
+ resources name, only: %i(index show new create edit update destroy)
111
+ end
112
+
113
+ # names_controller.rb
114
+ # Ensure each of those methods are defined
115
+ ```
@@ -0,0 +1,4 @@
1
+ require "administrate/engine"
2
+
3
+ module Administrate
4
+ end
@@ -0,0 +1,72 @@
1
+ require "administrate/field/belongs_to"
2
+ require "administrate/field/boolean"
3
+ require "administrate/field/date_time"
4
+ require "administrate/field/email"
5
+ require "administrate/field/has_many"
6
+ require "administrate/field/has_one"
7
+ require "administrate/field/number"
8
+ require "administrate/field/polymorphic"
9
+ require "administrate/field/select"
10
+ require "administrate/field/string"
11
+ require "administrate/field/text"
12
+
13
+ module Administrate
14
+ class BaseDashboard
15
+ include Administrate
16
+
17
+ def attribute_types
18
+ self.class::ATTRIBUTE_TYPES
19
+ end
20
+
21
+ def attribute_type_for(attribute_name)
22
+ attribute_types.fetch(attribute_name) do
23
+ fail attribute_not_found_message(attribute_name)
24
+ end
25
+ end
26
+
27
+ def attribute_types_for(attribute_names)
28
+ attribute_names.each_with_object({}) do |name, attributes|
29
+ attributes[name] = attribute_type_for(name)
30
+ end
31
+ end
32
+
33
+ def form_attributes
34
+ self.class::FORM_ATTRIBUTES
35
+ end
36
+
37
+ def permitted_attributes
38
+ form_attributes.map do |attr|
39
+ attribute_types[attr].permitted_attribute(attr)
40
+ end.uniq
41
+ end
42
+
43
+ def show_page_attributes
44
+ self.class::SHOW_PAGE_ATTRIBUTES
45
+ end
46
+
47
+ def collection_attributes
48
+ self.class::COLLECTION_ATTRIBUTES
49
+ end
50
+
51
+ def display_resource(resource)
52
+ "#{resource.class} ##{resource.id}"
53
+ end
54
+
55
+ def association_includes
56
+ association_classes = [Field::HasMany, Field::HasOne, Field::BelongsTo]
57
+
58
+ collection_attributes.map do |key|
59
+ field = self.class::ATTRIBUTE_TYPES[key]
60
+
61
+ next key if association_classes.include?(field)
62
+ key if association_classes.include?(field.try :deferred_class)
63
+ end.compact
64
+ end
65
+
66
+ private
67
+
68
+ def attribute_not_found_message(attr)
69
+ "Attribute #{attr} could not be found in #{self.class}::ATTRIBUTE_TYPES"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,44 @@
1
+ require "datetime_picker_rails"
2
+ require "jquery-rails"
3
+ require "kaminari"
4
+ require "momentjs-rails"
5
+ require "sass-rails"
6
+ require "selectize-rails"
7
+ require "sprockets/railtie"
8
+
9
+ require "administrate/page/form"
10
+ require "administrate/page/show"
11
+ require "administrate/page/collection"
12
+ require "administrate/order"
13
+ require "administrate/resource_resolver"
14
+ require "administrate/search"
15
+ require "administrate/namespace"
16
+ require "administrate/namespace/resource"
17
+
18
+ module Administrate
19
+ class Engine < ::Rails::Engine
20
+ isolate_namespace Administrate
21
+
22
+ @@javascripts = []
23
+ @@stylesheets = []
24
+
25
+ def self.add_javascript(script)
26
+ @@javascripts << script
27
+ end
28
+
29
+ def self.add_stylesheet(stylesheet)
30
+ @@stylesheets << stylesheet
31
+ end
32
+
33
+ def self.stylesheets
34
+ @@stylesheets
35
+ end
36
+
37
+ def self.javascripts
38
+ @@javascripts
39
+ end
40
+
41
+ add_javascript "administrate/application"
42
+ add_stylesheet "administrate/application"
43
+ end
44
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class Associative < Base
6
+ def display_associated_resource
7
+ associated_dashboard.display_resource(data)
8
+ end
9
+
10
+ protected
11
+
12
+ def associated_dashboard
13
+ "#{associated_class_name}Dashboard".constantize.new
14
+ end
15
+
16
+ def associated_class
17
+ associated_class_name.constantize
18
+ end
19
+
20
+ def associated_class_name
21
+ options.fetch(:class_name, attribute.to_s.singularize.camelcase)
22
+ end
23
+
24
+ def primary_key
25
+ options.fetch(:primary_key, :id)
26
+ end
27
+
28
+ def foreign_key
29
+ options.fetch(:foreign_key, :"#{attribute}_id")
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,54 @@
1
+ require_relative "deferred"
2
+ require "active_support/core_ext/string/inflections"
3
+
4
+ module Administrate
5
+ module Field
6
+ class Base
7
+ def self.with_options(options = {})
8
+ Deferred.new(self, options)
9
+ end
10
+
11
+ def self.html_class
12
+ field_type.dasherize
13
+ end
14
+
15
+ def self.searchable?
16
+ false
17
+ end
18
+
19
+ def initialize(attribute, data, page, options = {})
20
+ @attribute = attribute
21
+ @data = data
22
+ @page = page
23
+ @resource = options.delete(:resource)
24
+ @options = options
25
+ end
26
+
27
+ def self.permitted_attribute(attr)
28
+ attr
29
+ end
30
+
31
+ def html_class
32
+ self.class.html_class
33
+ end
34
+
35
+ def name
36
+ attribute.to_s
37
+ end
38
+
39
+ def to_partial_path
40
+ "/fields/#{self.class.field_type}/#{page}"
41
+ end
42
+
43
+ attr_reader :attribute, :data, :page, :resource
44
+
45
+ protected
46
+
47
+ attr_reader :options
48
+
49
+ def self.field_type
50
+ to_s.split("::").last.underscore
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ require_relative "associative"
2
+
3
+ module Administrate
4
+ module Field
5
+ class BelongsTo < Associative
6
+ def self.permitted_attribute(attr)
7
+ :"#{attr}_id"
8
+ end
9
+
10
+ def permitted_attribute
11
+ foreign_key
12
+ end
13
+
14
+ def associated_resource_options
15
+ [nil] + candidate_resources.map do |resource|
16
+ [display_candidate_resource(resource), resource.send(primary_key)]
17
+ end
18
+ end
19
+
20
+ def selected_option
21
+ data && data.send(primary_key)
22
+ end
23
+
24
+ private
25
+
26
+ def candidate_resources
27
+ order = options.delete(:order)
28
+ order ? associated_class.order(order) : associated_class.all
29
+ end
30
+
31
+ def display_candidate_resource(resource)
32
+ associated_dashboard.display_resource(resource)
33
+ end
34
+ end
35
+ end
36
+ end