admin_it 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/README.md +6 -0
- data/lib/admin_it/context/collection_context.rb +5 -22
- data/lib/admin_it/context/context.rb +13 -34
- data/lib/admin_it/context/show_context.rb +8 -7
- data/lib/admin_it/context/single_context.rb +35 -33
- data/lib/admin_it/context/table_context.rb +18 -11
- data/lib/admin_it/context/tiles_context.rb +14 -14
- data/lib/admin_it/data/active_record.rb +0 -2
- data/lib/admin_it/field/field.rb +95 -23
- data/lib/admin_it/filters/field_filter.rb +4 -0
- data/lib/admin_it/filters/filter.rb +37 -14
- data/lib/admin_it/helpers/table.rb +13 -17
- data/lib/admin_it/resource.rb +58 -115
- data/lib/admin_it/shared.rb +64 -0
- data/lib/admin_it/version.rb +1 -1
- data/lib/admin_it.rb +7 -5
- data/lib/extend_it/array_of.rb +3 -3
- data/lib/extend_it/asserts.rb +5 -3
- data/lib/extend_it/{class.rb → base.rb} +29 -10
- data/lib/extend_it/callbacks.rb +7 -7
- data/lib/extend_it/config.rb +30 -0
- data/lib/extend_it/dsl.rb +223 -64
- data/lib/extend_it/ensures.rb +193 -0
- data/lib/extend_it.rb +1 -1
- data/spec/extend_it/config_spec.rb +52 -0
- data/spec/extend_it/dsl_spec.rb +149 -0
- data/spec/extend_it/ensures_spec.rb +39 -0
- data/spec/lib/context/collection_context_spec.rb +4 -2
- data/spec/lib/context/context_spec.rb +3 -1
- data/spec/lib/context/single_context_spec.rb +3 -2
- data/spec/lib/data/object_spec.rb +2 -2
- data/spec/lib/field_spec.rb +1 -56
- data/spec/lib/resource_spec.rb +1 -13
- data/spec/spec_helper.rb +7 -0
- data/spec/support/example_groups/context_example_group.rb +3 -3
- metadata +14 -11
- data/lib/admin_it/renderable.rb +0 -18
- data/lib/extend_it/refines.rb +0 -6
- data/lib/extend_it/symbolize.rb +0 -39
- data/spec/lib/definitions_spec.rb +0 -171
- data/spec/lib/utils_spec.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3c78b05180f3886708f8ebb99413ae49d655d1d
|
4
|
+
data.tar.gz: 777702fc5bc52596130f80447c686859460d442f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d1eca80d0a17486ef98a48c0d74bd5b146c37b04b4ffa98849231077bad3f73f0a2bc5368da5ff58b39427e82811ee8604a01494258084ac228938a37499c13
|
7
|
+
data.tar.gz: 3b51e836dc3cd9742b06e33a479f48e2f4d4a8af7e525eda044361ce838e797b86e82b37fd5982327e3d845efe96793e049d6fea792cd7156acb352720056122
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/README.md
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'csv'
|
3
|
-
require File.join %w(extend_it symbolize)
|
4
|
-
|
5
|
-
using ExtendIt::Symbolize
|
6
3
|
|
7
4
|
module AdminIt
|
8
5
|
class CollectionContext < Context
|
9
6
|
extend FiltersHolder
|
10
7
|
|
11
|
-
@entities_getter = nil
|
12
|
-
|
13
8
|
class << self
|
14
|
-
|
9
|
+
attr_reader :entities_getter, :default_sorting
|
10
|
+
end
|
11
|
+
|
12
|
+
dsl do
|
13
|
+
dsl_block :entities, variable: :entities_getter
|
15
14
|
dsl_accessor :default_sorting
|
16
|
-
dsl_use_hash :filters
|
17
15
|
end
|
18
16
|
|
19
17
|
def self.before_configure
|
@@ -27,21 +25,6 @@ module AdminIt
|
|
27
25
|
]
|
28
26
|
end
|
29
27
|
|
30
|
-
def self.filter(name, filter_class: nil, &block)
|
31
|
-
assert_symbol(:name)
|
32
|
-
if @filters.key?(name)
|
33
|
-
filter = @filters[name] = Class.new(@filters[name]) if block_given?
|
34
|
-
else
|
35
|
-
filter_class = Filter if filter_class.nil? || !filter_class <= Filter
|
36
|
-
filter = @filters[name] = filter_class.create(name, self)
|
37
|
-
end
|
38
|
-
filter.instance_eval(&block) if block_given?
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.entities_getter
|
42
|
-
@entities
|
43
|
-
end
|
44
|
-
|
45
28
|
def self.collection?
|
46
29
|
true
|
47
30
|
end
|
@@ -1,35 +1,32 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require File.join %w(extend_it dsl)
|
3
|
-
require File.join %w(extend_it
|
4
|
-
require File.join %w(extend_it
|
3
|
+
require File.join %w(extend_it base)
|
4
|
+
require File.join %w(extend_it callbacks)
|
5
5
|
|
6
|
-
using ExtendIt::
|
6
|
+
using ExtendIt::Ensures
|
7
7
|
|
8
8
|
module AdminIt
|
9
9
|
class Context
|
10
|
-
extend ExtendIt::
|
10
|
+
extend ExtendIt::Base
|
11
11
|
extend ExtendIt::Dsl
|
12
|
-
|
13
|
-
extend DataBehavior
|
12
|
+
extend Iconed
|
14
13
|
extend FieldsHolder
|
14
|
+
extend DataBehavior
|
15
|
+
include ExtendIt::Callbacks
|
15
16
|
|
16
17
|
class << self
|
17
|
-
extend ExtendIt::Dsl
|
18
|
-
|
19
18
|
attr_reader :context_name
|
20
19
|
attr_accessor :controller_class
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
value.nil? ? default_icon : value.to_s
|
24
|
-
end
|
25
|
-
dsl_use_hash :fields
|
22
|
+
dsl do
|
26
23
|
dsl_boolean :confirm_destroy
|
27
24
|
end
|
28
25
|
|
29
26
|
inherited_class_reader :resource, :entity_class
|
30
27
|
define_callbacks :initialize, :load, :save
|
31
28
|
|
32
|
-
def self.create(context_name, _resource
|
29
|
+
def self.create(context_name, _resource)
|
33
30
|
fail ArgumentError, 'Wrong resource' unless _resource.is_a?(Resource)
|
34
31
|
base = self
|
35
32
|
Class.new(base) do
|
@@ -45,21 +42,11 @@ module AdminIt
|
|
45
42
|
]
|
46
43
|
|
47
44
|
before_configure if respond_to?(:before_configure)
|
48
|
-
instance_eval(&block) if block_given?
|
49
|
-
after_configure if respond_to?(:after_configure)
|
50
45
|
end
|
51
46
|
end
|
52
47
|
|
53
|
-
def self.
|
54
|
-
|
55
|
-
if @fields.key?(name)
|
56
|
-
field = @fields[name] = Class.new(@fields[name]) if block_given?
|
57
|
-
else
|
58
|
-
field_class = Field if field_class.nil? || !field_class <= Field
|
59
|
-
field = @fields[name] = field_class.create(name, entity_class)
|
60
|
-
end
|
61
|
-
field.instance_eval(&block) if block_given?
|
62
|
-
end
|
48
|
+
def self.confirm_destroy?
|
49
|
+
@confirm_destroy.nil? ? true : @confirm_destroy == true
|
63
50
|
end
|
64
51
|
|
65
52
|
def self.collection?
|
@@ -84,15 +71,7 @@ module AdminIt
|
|
84
71
|
url
|
85
72
|
end
|
86
73
|
|
87
|
-
|
88
|
-
protected
|
89
|
-
|
90
|
-
def default_icon
|
91
|
-
''
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class_attr_reader :collection?, :single?, :entity_class, :resource, :icon,
|
74
|
+
class_attr_reader :collection?, :single?, :entity_class, :resource,
|
96
75
|
:entity_path?, :confirm_destroy?
|
97
76
|
attr_reader :top_menu, :toolbar, :parent, :template, :controller
|
98
77
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module AdminIt
|
2
2
|
class ShowContext < SingleContext
|
3
|
+
extend Renderable
|
3
4
|
include Identifiable
|
4
5
|
|
5
6
|
CONFIRMS = %i(destroy update)
|
6
7
|
|
7
8
|
class << self
|
8
|
-
include Renderable
|
9
|
-
|
10
9
|
protected
|
11
10
|
|
12
11
|
def default_icon
|
@@ -14,15 +13,17 @@ module AdminIt
|
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
16
|
+
dsl do
|
17
|
+
dsl_block :read
|
18
|
+
end
|
19
|
+
|
17
20
|
def self.entity_path?
|
18
21
|
true
|
19
22
|
end
|
20
23
|
|
21
|
-
def self.read(entity
|
22
|
-
|
23
|
-
@
|
24
|
-
elsif !@reader.nil?
|
25
|
-
@reader.call(entity)
|
24
|
+
def self.read(entity)
|
25
|
+
unless @read.nil?
|
26
|
+
@read.call(entity)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
@@ -1,18 +1,29 @@
|
|
1
|
-
require File.join %w(extend_it dsl)
|
2
|
-
require File.join %w(extend_it symbolize)
|
3
|
-
|
4
|
-
using ExtendIt::Symbolize
|
5
|
-
|
6
1
|
module AdminIt
|
7
2
|
class Section
|
8
|
-
extend ExtendIt::
|
3
|
+
extend ExtendIt::Base
|
4
|
+
include ExtendIt::Dsl
|
9
5
|
include Renderable
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
|
7
|
+
attr_reader :name, :display_name
|
8
|
+
|
9
|
+
dsl do
|
10
|
+
dsl_accessor :name, :display_name
|
11
|
+
dsl_boolean :visible
|
12
|
+
end
|
13
|
+
|
14
|
+
def visible?
|
15
|
+
@visible.nil? ? @visible = true : @visible == true
|
16
|
+
end
|
17
|
+
|
13
18
|
def fields(*names)
|
14
19
|
names.empty? ? @fields ||= [] : @fields = names
|
15
20
|
end
|
21
|
+
|
22
|
+
def initialize(name, *fields, display_name: nil)
|
23
|
+
@name = name
|
24
|
+
@display_name = display_name || name
|
25
|
+
@fields = fields
|
26
|
+
end
|
16
27
|
end
|
17
28
|
|
18
29
|
module Identifiable
|
@@ -33,37 +44,28 @@ module AdminIt
|
|
33
44
|
end
|
34
45
|
|
35
46
|
class SingleContext < Context
|
36
|
-
|
47
|
+
dsl do
|
37
48
|
dsl_block :entity_getter, :entity_saver, :entity_destroyer
|
49
|
+
|
50
|
+
dsl_hash_of_objects :sections, single: :section do |name, **opts|
|
51
|
+
if @sections.empty?
|
52
|
+
# TODO: require this and other files after I18n config in engine.rb
|
53
|
+
#general.display_name(I18n.t('admin_it.collection.no_data'))
|
54
|
+
general = Section.new(
|
55
|
+
:general,
|
56
|
+
*fields.map(&:field_name),
|
57
|
+
display_name: 'Основные свойства'
|
58
|
+
)
|
59
|
+
@sections[:general] = general
|
60
|
+
end
|
61
|
+
Section.new(name)
|
62
|
+
end
|
38
63
|
end
|
39
64
|
|
40
65
|
def self.sections
|
41
66
|
(@sections ||= {}).values
|
42
67
|
end
|
43
68
|
|
44
|
-
def self.section(*names, &block)
|
45
|
-
@sections ||= {}
|
46
|
-
names.ensure_symbols.each do |name|
|
47
|
-
if @sections.key?(name)
|
48
|
-
section = @sections[name]
|
49
|
-
else
|
50
|
-
if @sections.empty?
|
51
|
-
general = Section.new
|
52
|
-
general.name(:general)
|
53
|
-
# TODO: require this and other files after I18n config in engine.rb
|
54
|
-
#general.display_name(I18n.t('admin_it.collection.no_data'))
|
55
|
-
general.display_name('Основные свойства')
|
56
|
-
general.fields(*fields.map(&:field_name))
|
57
|
-
@sections[:general] = general
|
58
|
-
end
|
59
|
-
section = Section.new
|
60
|
-
section.name(name)
|
61
|
-
@sections[name] = section
|
62
|
-
end
|
63
|
-
section.instance_eval(&block) if block_given?
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
69
|
def self.single?
|
68
70
|
true
|
69
71
|
end
|
@@ -1,16 +1,12 @@
|
|
1
|
-
require File.join %w(extend_it dsl)
|
2
|
-
|
3
1
|
module AdminIt
|
4
2
|
class TableContext < CollectionContext
|
5
|
-
|
6
|
-
dsl_accessor :page_size, default: 10
|
7
|
-
value.is_a?(Fixnum) && value > 0 ? value : 10
|
8
|
-
end
|
9
|
-
|
3
|
+
dsl do
|
4
|
+
dsl_accessor :page_size, default: 10
|
10
5
|
dsl_boolean :actions
|
11
|
-
|
12
6
|
dsl_block :row
|
7
|
+
end
|
13
8
|
|
9
|
+
class << self
|
14
10
|
protected
|
15
11
|
|
16
12
|
def default_icon
|
@@ -18,12 +14,23 @@ module AdminIt
|
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
17
|
+
def self.actions?
|
18
|
+
@actions.nil? ? true : @actions == true
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.page_size
|
22
|
+
@page_size ||= 10
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.page_size=(value)
|
26
|
+
@page_size = value.is_a?(Fixnum) && value > 0 ? value : 10
|
27
|
+
end
|
28
|
+
|
21
29
|
def self.path
|
22
|
-
AdminIt::Engine.routes
|
23
|
-
.url_helpers.send("table_#{resource.plural}_path")
|
30
|
+
AdminIt::Engine.routes.url_helpers.send("table_#{resource.plural}_path")
|
24
31
|
end
|
25
32
|
|
26
|
-
class_attr_reader :page_size, :actions
|
33
|
+
class_attr_reader :page_size, :actions?, :row
|
27
34
|
|
28
35
|
after_load do |store: {}, params: {}|
|
29
36
|
self.page = params[:page] || store[:page]
|
@@ -1,24 +1,15 @@
|
|
1
|
-
require File.join %w(extend_it dsl)
|
2
|
-
|
3
1
|
module AdminIt
|
4
2
|
class TilesContext < CollectionContext
|
5
|
-
|
3
|
+
dsl do
|
6
4
|
dsl_accessor :header do |value|
|
7
|
-
|
8
|
-
|
9
|
-
else
|
10
|
-
field = fields.find { |f| f.field_name == value }
|
11
|
-
field.nil? ? header(nil) : field.field_name
|
12
|
-
end
|
5
|
+
field = fields.find { |f| f.field_name == value }
|
6
|
+
field.nil? ? header : field.field_name
|
13
7
|
end
|
14
8
|
end
|
15
9
|
|
16
|
-
def self.path
|
17
|
-
AdminIt::Engine.routes
|
18
|
-
.url_helpers.send("tiles_#{resource.plural}_path")
|
19
|
-
end
|
20
|
-
|
21
10
|
class << self
|
11
|
+
attr_reader :header
|
12
|
+
|
22
13
|
protected
|
23
14
|
|
24
15
|
def default_icon
|
@@ -26,6 +17,15 @@ module AdminIt
|
|
26
17
|
end
|
27
18
|
end
|
28
19
|
|
20
|
+
def self.header
|
21
|
+
fields.empty? ? nil : fields.first.name
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.path
|
25
|
+
AdminIt::Engine.routes
|
26
|
+
.url_helpers.send("tiles_#{resource.plural}_path")
|
27
|
+
end
|
28
|
+
|
29
29
|
class_attr_reader :header
|
30
30
|
end
|
31
31
|
end
|
data/lib/admin_it/field/field.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join %w(extend_it
|
1
|
+
require File.join %w(extend_it base)
|
2
2
|
require File.join %w(extend_it dsl)
|
3
3
|
require File.join %w(extend_it callbacks)
|
4
4
|
|
@@ -9,42 +9,60 @@ module AdminIt
|
|
9
9
|
# @author [alexiss]
|
10
10
|
#
|
11
11
|
class Field
|
12
|
-
extend ExtendIt::
|
12
|
+
extend ExtendIt::Base
|
13
13
|
extend DataBehavior
|
14
|
+
extend ExtendIt::Dsl
|
15
|
+
extend DisplayableName
|
14
16
|
include ExtendIt::Callbacks
|
15
17
|
|
16
18
|
TYPES = %i(unknown integer float string date relation enum)
|
17
19
|
|
18
|
-
define_callbacks :initialize
|
20
|
+
define_callbacks :initialize
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
dsl do
|
23
|
+
dsl_accessor :type, default: TYPES[0]
|
22
24
|
|
23
|
-
|
25
|
+
dsl_accessor :placeholder
|
24
26
|
|
25
|
-
|
26
|
-
value.nil? ? default_display_name : value.to_s
|
27
|
-
end
|
27
|
+
dsl_boolean :readable, :writable, :visible, :sortable
|
28
28
|
|
29
|
-
|
30
|
-
TYPES.include?(value) ? value : TYPES[0]
|
31
|
-
end
|
29
|
+
dsl_block :read, :write, :render, :display
|
32
30
|
|
33
|
-
|
34
|
-
|
31
|
+
def hide
|
32
|
+
@visible = false
|
35
33
|
end
|
36
34
|
|
37
|
-
|
35
|
+
def show
|
36
|
+
@visible = true
|
37
|
+
end
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
+
class << self
|
41
|
+
attr_reader :type, :read, :write, :render, :display
|
40
42
|
|
41
43
|
protected
|
42
44
|
|
43
45
|
def default_display_name
|
44
|
-
|
46
|
+
field_name
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
50
|
+
def self.readable?
|
51
|
+
@readable.nil? ? @readable = true : @readable == true
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.writable?
|
55
|
+
@writable.nil? ? @writable = true : @writable == true
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.visible?
|
59
|
+
@visible.nil? ? @visible = true : @visible == true
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.sortable?
|
63
|
+
@sortable.nil? ? @sortable = true : @sortable == true
|
64
|
+
end
|
65
|
+
|
48
66
|
inherited_class_reader :field_name, :entity_class
|
49
67
|
|
50
68
|
def self.create(name, _entity_class,
|
@@ -56,18 +74,24 @@ module AdminIt
|
|
56
74
|
)
|
57
75
|
base = self
|
58
76
|
Class.new(base) do
|
59
|
-
#run_callbacks :configure do
|
60
77
|
@field_name, @entity_class = name, _entity_class
|
61
78
|
import_data_module(base)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
79
|
+
@readable = readable == true
|
80
|
+
@writable = writable == true
|
81
|
+
@visible = visible == true
|
82
|
+
@sortable = sortable == true
|
66
83
|
self.type = type
|
67
|
-
#end
|
68
84
|
end
|
69
85
|
end
|
70
86
|
|
87
|
+
def self.type=(value)
|
88
|
+
TYPES.include?(value) ? value : TYPES[0]
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.placeholder
|
92
|
+
@placeholder ||= display_name
|
93
|
+
end
|
94
|
+
|
71
95
|
def self.hide
|
72
96
|
@visible = false
|
73
97
|
end
|
@@ -171,4 +195,52 @@ module AdminIt
|
|
171
195
|
"Attempt to write to field #{name} with unimplemented writer"
|
172
196
|
end
|
173
197
|
end
|
198
|
+
|
199
|
+
module FieldsHolder
|
200
|
+
extend ExtendIt::DslModule
|
201
|
+
|
202
|
+
dsl do
|
203
|
+
dsl_hash_of_objects :fields, single: :field do |name, **opts|
|
204
|
+
field_class = opts[:class] || opts[:field_class] || Field
|
205
|
+
unless field_class.is_a?(Class) && field_class <= Field
|
206
|
+
fail(
|
207
|
+
ArgumentError,
|
208
|
+
'field class should be AdminIt::Field descendant'
|
209
|
+
)
|
210
|
+
end
|
211
|
+
field_class.create(name, entity_class)
|
212
|
+
end
|
213
|
+
|
214
|
+
def hide_fields(*names)
|
215
|
+
hash = dsl_get(:fields, {})
|
216
|
+
names.ensure_symbols.each do |name|
|
217
|
+
hash[name].hide if hash.key?(name)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def show_fields(*names)
|
222
|
+
hash = dsl_get(:fields, {})
|
223
|
+
names.ensure_symbols.each do |name|
|
224
|
+
hash[name].show if hash.key?(name)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def fields(scope: :visible)
|
230
|
+
case scope
|
231
|
+
when nil, :all then @fields.values
|
232
|
+
when :visible then @fields.values.select { |f| f.visible? }
|
233
|
+
when :hidden then @fields.values.select { |f| !f.visible? }
|
234
|
+
when :readable then @fields.values.select { |f| f.readable? }
|
235
|
+
when :writable then @fields.values.select { |f| f.writable? }
|
236
|
+
when :sortable then @fields.values.select { |f| f.sortable? }
|
237
|
+
when Field::TYPES then @fields.values.select { |f| f.type == scope }
|
238
|
+
else @fields.values
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def field(name)
|
243
|
+
@fields[name.ensure_symbol]
|
244
|
+
end
|
245
|
+
end
|
174
246
|
end
|
@@ -1,19 +1,16 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'json'
|
3
|
-
require File.join %w(extend_it
|
3
|
+
require File.join %w(extend_it base)
|
4
4
|
require File.join %w(extend_it dsl)
|
5
5
|
require File.join %w(extend_it callbacks)
|
6
|
-
require File.join %w(extend_it asserts)
|
7
|
-
require File.join %w(extend_it symbolize)
|
8
|
-
|
9
|
-
using ExtendIt::Symbolize
|
10
6
|
|
11
7
|
module AdminIt
|
12
8
|
class Filter
|
13
|
-
extend ExtendIt::
|
9
|
+
extend ExtendIt::Base
|
10
|
+
extend ExtendIt::Dsl
|
14
11
|
extend DataBehavior
|
12
|
+
extend DisplayableName
|
15
13
|
include ExtendIt::Callbacks
|
16
|
-
extend ExtendIt::Asserts
|
17
14
|
|
18
15
|
REGEXP = /
|
19
16
|
(?<=\A|[,;|])\s*
|
@@ -41,18 +38,16 @@ module AdminIt
|
|
41
38
|
define_callbacks :initialize, :save, :load
|
42
39
|
|
43
40
|
class << self
|
44
|
-
extend ExtendIt::Dsl
|
45
|
-
|
46
41
|
attr_reader :filter_name, :resource
|
47
42
|
|
48
|
-
dsl_accessor :display_name do |value = nil|
|
49
|
-
value.nil? ? default_display_name : value.to_s
|
50
|
-
end
|
51
|
-
|
52
43
|
protected
|
53
44
|
|
54
45
|
def create_class(name, _resource)
|
55
|
-
|
46
|
+
name = name.ensure_symbol || fail(
|
47
|
+
ArgumentError,
|
48
|
+
'`name` argument for `Filter::create_class` should be a Symbol' \
|
49
|
+
' or a String'
|
50
|
+
)
|
56
51
|
base = self
|
57
52
|
Class.new(base) do
|
58
53
|
@filter_name, @resource = name, _resource
|
@@ -211,4 +206,32 @@ module AdminIt
|
|
211
206
|
end
|
212
207
|
end
|
213
208
|
end
|
209
|
+
|
210
|
+
module FiltersHolder
|
211
|
+
extend ExtendIt::DslModule
|
212
|
+
|
213
|
+
dsl do
|
214
|
+
dsl_hash_of_objects :filters, single: :filter do |name, **opts|
|
215
|
+
filter_class = opts[:class] || opts[:filter_class] || Filter
|
216
|
+
unless filter_class.is_a?(Class) && filter_class <= Filter
|
217
|
+
fail(
|
218
|
+
ArgumentError,
|
219
|
+
'filter class should be AdminIt::Filter descendant'
|
220
|
+
)
|
221
|
+
end
|
222
|
+
filter_class.create(name, entity_class)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def filters(scope: :all)
|
227
|
+
case scope
|
228
|
+
when nil, :all then @filters.values
|
229
|
+
else @filters.values
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def filter(name)
|
234
|
+
@filters[name.ensure_symbol]
|
235
|
+
end
|
236
|
+
end
|
214
237
|
end
|
@@ -34,28 +34,24 @@ module AdminIt
|
|
34
34
|
if context.confirm_destroy?
|
35
35
|
confirm = single.find { |c| c.context_name == :confirm } ||
|
36
36
|
single.first { |c| c <= ShowContext }
|
37
|
-
|
38
|
-
|
37
|
+
unless confirm.nil?
|
38
|
+
buttons <<
|
39
|
+
'<a class="btn btn-xs btn-danger" ' +
|
40
|
+
%Q{data-toggle="modal" data-target="#confirm_modal" } +
|
41
|
+
%Q{href="#{confirm.path(entity)}} +
|
42
|
+
'?layout=dialog&confirm=destroy">' +
|
43
|
+
'<i class="fa fa-trash-o"></i></a>'
|
44
|
+
end
|
45
|
+
else
|
46
|
+
show = single.first { |c| c <= ShowContext }
|
47
|
+
unless show.nil?
|
48
|
+
buttons << @template.link_to(
|
39
49
|
html_safe('<i class="fa fa-trash-o"></i>'),
|
40
50
|
show.path(entity),
|
41
51
|
method: :delete,
|
42
|
-
confirm: I18n.t('admin_it.confirm.destroy.text'),
|
43
52
|
class: 'btn btn-xs btn-danger'
|
44
53
|
)
|
45
|
-
else
|
46
|
-
'<a class="btn btn-xs btn-danger" ' +
|
47
|
-
%Q{data-toggle="modal" data-target="#confirm_modal" } +
|
48
|
-
%Q{href="#{confirm.path(entity)}} +
|
49
|
-
'?layout=dialog&confirm=destroy">' +
|
50
|
-
'<i class="fa fa-trash-o"></i></a>'
|
51
54
|
end
|
52
|
-
else
|
53
|
-
buttons << @template.link_to(
|
54
|
-
html_safe('<i class="fa fa-trash-o"></i>'),
|
55
|
-
show.path(entity),
|
56
|
-
method: :delete,
|
57
|
-
class: 'btn btn-xs btn-danger'
|
58
|
-
)
|
59
55
|
end
|
60
56
|
end
|
61
57
|
|
@@ -77,7 +73,7 @@ module AdminIt
|
|
77
73
|
child :actions, ActionsCell
|
78
74
|
|
79
75
|
before_capture do
|
80
|
-
block = parent.context.
|
76
|
+
block = parent.context.row
|
81
77
|
unless block.nil?
|
82
78
|
instance_exec(parent.context.entity, &block)
|
83
79
|
end
|