ez-resources 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/cells/ez/resources/collection/table.slim +1 -1
- data/app/cells/ez/resources/collection_cell.rb +15 -1
- data/app/cells/ez/resources/search/show.slim +1 -1
- data/app/cells/ez/resources/search_cell.rb +1 -1
- data/lib/ez/resources/manager/config.rb +6 -5
- data/lib/ez/resources/manager/field.rb +2 -0
- data/lib/ez/resources/manager.rb +10 -2
- data/lib/ez/resources/version.rb +1 -1
- metadata +16 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 386052e063ee3b18f98da26da65840f8bdbb023ec2675b7478cbd037dcc779c8
|
4
|
+
data.tar.gz: 7e70f363241f152bff569238393c10cd9cb9038d71f7e368466fb1e3b61a04ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00d8697327f8493a2ae24dfba5458bdd4f4c2e196fb585aa782a255e69f855e71b48b46f3b56c33bd82cad27f43efe1b2829db5925ea0c9e86a0b9dc61875aec
|
7
|
+
data.tar.gz: '059c05e2a65dde2fce7a68a4af0c698e21e674240edc93cc0cccf3c391ae8f20e01fb065dd3bcb19da50b6b04b11684563eba0e9581a009586cd52d33d6d41cf'
|
data/README.md
CHANGED
@@ -43,7 +43,7 @@ class UsersController < ApplicationController
|
|
43
43
|
config.collection_columns do
|
44
44
|
column :email
|
45
45
|
column :active, type: :boolean
|
46
|
-
column :name, type: :link, presenter: -> (user) { user.name.humanize }
|
46
|
+
column :name, type: :link, presenter: -> (user) { user.name.humanize }, sortable: true
|
47
47
|
column :age
|
48
48
|
column :avatar, type: :image, getter: ->(user) { "/avatars/#{user.id}.jpg" }, class: "t-image-tag"
|
49
49
|
column :custom, type: :custom, builder: ->(user) { "custom #{user.email}" }
|
@@ -17,7 +17,7 @@
|
|
17
17
|
thead class=(css_for 'collection-table-thead')
|
18
18
|
tr class=(css_for 'collection-table-thead-tr')
|
19
19
|
- collection_columns.each do |column|
|
20
|
-
th class=(css_for 'collection-table-thead-th') id=("ez-t-#{column.name}") = column
|
20
|
+
th class=(css_for 'collection-table-thead-th') id=("ez-t-#{column.name}") = column_title(column)
|
21
21
|
th class=(css_for 'collection-table-thead-th') colspan="2" style="width: 1%"
|
22
22
|
tbody class=(css_for 'collection-table-tbody')
|
23
23
|
- collection.each do |record|
|
@@ -4,6 +4,7 @@ module Ez
|
|
4
4
|
module Resources
|
5
5
|
class CollectionCell < ApplicationCell
|
6
6
|
include Pagy::Frontend
|
7
|
+
include Ransack::Helpers::FormHelper
|
7
8
|
|
8
9
|
delegate :resources_name, :collection_columns, :paginator, to: :model
|
9
10
|
|
@@ -81,7 +82,12 @@ module Ez
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def remove_link(record)
|
84
|
-
|
85
|
+
return unless model.actions.include?(:destroy)
|
86
|
+
return unless Manager::Hooks.can?(:can_destroy?, model, record)
|
87
|
+
|
88
|
+
link_to t('actions.remove'), model.path_for(action: :destroy, id: record.id),
|
89
|
+
method: :delete,
|
90
|
+
class: css_for('collection-table-td-action-item')
|
85
91
|
end
|
86
92
|
|
87
93
|
def pagination
|
@@ -103,6 +109,10 @@ module Ez
|
|
103
109
|
end
|
104
110
|
end
|
105
111
|
|
112
|
+
def column_title(column)
|
113
|
+
column.sortable ? sort_link(search, column.name, column.title) : column.title
|
114
|
+
end
|
115
|
+
|
106
116
|
private
|
107
117
|
|
108
118
|
def maybe_use_custom_boolean_presenter(bool)
|
@@ -110,6 +120,10 @@ module Ez
|
|
110
120
|
|
111
121
|
instance_exec bool, &Ez::Resources.config.ui_custom_boolean_presenter
|
112
122
|
end
|
123
|
+
|
124
|
+
def search
|
125
|
+
@search ||= model.model.ransack(model.params[:q])
|
126
|
+
end
|
113
127
|
end
|
114
128
|
end
|
115
129
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
- model.collection_columns.each do |field|
|
8
8
|
- if field.searchable && SEARCHABLE_FIELDS.include?(field.type)
|
9
9
|
= div_for 'collection-search-panel-field'
|
10
|
-
= f.input
|
10
|
+
= f.input field_input_name(field),
|
11
11
|
label: field_label(field),
|
12
12
|
required: false,
|
13
13
|
as: cast_field_type(field.type),
|
@@ -18,11 +18,12 @@ module Ez
|
|
18
18
|
|
19
19
|
def data
|
20
20
|
@data ||= case controller.action_name
|
21
|
-
when 'index'
|
22
|
-
when 'new'
|
23
|
-
when 'show'
|
24
|
-
when 'edit'
|
25
|
-
when 'update'
|
21
|
+
when 'index' then collection
|
22
|
+
when 'new' then new_resource
|
23
|
+
when 'show' then resource
|
24
|
+
when 'edit' then resource
|
25
|
+
when 'update' then resource
|
26
|
+
when 'destroy' then resource
|
26
27
|
else
|
27
28
|
raise ConfigurationError, "Invalid action #{controller.action_name}"
|
28
29
|
end
|
@@ -18,6 +18,7 @@ module Ez
|
|
18
18
|
:presenter,
|
19
19
|
:builder,
|
20
20
|
:searchable,
|
21
|
+
:sortable,
|
21
22
|
:search_suffix,
|
22
23
|
:options
|
23
24
|
|
@@ -35,6 +36,7 @@ module Ez
|
|
35
36
|
@getter = options.delete(:getter)
|
36
37
|
@presenter = options.delete(:presenter)
|
37
38
|
@searchable = options.delete(:searchable) != false
|
39
|
+
@sortable = options.delete(:sortable) || false
|
38
40
|
@search_suffix = options.delete(:search_suffix) || :cont
|
39
41
|
@options = options # use for all other custom options
|
40
42
|
end
|
data/lib/ez/resources/manager.rb
CHANGED
@@ -89,8 +89,16 @@ module Ez
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
92
|
+
def destroy
|
93
|
+
Manager::Hooks.can?(:can_destroy?, ez_resource_config, ez_resource_config.data)
|
94
|
+
ez_resource_config.data.delete
|
95
|
+
|
96
|
+
flash[:notice] = t('messages.removed',
|
97
|
+
resource_name: ez_resource_config.resource_name,
|
98
|
+
scope: Ez::Resources.config.i18n_scope)
|
99
|
+
|
100
|
+
redirect_to ez_resource_config.path_for(action: :index)
|
101
|
+
end
|
94
102
|
|
95
103
|
private
|
96
104
|
|
data/lib/ez/resources/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ez-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volodya Sveredyuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cells-rails
|
@@ -73,9 +73,6 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '5.2'
|
76
|
-
- - "<="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '7.0'
|
79
76
|
type: :runtime
|
80
77
|
prerelease: false
|
81
78
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -83,9 +80,6 @@ dependencies:
|
|
83
80
|
- - ">="
|
84
81
|
- !ruby/object:Gem::Version
|
85
82
|
version: '5.2'
|
86
|
-
- - "<="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '7.0'
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: ransack
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +192,20 @@ dependencies:
|
|
198
192
|
- - ">="
|
199
193
|
- !ruby/object:Gem::Version
|
200
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: orderly
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
201
209
|
- !ruby/object:Gem::Dependency
|
202
210
|
name: pry-rails
|
203
211
|
requirement: !ruby/object:Gem::Requirement
|