ez-resources 0.1.0 → 0.1.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 +1 -1
- data/app/cells/ez/resources/collection/table.slim +1 -1
- data/app/cells/ez/resources/collection_cell.rb +17 -3
- 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 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b3e10c0d602e396efdb1f247852079a73a3ff7400f4b8f6e29be00ef09d00a0
|
4
|
+
data.tar.gz: d2a3b95d310489e308e114fcb7cf254839e98673fdb72431c14eda556f10bca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5352b31aeeb6e3e427dd18a8968c96d8af522c55f5a67240f17131fae7090c25c84fb3b26d5dd2ba0cde8805a1f3f0605cf13671fa196857cadd97279b6709f
|
7
|
+
data.tar.gz: 1bebc28528126229a4b491a56fa766c8695a279a8780a6118f296ae92242a1aab4596716ed6139dfa8298d5d0a5fd225185591f0fa6aa21308717ca32d59223b
|
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
|
|
@@ -46,9 +47,9 @@ module Ez
|
|
46
47
|
|
47
48
|
def record_tr(record, &block)
|
48
49
|
if model.actions.include?(:show) && Manager::Hooks.can?(:can_read?, model, record)
|
49
|
-
content_tag :tr, class: css_for('collection-table-tr'), id: "#{
|
50
|
+
content_tag :tr, class: css_for('collection-table-tr'), id: "#{model.model.name.demodulize.pluralize.downcase}-#{record.id}", data: { link: model.path_for(action: :show, id: record.id).to_s }, &block
|
50
51
|
else
|
51
|
-
content_tag :tr, class: css_for('collection-table-tr'), id: "#{
|
52
|
+
content_tag :tr, class: css_for('collection-table-tr'), id: "#{model.model.name.demodulize.pluralize.downcase}-#{record.id}", &block
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
@@ -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
|
@@ -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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volodya Sveredyuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cells-rails
|
@@ -198,6 +198,20 @@ dependencies:
|
|
198
198
|
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0'
|
201
|
+
- !ruby/object:Gem::Dependency
|
202
|
+
name: orderly
|
203
|
+
requirement: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
type: :development
|
209
|
+
prerelease: false
|
210
|
+
version_requirements: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
201
215
|
- !ruby/object:Gem::Dependency
|
202
216
|
name: pry-rails
|
203
217
|
requirement: !ruby/object:Gem::Requirement
|