adminable 0.0.6 → 0.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ddb7fa61bee7a687cdc0c39c37990d5bb521304
4
- data.tar.gz: 39e26845450a55d099ed58a2abc9feb49c151427
3
+ metadata.gz: fe14efbd7a9b891b5bc5589e45c36348e669dbde
4
+ data.tar.gz: f7e2f55e7616fc473e3bdec17a4c7fe99ed87631
5
5
  SHA512:
6
- metadata.gz: 030afe5a4016c70a0ecbd93ab4d42872b2b14307f697d2268f36707c400b8cd0d6a28a93baa939dd4de0ce0cf6b2d89260de5ae618089fc5ee97c0b6fd32d85e
7
- data.tar.gz: be70b417ed4ef1804fd51549fda2443645be24f6cf3463cb9ffbbdafe3df0eef12dc951ec4c0597ce56592b86e439fec6e64c2c06b2d4c0543020b6f2d66f948
6
+ metadata.gz: 15ac25cf770b37f9d7b5a59213328722766d4d90c62e43eb26e150805b795dda42ee9335478f6a73365113fcef04cf1a942bf4ead32ad323beb7222194ae472f
7
+ data.tar.gz: fd6965f302510e697657e792d6f1c83fab0058cfe3b58e5acd1ab49676bd096b6e327de10fdd54ccf40acf252d231792e3153e1e028867cd2b62bc5c9cbc52c5
data/README.md CHANGED
@@ -75,6 +75,7 @@ Change fields as you like inside `fields` method array:
75
75
  class Adminable::Blog::PostsController < Adminable::ResourcesController
76
76
  def fields
77
77
  [
78
+ Adminable::Fields::Integer.new(:id, form: false),
78
79
  Adminable::Fields::String.new(:title),
79
80
  Adminable::Fields::Text.new(:body),
80
81
  Adminable::Fields::Float.new(:rating, form: false),
@@ -105,6 +106,7 @@ Adds `text-align: center` for field value on index page.
105
106
 
106
107
  #### search
107
108
  `true` or `false`, default: `false`.
109
+
108
110
  Enables search for this field.
109
111
 
110
112
  ### See Also
@@ -83,7 +83,7 @@ module Adminable
83
83
  end
84
84
 
85
85
  def set_fields
86
- @fields = Adminable::Presenters::Fields.new(fields)
86
+ @fields = Adminable::Decorators::Fields.new(fields)
87
87
  end
88
88
 
89
89
  def resource_model_name
@@ -0,0 +1,3 @@
1
+ = render 'adminable/shared/label', field: field
2
+ %p.form-control-static
3
+ = Adminable::Presenters::Entry.new(entry, field: field).has_one_value
@@ -0,0 +1,2 @@
1
+ - if value
2
+ = Adminable::Presenters::Entry.new(value).link_to_self
@@ -5,6 +5,7 @@ en:
5
5
  confirm: Are you sure?
6
6
  not_selected: Not selected
7
7
  and_more: and %{size} more.
8
+ no_has_one: "%{resource} is not selected."
8
9
  buttons:
9
10
  submit: Submit
10
11
  back: Back
@@ -5,6 +5,7 @@ ru:
5
5
  confirm: Вы уверены?
6
6
  not_selected: Не выбрано
7
7
  and_more: и еще %{size}.
8
+ no_has_one: "%{resource} не выбран."
8
9
  buttons:
9
10
  submit: Сохранить
10
11
  back: Назад
@@ -7,7 +7,8 @@ require 'adminable/resource'
7
7
  require 'adminable/presenters/base'
8
8
  require 'adminable/presenters/entry'
9
9
  require 'adminable/presenters/entries'
10
- require 'adminable/presenters/fields'
10
+
11
+ require 'adminable/decorators/fields'
11
12
 
12
13
  require 'adminable/field_collector'
13
14
 
@@ -19,6 +20,7 @@ require 'adminable/fields/datetime'
19
20
  require 'adminable/fields/decimal'
20
21
  require 'adminable/fields/float'
21
22
  require 'adminable/fields/has_many'
23
+ require 'adminable/fields/has_one'
22
24
  require 'adminable/fields/integer'
23
25
  require 'adminable/fields/string'
24
26
  require 'adminable/fields/text'
@@ -1,5 +1,5 @@
1
1
  module Adminable
2
- module Presenters
2
+ module Decorators
3
3
  class Fields < SimpleDelegator
4
4
  def index
5
5
  select { |field| field.options[:index] }
@@ -17,8 +17,6 @@ module Adminable
17
17
 
18
18
  # Collects fields from model columns
19
19
  # @return [Array]
20
- #
21
- # rubocop:disable Metrics/MethodLength
22
20
  def columns
23
21
  @columns ||= [].tap do |fields|
24
22
  @model.columns.reject { |a| a.name.match(/_id$/) }.each do |column|
@@ -0,0 +1,6 @@
1
+ module Adminable
2
+ module Fields
3
+ class HasOne < Base
4
+ end
5
+ end
6
+ end
@@ -1,8 +1,10 @@
1
1
  module Adminable
2
2
  module Presenters
3
3
  class Entry < Base
4
- def initialize(entry)
4
+ def initialize(entry, field: nil)
5
5
  @entry = entry
6
+ @field = field
7
+ @value = entry.public_send(field.name) if field
6
8
  end
7
9
 
8
10
  def to_name
@@ -57,6 +59,22 @@ module Adminable
57
59
  )
58
60
  end
59
61
 
62
+ def has_one_value
63
+ association = @entry.association(@field.name).klass
64
+
65
+ if @value
66
+ Adminable::Presenters::Entry(@value).link_to_self
67
+ else
68
+ view.link_to(
69
+ I18n.t(
70
+ 'adminable.ui.no_has_one',
71
+ resource: association.model_name.human
72
+ ),
73
+ polymorphic_path(association),
74
+ )
75
+ end
76
+ end
77
+
60
78
  def method_missing(method_name, *args, &block)
61
79
  entry.public_send(method_name, *args, &block)
62
80
  end
@@ -1,3 +1,3 @@
1
1
  module Adminable
2
- VERSION = '0.0.6'.freeze
2
+ VERSION = '0.0.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adminable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Novikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -343,6 +343,7 @@ files:
343
343
  - app/views/adminable/resources/form/_decimal.html.haml
344
344
  - app/views/adminable/resources/form/_float.html.haml
345
345
  - app/views/adminable/resources/form/_has_many.html.haml
346
+ - app/views/adminable/resources/form/_has_one.html.haml
346
347
  - app/views/adminable/resources/form/_integer.html.haml
347
348
  - app/views/adminable/resources/form/_string.html.haml
348
349
  - app/views/adminable/resources/form/_text.html.haml
@@ -356,6 +357,7 @@ files:
356
357
  - app/views/adminable/resources/index/_decimal.html.haml
357
358
  - app/views/adminable/resources/index/_float.html.haml
358
359
  - app/views/adminable/resources/index/_has_many.html.haml
360
+ - app/views/adminable/resources/index/_has_one.html.haml
359
361
  - app/views/adminable/resources/index/_integer.html.haml
360
362
  - app/views/adminable/resources/index/_string.html.haml
361
363
  - app/views/adminable/resources/index/_text.html.haml
@@ -371,6 +373,7 @@ files:
371
373
  - config/routes.rb
372
374
  - lib/adminable.rb
373
375
  - lib/adminable/configuration.rb
376
+ - lib/adminable/decorators/fields.rb
374
377
  - lib/adminable/engine.rb
375
378
  - lib/adminable/errors.rb
376
379
  - lib/adminable/field_collector.rb
@@ -382,6 +385,7 @@ files:
382
385
  - lib/adminable/fields/decimal.rb
383
386
  - lib/adminable/fields/float.rb
384
387
  - lib/adminable/fields/has_many.rb
388
+ - lib/adminable/fields/has_one.rb
385
389
  - lib/adminable/fields/integer.rb
386
390
  - lib/adminable/fields/string.rb
387
391
  - lib/adminable/fields/text.rb
@@ -390,7 +394,6 @@ files:
390
394
  - lib/adminable/presenters/base.rb
391
395
  - lib/adminable/presenters/entries.rb
392
396
  - lib/adminable/presenters/entry.rb
393
- - lib/adminable/presenters/fields.rb
394
397
  - lib/adminable/resource.rb
395
398
  - lib/adminable/version.rb
396
399
  - lib/generators/adminable/install/templates/application_controller.rb