administrate 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of administrate might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab74a9176bf14060fc26e4346b4fca17b2672371
4
- data.tar.gz: 990b4f062e37a68c7be97ee5104323d00e99a4ad
3
+ metadata.gz: f99e940d39ae750c539424f5430bd5f07c1d33a5
4
+ data.tar.gz: 8d9917e0b8332333309afdefe113cac7c3b0caee
5
5
  SHA512:
6
- metadata.gz: 4f04b6bea3d168597600b14b390ec6ea6bc14836cf3236b34a0982b4067468c161b8014f253e8d4ca7ccac898aaac8ca9093dcf7143cc32aa51b8f6d54834c98
7
- data.tar.gz: ec346e46a0ed10bbd38d14f5bffc2859fd8047467a1be90360a9b8fdc3dc8d7ebc67aa7472d9537c99527e7fd10960806a58502b88d7f6e4fddcb86e529adc72
6
+ metadata.gz: 32889166105790ee128bef195cba90618686b5a00d90a0c48195faa46d4b580c48032ce48145cf713348029048a288f51018cce289fa16402c43b0d89286fc49
7
+ data.tar.gz: 4abd94bd39f09afb5b0054338b076e0f144f2d4b27473a2051d0a03c37fe4de7ca97b55d4c8b0ce80471900fe08ef3db8b2bce802a51a4298b6695373072d313
@@ -11,7 +11,8 @@ $(function() {
11
11
  }
12
12
 
13
13
  var dataUrl = $(event.target).closest("tr").data("url");
14
- if (dataUrl) {
14
+ var selection = window.getSelection().toString();
15
+ if (selection.length === 0 && dataUrl) {
15
16
  window.location = dataUrl;
16
17
  }
17
18
  }
@@ -7,6 +7,25 @@
7
7
  @import "selectize";
8
8
  @import "datetime_picker";
9
9
 
10
- @import "library/**/*";
11
- @import "base/**/*";
12
- @import "components/**/*";
10
+ @import "library/data-label";
11
+ @import "library/variables";
12
+
13
+ @import "base/forms";
14
+ @import "base/layout";
15
+ @import "base/lists";
16
+ @import "base/tables";
17
+ @import "base/typography";
18
+
19
+ @import "components/app-container";
20
+ @import "components/attributes";
21
+ @import "components/buttons";
22
+ @import "components/cells";
23
+ @import "components/field-unit";
24
+ @import "components/flashes";
25
+ @import "components/form-actions";
26
+ @import "components/header";
27
+ @import "components/main-content";
28
+ @import "components/pagination";
29
+ @import "components/search";
30
+ @import "components/sidebar";
31
+ @import "components/table";
@@ -5,6 +5,7 @@ module Administrate
5
5
  def index
6
6
  search_term = params[:search].to_s.strip
7
7
  resources = Administrate::Search.new(resource_resolver, search_term).run
8
+ resources = resources.includes(*resource_includes) if resource_includes.any?
8
9
  resources = order.apply(resources)
9
10
  resources = resources.page(params[:page]).per(records_per_page)
10
11
  page = Administrate::Page::Collection.new(dashboard, order: order)
@@ -73,11 +74,7 @@ module Administrate
73
74
 
74
75
  helper_method :nav_link_state
75
76
  def nav_link_state(resource)
76
- if resource_name.to_s.pluralize == resource.to_s
77
- :active
78
- else
79
- :inactive
80
- end
77
+ resource_name.to_s.pluralize == resource.to_s ? :active : :inactive
81
78
  end
82
79
 
83
80
  helper_method :valid_action?
@@ -111,6 +108,10 @@ module Administrate
111
108
  resource_class.find(param)
112
109
  end
113
110
 
111
+ def resource_includes
112
+ dashboard.association_includes
113
+ end
114
+
114
115
  def resource_params
115
116
  params.require(resource_name).permit(dashboard.permitted_attributes)
116
117
  end
@@ -12,7 +12,7 @@ as defined by the routes in the `admin/` namespace
12
12
  <li>
13
13
  <%= link_to(
14
14
  display_resource_name(resource),
15
- [namespace, resource],
15
+ [namespace, resource.path],
16
16
  class: "sidebar__link sidebar__link--#{nav_link_state(resource)}"
17
17
  ) %>
18
18
  </li>
@@ -38,7 +38,7 @@ It renders the `_table` partial to display details about the resources.
38
38
  <div class="header__actions">
39
39
  <%= link_to(
40
40
  "#{t("administrate.actions.new")} #{page.resource_name.titleize.downcase}",
41
- [:new, namespace, page.resource_name],
41
+ [:new, namespace, page.resource_path],
42
42
  class: "button",
43
43
  ) if valid_action? :new %>
44
44
  </div>
@@ -6,8 +6,8 @@ ja:
6
6
  destroy: 削除
7
7
  edit: 編集
8
8
  show: 参照
9
- new: 目新しい
10
- back: バック
9
+ new: 新規
10
+ back: 戻る
11
11
  controller:
12
12
  create:
13
13
  success: "%{resource}を作成しました。"
@@ -7,7 +7,7 @@ pl:
7
7
  edit: Edytuj
8
8
  show: Wyświetl
9
9
  new: Nowy
10
- back: Plecy
10
+ back: Wstecz
11
11
  controller:
12
12
  create:
13
13
  success: "Zasób %{resource} został pomyślnie utworzony."
@@ -6,15 +6,15 @@ uk:
6
6
  destroy: Видалити
7
7
  edit: Редагувати
8
8
  show: Показати
9
- new: новий
10
- back: назад
9
+ new: Новий
10
+ back: Назад
11
11
  controller:
12
12
  create:
13
- success: "%{resource} було успішно створено."
13
+ success: "Успішно створено %{resource}."
14
14
  destroy:
15
- success: "%{resource} було успішно видалено."
15
+ success: "Успішно видалено %{resource}."
16
16
  update:
17
- success: "%{resource} було успішно оновлено."
17
+ success: "Успішно оновлено %{resource}."
18
18
  fields:
19
19
  has_many:
20
20
  more: "%{count} із %{total_count}"
@@ -6,8 +6,8 @@ zh-TW:
6
6
  destroy: 刪除
7
7
  edit: 編輯
8
8
  show: 檢視
9
- new: 删除
10
- back: 背部
9
+ new: 新增
10
+ back: 返回
11
11
  controller:
12
12
  create:
13
13
  success: "已成功新增 %{resource}。"
@@ -1,7 +1,8 @@
1
1
  # Authenticating admin users
2
2
 
3
3
  Authentication is left for you to implement after you install Administrate into
4
- your app. You can easily plugin your existing authentication system.
4
+ your app. It's expected that you can plugin your existing authentication
5
+ system.
5
6
 
6
7
  The base `Admin::ApplicationController` has a `TODO` to be completed:
7
8
 
@@ -3,7 +3,7 @@
3
3
  When you install Administrate into your app,
4
4
  we generate empty controllers for each of your resources.
5
5
  If you want to create more complex application behavior for a dashboard,
6
- simply overwrite controller actions.
6
+ you can overwrite controller actions.
7
7
 
8
8
  The generated controller will look something like:
9
9
 
@@ -74,12 +74,18 @@ which are specified through the `.with_options` class method:
74
74
  `:limit` - Set the number of resources to display in the show view. Default is
75
75
  `5`.
76
76
 
77
+ `:sort_by` - What to sort the association by in the show view.
78
+
79
+ `:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.
80
+
77
81
  **Field::Number**
78
82
 
79
83
  `:decimals` - Set the number of decimals to display. Defaults to `0`.
80
84
 
81
85
  `:prefix` - Prefixes the number with a string. Defaults to `""`.
82
86
 
87
+ `:suffix` - Suffixes the number with a string. Defaults to `""`.
88
+
83
89
  For example, you might use the following to display U.S. currency:
84
90
 
85
91
  ```ruby
@@ -89,6 +95,15 @@ For example, you might use the following to display U.S. currency:
89
95
  )
90
96
  ```
91
97
 
98
+ Or, to display a distance in kilometers:
99
+
100
+ ```ruby
101
+ unit_price: Field::Number.with_options(
102
+ suffix: " km",
103
+ decimals: 2,
104
+ )
105
+ ```
106
+
92
107
  **Field::Select**
93
108
 
94
109
  `:collection` - Specify the array or range to select from. Defaults to `[]`.
@@ -42,7 +42,7 @@ visit <http://localhost:3000/admin> to see your new dashboard in action.
42
42
 
43
43
  ## Create Additional Dashboards
44
44
 
45
- In order to create additional dashboards, pass in the resource name to
45
+ In order to create additional dashboards, pass in the resource name to
46
46
  the dashboard generator. A dashboard and controller will be created.
47
47
 
48
48
  ```bash
@@ -58,3 +58,19 @@ namespace :admin do
58
58
  resources :foos
59
59
  end
60
60
  ```
61
+
62
+ ## Rails API
63
+
64
+ Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
65
+ we still want to have an admin. To get this working, please update this config:
66
+
67
+ ```ruby
68
+ # config/application.rb
69
+ config.api_only = false
70
+ ```
71
+
72
+ That means, when your app _boots_, we'll have access to flashes and such. We
73
+ also don't use your `ApplicationController`. Instead, Administrate provides its
74
+ own. Meaning you're free to specify `ActionController::API` as your parent
75
+ controller to make sure no flash, session, or cookie middleware is used by your
76
+ API.
@@ -52,6 +52,17 @@ module Administrate
52
52
  "#{resource.class} ##{resource.id}"
53
53
  end
54
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
+
55
66
  private
56
67
 
57
68
  def attribute_not_found_message(attr)
@@ -16,6 +16,7 @@ require "administrate/order"
16
16
  require "administrate/resource_resolver"
17
17
  require "administrate/search"
18
18
  require "administrate/namespace"
19
+ require "administrate/namespace/resource"
19
20
 
20
21
  module Administrate
21
22
  class Engine < ::Rails::Engine
@@ -24,7 +25,12 @@ module Administrate
24
25
  @@javascripts = []
25
26
  @@stylesheets = []
26
27
 
27
- Engine.config.assets.precompile << /\.(?:svg)\z/
28
+ Engine.config.assets.precompile << %w(
29
+ administrate/cancel.svg
30
+ administrate/dropdown.svg
31
+ administrate/search.svg
32
+ administrate/sort_arrow.svg
33
+ )
28
34
 
29
35
  def self.add_javascript(script)
30
36
  @@javascripts << script
@@ -1,5 +1,6 @@
1
1
  require_relative "associative"
2
2
  require "administrate/page/collection"
3
+ require "administrate/order"
3
4
 
4
5
  module Administrate
5
6
  module Field
@@ -37,7 +38,8 @@ module Administrate
37
38
  end
38
39
 
39
40
  def resources(page = 1)
40
- data.page(page).per(limit)
41
+ resources = order.apply(data).page(page).per(limit)
42
+ includes.any? ? resources.includes(*includes) : resources
41
43
  end
42
44
 
43
45
  def more_than_limit?
@@ -46,6 +48,10 @@ module Administrate
46
48
 
47
49
  private
48
50
 
51
+ def includes
52
+ associated_dashboard.association_includes
53
+ end
54
+
49
55
  def candidate_resources
50
56
  if options.key?(:includes)
51
57
  includes = options.fetch(:includes)
@@ -58,6 +64,18 @@ module Administrate
58
64
  def display_candidate_resource(resource)
59
65
  associated_dashboard.display_resource(resource)
60
66
  end
67
+
68
+ def order
69
+ @_order ||= Administrate::Order.new(sort_by, direction)
70
+ end
71
+
72
+ def sort_by
73
+ options[:sort_by]
74
+ end
75
+
76
+ def direction
77
+ options[:direction]
78
+ end
61
79
  end
62
80
  end
63
81
  end
@@ -4,11 +4,7 @@ module Administrate
4
4
  module Field
5
5
  class Number < Field::Base
6
6
  def to_s
7
- if data.nil?
8
- "-"
9
- else
10
- format_string % value
11
- end
7
+ data.nil? ? "-" : format_string % value
12
8
  end
13
9
 
14
10
  private
@@ -26,7 +22,9 @@ module Administrate
26
22
  end
27
23
 
28
24
  def decimals
29
- options.fetch(:decimals, 0)
25
+ _left, right = data.to_s.split(".")
26
+ default = right.nil? ? 0 : right.size
27
+ options.fetch(:decimals, default)
30
28
  end
31
29
 
32
30
  def value
@@ -5,7 +5,9 @@ module Administrate
5
5
  end
6
6
 
7
7
  def resources
8
- @resources ||= routes.map(&:first).uniq.map(&:to_sym)
8
+ @resources ||= routes.map(&:first).uniq.map do |path|
9
+ Resource.new(namespace, path)
10
+ end
9
11
  end
10
12
 
11
13
  def routes
@@ -0,0 +1,28 @@
1
+ module Administrate
2
+ class Namespace
3
+ class Resource
4
+ attr_reader :namespace, :resource
5
+
6
+ def initialize(namespace, resource)
7
+ @namespace = namespace
8
+ @resource = resource
9
+ end
10
+
11
+ def to_s
12
+ name.to_s
13
+ end
14
+
15
+ def to_sym
16
+ name
17
+ end
18
+
19
+ def name
20
+ resource.to_s.gsub(/^#{namespace}\//, "").to_sym
21
+ end
22
+
23
+ def path
24
+ name.to_s.gsub("/", "_")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -11,6 +11,10 @@ module Administrate
11
11
  dashboard.class.to_s.scan(/(.+)Dashboard/).first.first.underscore
12
12
  end
13
13
 
14
+ def resource_path
15
+ @resource_path ||= resource_name.gsub("/", "_")
16
+ end
17
+
14
18
  protected
15
19
 
16
20
  def attribute_field(dashboard, resource, attribute_name, page)
@@ -21,7 +21,12 @@ module Administrate
21
21
  delegate :resource_class, to: :resolver
22
22
 
23
23
  def query
24
- search_attributes.map { |attr| "lower(#{attr}) LIKE ?" }.join(" OR ")
24
+ search_attributes.map do |attr|
25
+ table_name = ActiveRecord::Base.connection.
26
+ quote_table_name(resource_class.table_name)
27
+ attr_name = ActiveRecord::Base.connection.quote_column_name(attr)
28
+ "lower(#{table_name}.#{attr_name}) LIKE ?"
29
+ end.join(" OR ")
25
30
  end
26
31
 
27
32
  def search_terms
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.5.0".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  end
@@ -1,7 +1,7 @@
1
1
  module Admin
2
2
  class <%= class_name.pluralize %>Controller < Admin::ApplicationController
3
3
  # To customize the behavior of this controller,
4
- # simply overwrite any of the RESTful actions. For example:
4
+ # you can overwrite any of the RESTful actions. For example:
5
5
  #
6
6
  # def index
7
7
  # super
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Charlton
@@ -9,8 +9,68 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-27 00:00:00.000000000 Z
12
+ date: 2017-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionpack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '4.2'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '5.1'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '4.2'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.1'
34
+ - !ruby/object:Gem::Dependency
35
+ name: actionview
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '5.1'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '4.2'
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.1'
54
+ - !ruby/object:Gem::Dependency
55
+ name: activerecord
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '4.2'
61
+ - - "<"
62
+ - !ruby/object:Gem::Version
63
+ version: '5.1'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '4.2'
71
+ - - "<"
72
+ - !ruby/object:Gem::Version
73
+ version: '5.1'
14
74
  - !ruby/object:Gem::Dependency
15
75
  name: autoprefixer-rails
16
76
  requirement: !ruby/object:Gem::Requirement
@@ -123,26 +183,6 @@ dependencies:
123
183
  - - ">="
124
184
  - !ruby/object:Gem::Version
125
185
  version: '3.0'
126
- - !ruby/object:Gem::Dependency
127
- name: rails
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: '4.2'
133
- - - "<"
134
- - !ruby/object:Gem::Version
135
- version: '5.1'
136
- type: :runtime
137
- prerelease: false
138
- version_requirements: !ruby/object:Gem::Requirement
139
- requirements:
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- version: '4.2'
143
- - - "<"
144
- - !ruby/object:Gem::Version
145
- version: '5.1'
146
186
  - !ruby/object:Gem::Dependency
147
187
  name: sass-rails
148
188
  requirement: !ruby/object:Gem::Requirement
@@ -220,11 +260,10 @@ files:
220
260
  - app/assets/stylesheets/administrate/components/_search.scss
221
261
  - app/assets/stylesheets/administrate/components/_sidebar.scss
222
262
  - app/assets/stylesheets/administrate/components/_table.scss
223
- - app/assets/stylesheets/administrate/library/_data_label.scss
263
+ - app/assets/stylesheets/administrate/library/_data-label.scss
224
264
  - app/assets/stylesheets/administrate/library/_variables.scss
225
265
  - app/assets/stylesheets/docs.scss
226
266
  - app/controllers/administrate/application_controller.rb
227
- - app/controllers/docs_controller.rb
228
267
  - app/helpers/administrate/application_helper.rb
229
268
  - app/views/administrate/application/_collection.html.erb
230
269
  - app/views/administrate/application/_flashes.html.erb
@@ -271,7 +310,6 @@ files:
271
310
  - app/views/fields/text/_index.html.erb
272
311
  - app/views/fields/text/_show.html.erb
273
312
  - app/views/layouts/administrate/application.html.erb
274
- - app/views/layouts/docs.html.erb
275
313
  - config/i18n-tasks.yml
276
314
  - config/locales/administrate.ar.yml
277
315
  - config/locales/administrate.da.yml
@@ -321,6 +359,7 @@ files:
321
359
  - lib/administrate/field/text.rb
322
360
  - lib/administrate/generator_helpers.rb
323
361
  - lib/administrate/namespace.rb
362
+ - lib/administrate/namespace/resource.rb
324
363
  - lib/administrate/order.rb
325
364
  - lib/administrate/page.rb
326
365
  - lib/administrate/page/base.rb
@@ -378,7 +417,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
378
417
  version: '0'
379
418
  requirements: []
380
419
  rubyforge_project:
381
- rubygems_version: 2.5.2
420
+ rubygems_version: 2.6.11
382
421
  signing_key:
383
422
  specification_version: 4
384
423
  summary: A Rails engine for creating super-flexible admin dashboards
@@ -1,9 +0,0 @@
1
- class DocsController < ApplicationController
2
- def index
3
- render file: "README"
4
- end
5
-
6
- def show
7
- render file: "docs/#{params[:page]}"
8
- end
9
- end
@@ -1,40 +0,0 @@
1
- <html>
2
- <head>
3
- <%= stylesheet_link_tag "docs", media: "all" %>
4
- <link href='//fonts.googleapis.com/css?family=Lato|Source+Code+Pro|Fjalla+One' rel='stylesheet' type='text/css'>
5
- <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/default.min.css">
6
- </head>
7
-
8
- <body>
9
- <div class="content">
10
- <div class="sidebar">
11
- <h1>Administrate</h1>
12
-
13
- <ul class="sidebar-links">
14
- <li><a href="/">Home</a></li>
15
- <li><a href="https://github.com/thoughtbot/administrate/issues/new">Feedback</a></li>
16
- </ul>
17
-
18
- <h3>Documentation</h3>
19
-
20
- <ul class="sidebar-links">
21
- <li><a href="/">README</a></li>
22
- <li><a href="/getting_started">Getting Started</a></li>
23
- <li><a href="/customizing_dashboards">Customizing Dashboards</a></li>
24
- <li><a href="/customizing_page_views">Customizing Page Views</a></li>
25
- <li><a href="/customizing_attribute_partials">Customizing Attribute Partials</a></li>
26
- <li><a href="/adding_custom_field_types">Adding Custom Field Types</a></li>
27
- <li><a href="/customizing_controller_actions">Customizing Controller Actions</a></li>
28
- <li><a href="/authentication">Authentication</a></li>
29
- </ul>
30
- </div>
31
-
32
- <div class="main">
33
- <%= yield %>
34
- </div>
35
- </div>
36
-
37
- <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
38
- <script>hljs.initHighlightingOnLoad();</script>
39
- </body>
40
- </html>