madmin 2.5.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 651ff84ef6656287c3eb1bbadae16eb38d2820bcc5eb122c10d19f42739a8d92
4
- data.tar.gz: 97176ea8203d5118b19e25a2e1ceffb4252c28ce8d3573f5f5b4937ef0876fef
3
+ metadata.gz: 35abef3e18e33da02efc68140fbbffe237a15b5054f99a6299265b1219181069
4
+ data.tar.gz: 6cd25c564e51d1d663b9b8525caa793d6395e8534f831a02fdf41b36411b6161
5
5
  SHA512:
6
- metadata.gz: f67235e06f0e0822a97bdcb306fc8328aae9e203edd06f1a3f6823bdaa19d9c072a1688f246faaedd73c6b2b5ce547f7f2340761c958f2c75d0b87f08ad79a71
7
- data.tar.gz: 8e36b4f0986ec2946b4a288b43c2c705b9b1eb07ab0a5d64e006b603b05b0e748292110614075b8ad11d6c55885fd554e2631b1320e534b357b96111b06be3bc
6
+ metadata.gz: 62b04e88f49fbbb3c680c482e6c73bfa71710471c858e872f11d8eb5ba6491fb8c12607adadea92f64c8ed3f1b6da10afa616fa3e13114dbe0a2a5365d41c897
7
+ data.tar.gz: 3e11e615a5720928b8997fa684549a2e67cc17e06d689a0856ba9d350d6037ccb63d6f6dd543e353712ce32616f8af09efbe66dfa545a91eae7cef98896cb6fe
data/README.md CHANGED
@@ -58,6 +58,20 @@ end
58
58
 
59
59
  ```
60
60
 
61
+ ### Read-only Resources
62
+
63
+ To expose a resource in the admin without allowing writes, override `readonly?` in the resource:
64
+
65
+ ```ruby
66
+ class AuditLogResource < Madmin::Resource
67
+ def self.readonly?
68
+ true
69
+ end
70
+ end
71
+ ```
72
+
73
+ The new, edit, and delete links are hidden for read-only resources, and any write actions redirect back to the index.
74
+
61
75
  ## Configuring Views
62
76
 
63
77
  The views packaged within the gem are a great starting point, but inevitably people will need to be able to customize those views.
@@ -5,6 +5,10 @@
5
5
  position: relative;
6
6
  min-width: 0;
7
7
  width: 100%;
8
+
9
+ &:not(:has(tbody tr)) th {
10
+ border-bottom: none;
11
+ }
8
12
  }
9
13
 
10
14
  table {
@@ -3,12 +3,13 @@ module Madmin
3
3
  include SortHelper
4
4
 
5
5
  before_action :set_record, except: [:index, :new, :create]
6
+ before_action :enforce_readonly, only: [:new, :create, :edit, :update, :destroy]
6
7
 
7
8
  # Assign current_user for paper_trail gem
8
9
  before_action :set_paper_trail_whodunnit, if: -> { respond_to?(:set_paper_trail_whodunnit, true) }
9
10
 
10
11
  def index
11
- @pagy, @records = pagy(scoped_resources)
12
+ @pagy, @records = paginate_collection(scoped_resources)
12
13
 
13
14
  respond_to do |format|
14
15
  format.html
@@ -68,9 +69,16 @@ module Madmin
68
69
  def scoped_resources
69
70
  resources = resource.model.send(valid_scope)
70
71
  resources = Madmin::Search.new(resources, resource, search_term).run
72
+
73
+ return resources if sort_column.blank?
74
+
71
75
  resources.reorder(sort_column => sort_direction)
72
76
  end
73
77
 
78
+ def paginate_collection(collection)
79
+ pagy(collection)
80
+ end
81
+
74
82
  def valid_scope
75
83
  scope = params.fetch(:scope, "all")
76
84
  resource.scopes.include?(scope.to_sym) ? scope : :all
@@ -102,6 +110,10 @@ module Madmin
102
110
  @search_term ||= params[:q].to_s.strip
103
111
  end
104
112
 
113
+ def enforce_readonly
114
+ redirect_to resource.index_path, alert: t("madmin.flash.readonly", name: resource.friendly_name) if resource.readonly?
115
+ end
116
+
105
117
  ActiveSupport.run_load_hooks(:madmin_resource_controller, self)
106
118
  end
107
119
  end
@@ -22,7 +22,7 @@ module Madmin
22
22
  end
23
23
 
24
24
  def default_sort_column
25
- resource.try(:default_sort_column) || (["created_at", "id", "uuid"] & resource.model.column_names).first
25
+ resource.try(:default_sort_column) || (["created_at", "id", "uuid"] & resource.sortable_columns).first || resource.sortable_columns.first
26
26
  end
27
27
 
28
28
  def default_sort_direction
@@ -19,8 +19,10 @@
19
19
  <%= instance_exec(&action) %>
20
20
  <% end %>
21
21
 
22
- <%= link_to resource.new_path, class: "btn btn-secondary" do %>
23
- <%= t("madmin.actions.new") %> <%= tag.span resource.friendly_name, class: "hidden md:inline-block" %>
22
+ <% unless resource.readonly? %>
23
+ <%= link_to resource.new_path, class: "btn btn-secondary" do %>
24
+ <%= t("madmin.actions.new") %> <%= tag.span resource.friendly_name, class: "hidden md:inline-block" %>
25
+ <% end %>
24
26
  <% end %>
25
27
  </div>
26
28
  </header>
@@ -60,7 +62,7 @@
60
62
 
61
63
  <td class="actions">
62
64
  <%= link_to t("madmin.actions.view"), resource.show_path(record), class: "btn btn-secondary" %>
63
- <%= link_to t("madmin.actions.edit"), resource.edit_path(record), class: "btn btn-secondary" %>
65
+ <%= link_to t("madmin.actions.edit"), resource.edit_path(record), class: "btn btn-secondary" unless resource.readonly? %>
64
66
 
65
67
  <% resource.collection_member_actions.each do |action| %>
66
68
  <%= instance_exec(record, &action) %>
@@ -11,8 +11,10 @@
11
11
  <% resource.member_actions.each do |action| %>
12
12
  <%= instance_exec(@record, &action) %>
13
13
  <% end %>
14
- <%= link_to t("madmin.actions.edit"), resource.edit_path(@record), class: "btn btn-secondary" %>
15
- <%= button_to t("madmin.actions.delete"), resource.show_path(@record), method: :delete, data: { turbo_confirm: t("madmin.confirmations.delete") }, class: "btn btn-danger" %>
14
+ <% unless resource.readonly? %>
15
+ <%= link_to t("madmin.actions.edit"), resource.edit_path(@record), class: "btn btn-secondary" %>
16
+ <%= button_to t("madmin.actions.delete"), resource.show_path(@record), method: :delete, data: { turbo_confirm: t("madmin.confirmations.delete") }, class: "btn btn-danger" %>
17
+ <% end %>
16
18
  </div>
17
19
  </header>
18
20
 
@@ -0,0 +1,42 @@
1
+ el:
2
+ madmin:
3
+ layout:
4
+ open_menu: Άνοιγμα μενού
5
+ admin_suffix: Διαχείριση
6
+ navigation:
7
+ dashboard: Πίνακας ελέγχου
8
+ github: Το Madmin στο GitHub
9
+ dashboard:
10
+ title: Πίνακας ελέγχου Madmin
11
+ hint_html: Δημιουργήστε το <code>app/views/madmin/dashboard/show.html.erb</code> για να προσαρμόσετε τον πίνακα ελέγχου σας.
12
+ actions:
13
+ all: Όλα
14
+ view: Προβολή
15
+ edit: Επεξεργασία
16
+ delete: Διαγραφή
17
+ new: Νέο
18
+ remove: Αφαίρεση
19
+ cancel: Ακύρωση
20
+ search:
21
+ placeholder: Αναζήτηση
22
+ titles:
23
+ new: Νέο %{name}
24
+ edit: Επεξεργασία %{name}
25
+ form:
26
+ errors:
27
+ one: Υπήρξε 1 σφάλμα με την υποβολή σας
28
+ other: Υπήρξαν %{count} σφάλματα με την υποβολή σας
29
+ flash:
30
+ readonly: "%{name}: μόνο για ανάγνωση"
31
+ confirmations:
32
+ delete: Είστε σίγουροι;
33
+ remove_with_changes: Είστε σίγουροι; Θα χάσετε όλες τις άλλες αλλαγές.
34
+ nested_form:
35
+ add_new: "+ Προσθήκη νέου"
36
+ fields:
37
+ attachment:
38
+ one: "%{count} συνημμένο"
39
+ other: "%{count} συνημμένα"
40
+ missing_resource:
41
+ message: "Λείπει: %{resource}"
42
+ create_hint: "Δημιουργήστε το εκτελώντας:"
@@ -26,6 +26,8 @@ en:
26
26
  errors:
27
27
  one: There was 1 error with your submission
28
28
  other: There were %{count} errors with your submission
29
+ flash:
30
+ readonly: "%{name} is read-only"
29
31
  confirmations:
30
32
  delete: Are you sure?
31
33
  remove_with_changes: Are you sure? You will lose any other changes.
@@ -26,6 +26,8 @@ fr:
26
26
  errors:
27
27
  one: Il y a eu 1 erreur dans votre soumission
28
28
  other: Il y a eu %{count} erreurs dans votre soumission
29
+ flash:
30
+ readonly: "%{name} est en lecture seule"
29
31
  confirmations:
30
32
  delete: Êtes-vous sûr ?
31
33
  remove_with_changes: Êtes-vous sûr ? Vous perdrez toutes les autres modifications.
@@ -0,0 +1,40 @@
1
+ ko:
2
+ madmin:
3
+ layout:
4
+ open_menu: 메뉴 열기
5
+ admin_suffix: 관리자
6
+ navigation:
7
+ dashboard: 대시보드
8
+ github: GitHub에서 Madmin 보기
9
+ dashboard:
10
+ title: Madmin 대시보드
11
+ hint_html: 대시보드를 원하는 대로 꾸미려면 <code>app/views/madmin/dashboard/show.html.erb</code> 파일을 생성하세요.
12
+ actions:
13
+ all: 전체
14
+ view: 보기
15
+ edit: 수정
16
+ delete: 삭제
17
+ new: 새로 만들기
18
+ remove: 제거
19
+ cancel: 취소
20
+ search:
21
+ placeholder: 검색
22
+ titles:
23
+ new: 새 %{name}
24
+ edit: "%{name} 수정"
25
+ form:
26
+ errors:
27
+ one: 제출한 내용에 오류가 1개 있습니다
28
+ other: 제출한 내용에 오류가 %{count}개 있습니다
29
+ confirmations:
30
+ delete: 정말 삭제하시겠습니까?
31
+ remove_with_changes: 정말 제거하시겠습니까? 다른 변경 사항도 함께 사라집니다.
32
+ nested_form:
33
+ add_new: "+ 새로 추가"
34
+ fields:
35
+ attachment:
36
+ one: "첨부파일 %{count}개"
37
+ other: "첨부파일 %{count}개"
38
+ missing_resource:
39
+ message: "%{resource}이(가) 존재하지 않습니다."
40
+ create_hint: "다음 명령어를 실행하여 생성하세요:"
@@ -2,7 +2,7 @@ module Madmin
2
2
  module Fields
3
3
  class String < Field
4
4
  def searchable?
5
- options.fetch(:searchable, model.column_names.include?(attribute_name.to_s))
5
+ options.fetch(:searchable, resource.model_column_names.include?(attribute_name.to_s))
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Madmin
2
2
  module Fields
3
3
  class Text < Field
4
4
  def searchable?
5
- options.fetch(:searchable, model.column_names.include?(attribute_name.to_s))
5
+ options.fetch(:searchable, resource.model_column_names.include?(attribute_name.to_s))
6
6
  end
7
7
  end
8
8
  end
@@ -126,7 +126,15 @@ module Madmin
126
126
  model.respond_to? :friendly
127
127
  end
128
128
 
129
+ def readonly?
130
+ false
131
+ end
132
+
129
133
  def sortable_columns
134
+ model_column_names
135
+ end
136
+
137
+ def model_column_names
130
138
  model.column_names
131
139
  end
132
140
 
@@ -258,6 +266,8 @@ module Madmin
258
266
  end
259
267
 
260
268
  def model_store_accessors
269
+ return [] unless model.respond_to?(:stored_attributes)
270
+
261
271
  store_accessors = model.stored_attributes.values
262
272
  store_accessors.flatten
263
273
  end
@@ -7,6 +7,8 @@ module Madmin
7
7
  end
8
8
 
9
9
  def associations
10
+ return [] unless model.respond_to?(:reflections)
11
+
10
12
  model.reflections.reject { |name, association|
11
13
  # Hide these special associations
12
14
  name.starts_with?("rich_text") ||
@@ -22,10 +24,14 @@ module Madmin
22
24
  end
23
25
 
24
26
  def store_accessors
27
+ return [] unless model.respond_to?(:stored_attributes)
28
+
25
29
  model.stored_attributes.values.flatten
26
30
  end
27
31
 
28
32
  def virtual_attributes
33
+ return [] unless model.respond_to?(:attribute_types)
34
+
29
35
  virtual = []
30
36
 
31
37
  # has_secure_password columns
@@ -50,6 +56,8 @@ module Madmin
50
56
  end
51
57
 
52
58
  def redundant_attributes
59
+ return [] unless model.respond_to?(:attribute_types)
60
+
53
61
  redundant = []
54
62
 
55
63
  # has_secure_password columns
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "2.5.1"
2
+ VERSION = "2.6.0"
3
3
  end
data/lib/madmin.rb CHANGED
@@ -78,6 +78,8 @@ module Madmin
78
78
  end
79
79
 
80
80
  def sti_resource_name_for(object)
81
+ return unless object.class.respond_to?(:inheritance_column) && object.class.respond_to?(:column_names)
82
+
81
83
  if (column = object.class.inheritance_column) && object.class.column_names.include?(column)
82
84
  "#{object.class.superclass.base_class.name}Resource"
83
85
  end
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: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
@@ -198,8 +198,10 @@ files:
198
198
  - app/views/madmin/fields/time/_show.html.erb
199
199
  - app/views/madmin/shared/_label.html.erb
200
200
  - config/importmap.rb
201
+ - config/locales/el.yml
201
202
  - config/locales/en.yml
202
203
  - config/locales/fr.yml
204
+ - config/locales/ko.yml
203
205
  - lib/generators/madmin/field/field_generator.rb
204
206
  - lib/generators/madmin/field/templates/_form.html.erb
205
207
  - lib/generators/madmin/field/templates/_index.html.erb
@@ -274,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
276
  - !ruby/object:Gem::Version
275
277
  version: '0'
276
278
  requirements: []
277
- rubygems_version: 4.0.18
279
+ rubygems_version: 4.0.16
278
280
  specification_version: 4
279
281
  summary: A modern admin for Ruby on Rails apps
280
282
  test_files: []