madmin 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/madmin/resource_controller.rb +3 -1
- data/app/helpers/madmin/sort_helper.rb +31 -0
- data/app/views/madmin/application/index.html.erb +1 -1
- data/lib/generators/madmin/resource/templates/resource.rb.tt +9 -0
- data/lib/madmin/resource.rb +5 -1
- data/lib/madmin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e868d17abd508729232e7ebeebd4b79a8e69545b853276a700c60e61e5d6348c
|
4
|
+
data.tar.gz: b19043a0a2e7dd0ad6392f995b76812b434e54f73682eb163ca28e1aaeb4ad34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09b7ec920a1c8ae8a1429db77cff71ca45574e379563db5a06648d5cd5434950597b99eed5b836f7834cdc5c71e9d68411f064cc78d363da848efde9a0ef1b1a'
|
7
|
+
data.tar.gz: 51b2b25ddabe18e8777c9eab9e34dd1b8afd74a05aae5671f2f94c85cb404043bcde8423d996033a9dd4fa07ee672ad36240e65e195166586afabc02d756237a
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Madmin
|
2
2
|
class ResourceController < ApplicationController
|
3
|
+
include SortHelper
|
4
|
+
|
3
5
|
before_action :set_record, except: [:index, :new, :create]
|
4
6
|
|
5
7
|
def index
|
@@ -54,7 +56,7 @@ module Madmin
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def scoped_resources
|
57
|
-
resource.model.send(valid_scope)
|
59
|
+
resource.model.send(valid_scope).order(sort_column => sort_direction)
|
58
60
|
end
|
59
61
|
|
60
62
|
def valid_scope
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Madmin
|
2
|
+
module SortHelper
|
3
|
+
def sortable(column, title, options = {})
|
4
|
+
matching_column = (column.to_s == sort_column)
|
5
|
+
|
6
|
+
link_to request.params.merge(sort: column, direction: sort_direction), options do
|
7
|
+
concat title
|
8
|
+
if matching_column
|
9
|
+
concat " "
|
10
|
+
concat tag.i(sort_direction == "asc" ? "▲" : "▼")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def sort_column
|
16
|
+
resource.sortable_columns.include?(params[:sort]) ? params[:sort] : default_sort_column
|
17
|
+
end
|
18
|
+
|
19
|
+
def sort_direction
|
20
|
+
["asc", "desc"].include?(params[:direction]) ? params[:direction] : default_sort_direction
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_sort_column
|
24
|
+
resource.try(:default_sort_column) || "created_at"
|
25
|
+
end
|
26
|
+
|
27
|
+
def default_sort_direction
|
28
|
+
resource.try(:default_sort_direction) || "desc"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -20,7 +20,7 @@
|
|
20
20
|
<% next if attribute[:field].nil? %>
|
21
21
|
<% next unless attribute[:field].visible?(action_name) %>
|
22
22
|
|
23
|
-
<th><%= attribute[:name].to_s.titleize %></th>
|
23
|
+
<th><%= sortable attribute[:name], attribute[:name].to_s.titleize %></th>
|
24
24
|
<% end %>
|
25
25
|
<th>Actions</th>
|
26
26
|
</tr>
|
@@ -13,4 +13,13 @@ class <%= class_name %>Resource < Madmin::Resource
|
|
13
13
|
# def self.display_name(record)
|
14
14
|
# record.name
|
15
15
|
# end
|
16
|
+
|
17
|
+
# Uncomment this to customize the default sort column and direction.
|
18
|
+
# def self.default_sort_column
|
19
|
+
# "created_at"
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def self.default_sort_direction
|
23
|
+
# "desc"
|
24
|
+
# end
|
16
25
|
end
|
data/lib/madmin/resource.rb
CHANGED
@@ -70,7 +70,7 @@ module Madmin
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def permitted_params
|
73
|
-
attributes.
|
73
|
+
attributes.filter_map { |a| a[:field].to_param if a[:field].visible?(:form) }
|
74
74
|
end
|
75
75
|
|
76
76
|
def display_name(record)
|
@@ -81,6 +81,10 @@ module Madmin
|
|
81
81
|
model.respond_to? :friendly
|
82
82
|
end
|
83
83
|
|
84
|
+
def sortable_columns
|
85
|
+
model.column_names
|
86
|
+
end
|
87
|
+
|
84
88
|
private
|
85
89
|
|
86
90
|
def field_for_type(name, type)
|
data/lib/madmin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: madmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- app/controllers/madmin/dashboard_controller.rb
|
64
64
|
- app/controllers/madmin/resource_controller.rb
|
65
65
|
- app/helpers/madmin/application_helper.rb
|
66
|
+
- app/helpers/madmin/sort_helper.rb
|
66
67
|
- app/views/layouts/madmin/application.html.erb
|
67
68
|
- app/views/madmin/application/_form.html.erb
|
68
69
|
- app/views/madmin/application/_javascript.html.erb
|