adminable 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -4
- data/app/controllers/adminable/resources_controller.rb +8 -5
- data/app/views/adminable/resources/form/_belongs_to.html.haml +2 -4
- data/app/views/adminable/resources/form/_has_many.html.haml +1 -1
- data/app/views/adminable/resources/index.html.haml +1 -1
- data/app/views/adminable/resources/index/_belongs_to.html.haml +2 -4
- data/app/views/adminable/resources/index/_has_many.html.haml +2 -2
- data/lib/adminable.rb +3 -3
- data/lib/adminable/attributes/association.rb +2 -2
- data/lib/adminable/attributes/base.rb +1 -1
- data/lib/adminable/configuration.rb +0 -4
- data/lib/adminable/presenters/base.rb +13 -0
- data/lib/adminable/presenters/entries.rb +57 -0
- data/lib/adminable/presenters/entry.rb +81 -0
- data/lib/adminable/resource.rb +5 -2
- data/lib/adminable/version.rb +1 -1
- data/lib/generators/adminable/partial_generator.rb +26 -0
- metadata +7 -6
- data/lib/adminable/presenters/base_presenter.rb +0 -11
- data/lib/adminable/presenters/entries_presenter.rb +0 -55
- data/lib/adminable/presenters/entry_presenter.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a219dbfca42335cddb071f1e9d2f24a08bb22992
|
4
|
+
data.tar.gz: 4be60a789135b4f404aa268b440bdd88a1705bac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9fc788109f641c6c626af0e5e63d822a119b0a8ffca8e5e2359ff0907daea3bd830158174d7f12f4c502852f5b56ef6b98721806080bd08dcff5a0dd2159fb2
|
7
|
+
data.tar.gz: ef331388d6bd326f84c82d9736001cce5f7af8c7f69093d297578f9b5f5d7f1e837dcfe5e11b27fd6849c7fa38471ec37b3853b6fa78947d32f3f929b86da174
|
data/README.md
CHANGED
@@ -85,10 +85,10 @@ You can update attributes with simple DSL inside `set_attributes` block:
|
|
85
85
|
|
86
86
|
##### Attributes Parameters
|
87
87
|
|
88
|
-
* `index` -
|
89
|
-
* `form` -
|
90
|
-
* `center` -
|
91
|
-
* `search` -
|
88
|
+
* `index` - (`true` or `false`) - Shows attribute on index page.
|
89
|
+
* `form` - (`true` or `false`) - Shows attribute on new/edit page.
|
90
|
+
* `center` - (`true` or `false`) - Adds `text-align: center` for attribute value on index page.
|
91
|
+
* `search` - (`true` or `false`) - Enables search for this attribute.
|
92
92
|
|
93
93
|
##### Examples
|
94
94
|
|
@@ -139,6 +139,16 @@ List of attributes with default parameters.
|
|
139
139
|
| Belongs To | | + | | |
|
140
140
|
| Has Many | | + | | |
|
141
141
|
|
142
|
+
## Generating Partials
|
143
|
+
|
144
|
+
You can use generator to copy original partial to your application.
|
145
|
+
|
146
|
+
`rails g adminable:partial [layout] [type] [resource]`
|
147
|
+
|
148
|
+
* `layout` - `index` or `form`.
|
149
|
+
* `type` - `string`, `text` etc. See [Built-in Attributes](#built-in-attributes).
|
150
|
+
* `resource` - Use controller name (e.g. `users`) to replace partial only for single controller or leave blank to replace partials for all controllers.
|
151
|
+
|
142
152
|
## Contributing
|
143
153
|
|
144
154
|
1. Fork it (https://github.com/droptheplot/adminable/fork)
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module Adminable
|
2
2
|
class ResourcesController < ApplicationController
|
3
3
|
def initialize(*)
|
4
|
-
@resource = Adminable::Configuration.
|
4
|
+
@resource = Adminable::Configuration.resources.find do |resource|
|
5
|
+
resource == Adminable::Resource.new(resource_model_name)
|
6
|
+
end
|
5
7
|
|
6
8
|
super
|
7
9
|
end
|
@@ -11,7 +13,8 @@ module Adminable
|
|
11
13
|
before_action do
|
12
14
|
append_view_path(
|
13
15
|
[
|
14
|
-
|
16
|
+
Rails.root.join('app/views', controller_path),
|
17
|
+
Rails.root.join('app/views/adminable/resources'),
|
15
18
|
Adminable::Engine.root.join('app/views/adminable/resources')
|
16
19
|
]
|
17
20
|
)
|
@@ -19,7 +22,7 @@ module Adminable
|
|
19
22
|
|
20
23
|
def index
|
21
24
|
@q = @resource.model.ransack(params[:q])
|
22
|
-
@entries = Adminable::
|
25
|
+
@entries = Adminable::Presenters::Entries.new(
|
23
26
|
@q.result.includes(*@resource.includes).order(id: :desc)
|
24
27
|
.page(params[:page]).per(25)
|
25
28
|
)
|
@@ -100,12 +103,12 @@ module Adminable
|
|
100
103
|
private
|
101
104
|
|
102
105
|
def set_entry
|
103
|
-
@entry = Adminable::
|
106
|
+
@entry = Adminable::Presenters::Entry.new(
|
104
107
|
@resource.model.find(params[:id])
|
105
108
|
)
|
106
109
|
end
|
107
110
|
|
108
|
-
def
|
111
|
+
def resource_model_name
|
109
112
|
controller_path.sub(%r{^adminable/}, '')
|
110
113
|
end
|
111
114
|
|
@@ -2,12 +2,10 @@
|
|
2
2
|
= hidden_field_tag "#{@resource.model.model_name.param_key}[#{attribute.key}]", nil
|
3
3
|
#clusterizeScrollArea.clusterize-scroll.associations
|
4
4
|
#clusterizeContentArea.clusterize-content
|
5
|
-
- attribute.association.
|
5
|
+
- attribute.association.entries.each do |association_entry|
|
6
6
|
.association
|
7
7
|
%label.c-input.c-radio.m-a-0
|
8
8
|
= radio_button_tag "#{@resource.model.model_name.param_key}[#{attribute.key}]",
|
9
9
|
association_entry.id, entry.send(attribute.key) == association_entry.id
|
10
10
|
%span.c-indicator
|
11
|
-
=
|
12
|
-
edit_polymorphic_path(association_entry),
|
13
|
-
target: '_blank'
|
11
|
+
= association_entry.link_to_self
|
@@ -2,7 +2,7 @@
|
|
2
2
|
= hidden_field_tag "#{@resource.model.model_name.param_key}[#{attribute.key}][]", nil
|
3
3
|
#clusterizeScrollArea.clusterize-scroll.associations
|
4
4
|
#clusterizeContentArea.clusterize-content
|
5
|
-
- attribute.association.
|
5
|
+
- attribute.association.entries.each do |association_entry|
|
6
6
|
.association
|
7
7
|
%label.c-input.c-checkbox.m-a-0
|
8
8
|
= check_box_tag "#{@resource.model.model_name.param_key}[#{attribute.key}][]",
|
@@ -19,7 +19,7 @@
|
|
19
19
|
- @resource.attributes.index.each do |attribute|
|
20
20
|
%td{ :class => ('text-md-center' if attribute.options[:center]) }
|
21
21
|
= render attribute.index_partial_path, entry: entry,
|
22
|
-
attribute: attribute, value: entry
|
22
|
+
attribute: attribute, value: entry.public_send(attribute.name)
|
23
23
|
%td.text-nowrap.text-md-right
|
24
24
|
= entry.link_to_edit_small
|
25
25
|
= entry.link_to_delete_small
|
@@ -1,2 +1,2 @@
|
|
1
|
-
- if
|
2
|
-
= Adminable::
|
1
|
+
- if value
|
2
|
+
= Adminable::Presenters::Entries.new(value).to_s
|
data/lib/adminable.rb
CHANGED
@@ -4,9 +4,9 @@ require 'adminable/errors'
|
|
4
4
|
|
5
5
|
require 'adminable/resource'
|
6
6
|
|
7
|
-
require 'adminable/presenters/
|
8
|
-
require 'adminable/presenters/
|
9
|
-
require 'adminable/presenters/
|
7
|
+
require 'adminable/presenters/base'
|
8
|
+
require 'adminable/presenters/entry'
|
9
|
+
require 'adminable/presenters/entries'
|
10
10
|
|
11
11
|
require 'adminable/attributes/collection'
|
12
12
|
require 'adminable/attributes/association'
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Adminable
|
2
2
|
module Attributes
|
3
3
|
class Association
|
4
|
-
attr_reader :reflection, :model, :
|
4
|
+
attr_reader :reflection, :model, :entries
|
5
5
|
|
6
6
|
# @param reflection [Object] ActiveRecord::Reflection::HasManyReflection
|
7
7
|
def initialize(reflection)
|
8
8
|
@reflection = reflection
|
9
9
|
@model = @reflection.klass
|
10
|
-
@
|
10
|
+
@entries = Adminable::Presenters::Entries.new(@model)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -12,10 +12,6 @@ module Adminable
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.find_resource(name)
|
16
|
-
resources.find { |resource| resource.name == name }
|
17
|
-
end
|
18
|
-
|
19
15
|
def self.resources_paths
|
20
16
|
Dir[Rails.root.join('app/controllers/adminable/**/*_controller.rb')]
|
21
17
|
.reject { |f| f['app/controllers/adminable/application_controller.rb'] }
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Adminable
|
2
|
+
module Presenters
|
3
|
+
class Entries < Base
|
4
|
+
ENTRIES_LIMIT = 5
|
5
|
+
|
6
|
+
include Enumerable
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :@collection, :each, :first, :last, :empty?
|
10
|
+
def_delegators(
|
11
|
+
*%i(
|
12
|
+
@relation
|
13
|
+
current_page
|
14
|
+
total_pages
|
15
|
+
limit_value
|
16
|
+
entry_name
|
17
|
+
total_count
|
18
|
+
offset_value
|
19
|
+
last_page?
|
20
|
+
)
|
21
|
+
)
|
22
|
+
|
23
|
+
def initialize(relation)
|
24
|
+
@relation = relation
|
25
|
+
@collection = relation.all.map do |entry|
|
26
|
+
Adminable::Presenters::Entry.new(entry)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
string = collection.first(ENTRIES_LIMIT).map do |entry|
|
32
|
+
view.link_to(entry.to_name, edit_polymorphic_path(entry))
|
33
|
+
end
|
34
|
+
|
35
|
+
string << and_more_tag if collection_size_residue > 0
|
36
|
+
|
37
|
+
string.join(', ').html_safe
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_accessor :relation, :collection
|
43
|
+
|
44
|
+
def collection_size_residue
|
45
|
+
@collection_residue ||= collection.size - ENTRIES_LIMIT
|
46
|
+
end
|
47
|
+
|
48
|
+
def and_more_tag
|
49
|
+
view.content_tag(
|
50
|
+
:span,
|
51
|
+
I18n.t('adminable.ui.and_more', size: collection_size_residue),
|
52
|
+
class: 'text-muted'
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Adminable
|
2
|
+
module Presenters
|
3
|
+
class Entry < Base
|
4
|
+
def initialize(entry)
|
5
|
+
@entry = entry
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_name
|
9
|
+
%i(name title email login id).each do |method_name|
|
10
|
+
begin
|
11
|
+
return entry.public_send(method_name)
|
12
|
+
rescue NoMethodError
|
13
|
+
next
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def link_to_self
|
19
|
+
return to_name unless resource
|
20
|
+
|
21
|
+
view.link_to(
|
22
|
+
to_name,
|
23
|
+
edit_polymorphic_path(entry),
|
24
|
+
target: '_blank'
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def link_to_delete
|
29
|
+
view.link_to(
|
30
|
+
I18n.t('adminable.buttons.delete'),
|
31
|
+
polymorphic_path(@entry),
|
32
|
+
class: 'btn btn-danger-outline pull-xs-right',
|
33
|
+
method: :delete,
|
34
|
+
data: {
|
35
|
+
confirm: I18n.t('adminable.ui.confirm')
|
36
|
+
}
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def link_to_edit_small
|
41
|
+
view.link_to(
|
42
|
+
I18n.t('adminable.buttons.edit'),
|
43
|
+
edit_polymorphic_path(entry),
|
44
|
+
class: 'label label-primary'
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def link_to_delete_small
|
49
|
+
view.link_to(
|
50
|
+
I18n.t('adminable.buttons.delete'),
|
51
|
+
polymorphic_path(entry),
|
52
|
+
class: 'label label-danger',
|
53
|
+
method: :delete,
|
54
|
+
data: {
|
55
|
+
confirm: I18n.t('adminable.ui.confirm')
|
56
|
+
}
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def method_missing(method_name, *args, &block)
|
61
|
+
entry.public_send(method_name, *args, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
def respond_to_missing?(method_name, *)
|
65
|
+
entry.respond_to?(method_name)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
attr_accessor :entry
|
71
|
+
|
72
|
+
def resource
|
73
|
+
Adminable::Configuration.resources.find do |resource|
|
74
|
+
resource == Adminable::Resource.new(
|
75
|
+
entry.class.name.pluralize.underscore
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/adminable/resource.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Adminable
|
2
2
|
class Resource
|
3
|
-
attr_reader :name, :model
|
4
|
-
attr_writer :attributes
|
3
|
+
attr_reader :name, :model, :attributes
|
5
4
|
|
6
5
|
# @param name [String] resource name, usually same as the model name
|
7
6
|
def initialize(name)
|
@@ -27,5 +26,9 @@ module Adminable
|
|
27
26
|
def attributes
|
28
27
|
@attributes ||= Adminable::Attributes::Collection.new(@model)
|
29
28
|
end
|
29
|
+
|
30
|
+
def ==(other)
|
31
|
+
other.is_a?(Adminable::Resource) && name == other.name
|
32
|
+
end
|
30
33
|
end
|
31
34
|
end
|
data/lib/adminable/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Adminable
|
4
|
+
module Generators
|
5
|
+
class PartialGenerator < Rails::Generators::Base
|
6
|
+
source_root Adminable::Engine.root.join('app/views/adminable/resources')
|
7
|
+
|
8
|
+
argument :layout, type: :string, default: 'index'
|
9
|
+
argument :type, type: :string, default: 'string'
|
10
|
+
argument :resource, type: :string, default: 'resources'
|
11
|
+
|
12
|
+
def copy_partial
|
13
|
+
template(
|
14
|
+
File.join(partial_path),
|
15
|
+
File.join('app/views/adminable', resource, partial_path)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def partial_path
|
22
|
+
File.join(layout, "_#{type}.html.haml")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
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.
|
4
|
+
version: 0.0.4
|
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-
|
11
|
+
date: 2016-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -388,13 +388,14 @@ files:
|
|
388
388
|
- lib/adminable/configuration.rb
|
389
389
|
- lib/adminable/engine.rb
|
390
390
|
- lib/adminable/errors.rb
|
391
|
-
- lib/adminable/presenters/
|
392
|
-
- lib/adminable/presenters/
|
393
|
-
- lib/adminable/presenters/
|
391
|
+
- lib/adminable/presenters/base.rb
|
392
|
+
- lib/adminable/presenters/entries.rb
|
393
|
+
- lib/adminable/presenters/entry.rb
|
394
394
|
- lib/adminable/resource.rb
|
395
395
|
- lib/adminable/version.rb
|
396
396
|
- lib/generators/adminable/install/templates/application_controller.rb
|
397
397
|
- lib/generators/adminable/install_generator.rb
|
398
|
+
- lib/generators/adminable/partial_generator.rb
|
398
399
|
- lib/generators/adminable/resource/templates/resource_controller.rb.erb
|
399
400
|
- lib/generators/adminable/resource_generator.rb
|
400
401
|
homepage: https://github.com/droptheplot/adminable
|
@@ -417,7 +418,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
417
418
|
version: '0'
|
418
419
|
requirements: []
|
419
420
|
rubyforge_project:
|
420
|
-
rubygems_version: 2.
|
421
|
+
rubygems_version: 2.5.1
|
421
422
|
signing_key:
|
422
423
|
specification_version: 4
|
423
424
|
summary: Simple admin interface for Ruby on Rails applications.
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Adminable
|
2
|
-
class EntriesPresenter < BasePresenter
|
3
|
-
ENTRIES_LIMIT = 5
|
4
|
-
|
5
|
-
include Enumerable
|
6
|
-
extend Forwardable
|
7
|
-
|
8
|
-
def_delegators :@collection, :each, :first, :last, :empty?
|
9
|
-
def_delegators(
|
10
|
-
*%i(
|
11
|
-
@relation
|
12
|
-
current_page
|
13
|
-
total_pages
|
14
|
-
limit_value
|
15
|
-
entry_name
|
16
|
-
total_count
|
17
|
-
offset_value
|
18
|
-
last_page?
|
19
|
-
)
|
20
|
-
)
|
21
|
-
|
22
|
-
def initialize(relation)
|
23
|
-
@relation = relation
|
24
|
-
@collection = relation.all.map do |entry|
|
25
|
-
Adminable::EntryPresenter.new(entry)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_s
|
30
|
-
string = collection.first(ENTRIES_LIMIT).map do |entry|
|
31
|
-
view.link_to(entry.to_name, edit_polymorphic_path(entry))
|
32
|
-
end
|
33
|
-
|
34
|
-
string << and_more_tag if collection_size_residue > 0
|
35
|
-
|
36
|
-
string.join(', ').html_safe
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
attr_accessor :relation, :collection
|
42
|
-
|
43
|
-
def collection_size_residue
|
44
|
-
@collection_residue ||= collection.size - ENTRIES_LIMIT
|
45
|
-
end
|
46
|
-
|
47
|
-
def and_more_tag
|
48
|
-
view.content_tag(
|
49
|
-
:span,
|
50
|
-
I18n.t('adminable.ui.and_more', size: collection_size_residue),
|
51
|
-
class: 'text-muted'
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module Adminable
|
2
|
-
class EntryPresenter < BasePresenter
|
3
|
-
def initialize(entry)
|
4
|
-
@entry = entry
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_name
|
8
|
-
%i(name title email login id).each do |method_name|
|
9
|
-
begin
|
10
|
-
return entry.public_send(method_name)
|
11
|
-
rescue NoMethodError
|
12
|
-
next
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def link_to_self
|
18
|
-
view.link_to(
|
19
|
-
to_name,
|
20
|
-
edit_polymorphic_path(entry)
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
def link_to_delete
|
25
|
-
view.link_to(
|
26
|
-
I18n.t('adminable.buttons.delete'),
|
27
|
-
polymorphic_path(@entry),
|
28
|
-
class: 'btn btn-danger-outline pull-xs-right',
|
29
|
-
method: :delete,
|
30
|
-
data: {
|
31
|
-
confirm: I18n.t('adminable.ui.confirm')
|
32
|
-
}
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
def link_to_edit_small
|
37
|
-
view.link_to(
|
38
|
-
I18n.t('adminable.buttons.edit'),
|
39
|
-
edit_polymorphic_path(entry),
|
40
|
-
class: 'label label-primary'
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
def link_to_delete_small
|
45
|
-
view.link_to(
|
46
|
-
I18n.t('adminable.buttons.delete'),
|
47
|
-
polymorphic_path(entry),
|
48
|
-
class: 'label label-danger',
|
49
|
-
method: :delete,
|
50
|
-
data: {
|
51
|
-
confirm: I18n.t('adminable.ui.confirm')
|
52
|
-
}
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
def method_missing(method_name, *args, &block)
|
57
|
-
entry.public_send(method_name, *args) { block if block_given? }
|
58
|
-
end
|
59
|
-
|
60
|
-
def respond_to_missing?(method_name, *)
|
61
|
-
entry.respond_to?(method_name)
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
attr_accessor :entry
|
67
|
-
end
|
68
|
-
end
|