madmin 1.2.6 → 1.2.8

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: 79be87e2c5e4bb8b7734ebfac9b623459491a836412bbd0faf077033e6a725ff
4
- data.tar.gz: a5f93e689c76e156ab396b7da05d47148e19b9ed7bd1f136c4a13b3530c1852a
3
+ metadata.gz: 452ba760d0701d79257b2f0ef4282a785dd3bc3e5380802c75220a6e7e8d3113
4
+ data.tar.gz: af23fac79122683d21c97866a355b2ebb373f7353610a46e8b83f25504a7e9b2
5
5
  SHA512:
6
- metadata.gz: 8bde02b65e86325f630bb2de481a3612e1ae5544891ac3e77bc5ffa78eb158eb6f5603967729040ac408a47f337b42375897848ba89e38a7723ff072dbb97703
7
- data.tar.gz: c709b74a65fef5383582e3577268dc61e85cb085ce233da6218b586fcf990da32ef5d60cb4991251b3a6b4485f660e018952135233ba23a3bdfeaadfcdbf459a
6
+ metadata.gz: 0e37320de16647c286f7551e819f290bd040862ba0b209f8ee0a57971c76ee2988fa149a889e6bb366e5fe212eb98c93f101cb010ac65af34f64a9144ec34800
7
+ data.tar.gz: 0ff60d8bca0aeb06769542e1d550ed468cad26213ab04259335dbec5e61e03890fc253babb78ac09358c15345f6c98d7b1fc55acaf77fe2115939b93d0d7005c
data/README.md CHANGED
@@ -73,6 +73,23 @@ rails g madmin:views:index
73
73
  # -> app/views/madmin/application/index.html.erb
74
74
  ```
75
75
 
76
+ You might want to make some of your model's attributes visible in some views but invisible in others.
77
+ The `attribute` method in model_resource.rb gives you that flexibility.
78
+
79
+ ```bash
80
+ # -> app/madmin/resources/book_resource.rb
81
+ ```
82
+ ```ruby
83
+ class UserResource < Madmin::Resource
84
+ attribute :id, form: false
85
+ attribute :tile
86
+ attribute :subtitle, index: false
87
+ attribute :author
88
+ attribute :genre
89
+ attribute :pages, show: false
90
+ end
91
+ ```
92
+
76
93
  You can also scope the copied view(s) to a specific Resource/Model:
77
94
  ```bash
78
95
  rails generate madmin:views:index Book
@@ -15,7 +15,7 @@ module Madmin
15
15
  end
16
16
 
17
17
  def clear_search_params
18
- resource.index_path(params.permit(:sort, :direction))
18
+ resource.index_path(sort: params[:sort], direction: params[:direction])
19
19
  end
20
20
  end
21
21
  end
@@ -2,13 +2,13 @@ module Madmin
2
2
  module SortHelper
3
3
  def sortable(column, title, options = {})
4
4
  matching_column = (column.to_s == sort_column)
5
- direction = sort_direction == "asc" ? "desc" : "asc"
5
+ direction = (sort_direction == "asc") ? "desc" : "asc"
6
6
 
7
7
  link_to resource.index_path(sort: column, direction: direction), options do
8
8
  concat title
9
9
  if matching_column
10
10
  concat " "
11
- concat tag.i(sort_direction == "asc" ? "▲" : "▼")
11
+ concat tag.i((sort_direction == "asc") ? "▲" : "▼")
12
12
  end
13
13
  end
14
14
  end
@@ -7,9 +7,7 @@
7
7
  <title>
8
8
  Madmin: <%= Rails.application.class %>
9
9
  </title>
10
- <link href="https://unpkg.com/@tailwindcss/forms/dist/forms.min.css" rel="stylesheet" />
11
- <link href="https://unpkg.com/tailwindcss@^2.0/dist/tailwind.min.css" rel="stylesheet" />
12
- <link href="https://unpkg.com/@tailwindcss/typography/dist/typography.min.css" rel="stylesheet" />
10
+
13
11
  <%= csrf_meta_tags %>
14
12
 
15
13
  <%= render "javascript" %>
@@ -1,28 +1,44 @@
1
+ <script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script>
1
2
  <%= stylesheet_link_tag "https://unpkg.com/flatpickr/dist/flatpickr.min.css", "data-turbo-track": "reload" %>
2
3
  <%= stylesheet_link_tag "https://unpkg.com/trix/dist/trix.css", "data-turbo-track": "reload" %>
3
4
  <%= stylesheet_link_tag "https://unpkg.com/tom-select/dist/css/tom-select.min.css", "data-turbo-track": "reload" %>
4
5
 
5
- <script type="module">
6
- import { Application, Controller } from 'https://cdn.skypack.dev/@hotwired/stimulus'
7
- const application = Application.start()
6
+ <script type="importmap" data-turbo-track="reload">
7
+ {
8
+ "imports": {
9
+ "@hotwired/stimulus": "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js",
10
+ "@hotwired/turbo": "https://unpkg.com/@hotwired/turbo",
11
+ "@hotwired/turbo-rails": "https://unpkg.com/@hotwired/turbo-rails",
12
+ "@rails/actiontext": "https://unpkg.com/@rails/actiontext@<%= npm_rails_version %>/app/assets/javascripts/actiontext.js",
13
+ "@rails/activestorage": "https://unpkg.com/@rails/activestorage@<%= npm_rails_version %>/app/assets/javascripts/activestorage.esm.js",
14
+ "flatpickr": "https://unpkg.com/flatpickr/dist/esm/index.js",
15
+ "stimulus-flatpickr": "https://unpkg.com/stimulus-flatpickr@3.0.0-0/dist/index.m.js",
16
+ "tailwindcss-stimulus-components": "https://unpkg.com/tailwindcss-stimulus-components/dist/tailwindcss-stimulus-components.modern.js",
17
+ "tom-select": "https://unpkg.com/tom-select/dist/esm/tom-select.complete.js",
18
+ "trix": "https://unpkg.com/trix"
19
+ }
20
+ }
21
+ </script>
22
+ <script async src="https://unpkg.com/es-module-shims/dist/es-module-shims.js"></script>
8
23
 
9
- import { Dropdown } from "https://cdn.skypack.dev/tailwindcss-stimulus-components"
10
- application.register("dropdown", Dropdown)
24
+ <script type="module">
25
+ import * as Turbo from "@hotwired/turbo-rails"
11
26
 
12
- import stimulusFlatpickr from 'https://cdn.skypack.dev/stimulus-flatpickr@3.0.0-0'
13
- application.register("flatpickr", stimulusFlatpickr)
27
+ import * as ActiveStorage from "@rails/activestorage"
28
+ ActiveStorage.start()
29
+ import "trix"
30
+ import "@rails/actiontext"
14
31
 
15
- import TomSelect from 'https://cdn.skypack.dev/tom-select'
32
+ import { Application, Controller } from '@hotwired/stimulus'
33
+ const application = Application.start()
16
34
 
17
- import Rails from 'https://cdn.skypack.dev/@rails/ujs@<%= npm_rails_version %>'
18
- import * as ActiveStorage from 'https://cdn.skypack.dev/@rails/activestorage@<%= npm_rails_version %>'
19
- import 'https://cdn.skypack.dev/trix'
20
- import 'https://cdn.skypack.dev/@rails/actiontext@<%= npm_rails_version %>'
35
+ import { Dropdown } from "tailwindcss-stimulus-components"
36
+ application.register("dropdown", Dropdown)
21
37
 
22
- if (!window._rails_loaded) { Rails.start() }
23
- ActiveStorage.start()
38
+ import StimulusFlatpickr from "stimulus-flatpickr"
39
+ application.register("flatpickr", StimulusFlatpickr)
24
40
 
25
- import * as Turbo from "https://cdn.skypack.dev/@hotwired/turbo"
41
+ import TomSelect from "tom-select"
26
42
 
27
43
  (() => {
28
44
  application.register('select', class extends Controller {
@@ -59,4 +59,4 @@
59
59
  </tbody>
60
60
  </table>
61
61
  </div>
62
- <%== pagy_nav(@pagy) if @pagy.pages > 1 %>
62
+ <%== render(partial: 'madmin/pagy/nav', locals: { pagy: @pagy }) if @pagy.pages > 1 %>
@@ -5,11 +5,12 @@
5
5
  <%= link_to resource.display_name(@record), resource.show_path(@record), class: "text-indigo-500 font-bold" %>
6
6
  </h1>
7
7
 
8
- <div class="flex items-center px-4">
9
- <div class="mr-2">
10
- <%= link_to "Edit", resource.edit_path(@record), class: "block bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow" %>
11
- </div>
12
- <%= button_to "Delete", resource.show_path(@record), method: :delete, data: { confirm: "Are you sure?" }, class: "bg-white hover:bg-gray-100 text-red-500 font-semibold py-2 px-4 border border-red-500 rounded shadow pointer-cursor" %>
8
+ <div class="flex gap-2 items-center px-4">
9
+ <% resource.member_actions.each do |action| %>
10
+ <%= instance_eval &action %>
11
+ <% end %>
12
+ <%= link_to "Edit", resource.edit_path(@record), class: "block bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow" %>
13
+ <%= button_to "Delete", resource.show_path(@record), method: :delete, data: { turbo_confirm: "Are you sure?" }, class: "bg-white hover:bg-gray-100 text-red-500 font-semibold py-2 px-4 border border-red-500 rounded shadow pointer-cursor" %>
13
14
  </div>
14
15
  </div>
15
16
 
@@ -0,0 +1,20 @@
1
+ <%#
2
+ This template is i18n-ready: if you don't use i18n, then you can replace the pagy_t
3
+ calls with the actual strings ("&lsaquo; Prev", "Next &rsaquo;", "&hellip;").
4
+ The link variable is set to a proc that returns the link tag.
5
+ Usage: link.call( page_number [, text [, extra_attributes_string ]])
6
+ -%>
7
+ <% link = pagy_link_proc(pagy) -%>
8
+ <%# -%><nav aria-label="pager" class="space-x-1 px-2 py-1" role="navigation">
9
+ <% if pagy.prev -%> <span><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="text-white bg-indigo-500 rounded-2xl px-3 py-1.5"') %></span>
10
+ <% else -%> <span class="text-gray-400 bg-gray-100 rounded-2xl px-3 py-1.5 cursor-not-allowed"><%== pagy_t('pagy.nav.prev') %></span>
11
+ <% end -%>
12
+ <% pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] -%>
13
+ <% if item.is_a?(Integer) -%> <span><%== link.call(item, item, 'class="text-gray-400 rounded-full px-2.5 py-1.5 hover:bg-indigo-200 hover:text-indigo-500"') %></span>
14
+ <% elsif item.is_a?(String) -%> <span class="text-indigo-500 font-semibold px-2.5 py-1.5"><%= item %></span>
15
+ <% elsif item == :gap -%> <span class="text-gray-400 text-xl px-1.5 py-1.5"><%== pagy_t('pagy.nav.gap') %></span>
16
+ <% end -%>
17
+ <% end -%>
18
+ <% if pagy.next -%> <span><%== link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next" class="text-white bg-indigo-500 rounded-2xl px-3 py-1.5"') %></span>
19
+ <% else -%> <span class="text-gray-400 bg-gray-100 rounded-2xl px-3 py-1.5 cursor-not-allowed"><%== pagy_t('pagy.nav.next') %></span>
20
+ <% end -%>
@@ -3,7 +3,7 @@ module Madmin
3
3
  class NestedHasMany < Field
4
4
  DEFAULT_ATTRIBUTES = %w[_destroy id].freeze
5
5
  def nested_attributes
6
- resource.attributes.reject { |name, attribute| skipped_fields.include?(name) }
6
+ resource.attributes.except(*skipped_fields)
7
7
  end
8
8
 
9
9
  def resource
@@ -1,11 +1,13 @@
1
1
  module Madmin
2
2
  class Resource
3
3
  class_attribute :attributes, default: ActiveSupport::OrderedHash.new
4
+ class_attribute :member_actions, default: []
4
5
  class_attribute :scopes, default: []
5
6
 
6
7
  class << self
7
8
  def inherited(base)
8
9
  base.attributes = attributes.dup
10
+ base.member_actions = scopes.dup
9
11
  base.scopes = scopes.dup
10
12
  super
11
13
  end
@@ -108,6 +110,10 @@ module Madmin
108
110
  attributes.values.select { |a| a.field.searchable? }
109
111
  end
110
112
 
113
+ def member_action(&block)
114
+ member_actions << block
115
+ end
116
+
111
117
  private
112
118
 
113
119
  def field_for_type(type)
@@ -129,6 +135,7 @@ module Madmin
129
135
  text: Fields::Text,
130
136
  time: Fields::Time,
131
137
  timestamp: Fields::Time,
138
+ timestamptz: Fields::Time,
132
139
  password: Fields::Password,
133
140
  file: Fields::File,
134
141
 
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "1.2.6"
2
+ VERSION = "1.2.8"
3
3
  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: 1.2.6
4
+ version: 1.2.8
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-16 00:00:00.000000000 Z
12
+ date: 2023-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -32,9 +32,6 @@ dependencies:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '3.5'
35
- - - "<"
36
- - !ruby/object:Gem::Version
37
- version: '6.0'
38
35
  type: :runtime
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,9 +39,6 @@ dependencies:
42
39
  - - ">="
43
40
  - !ruby/object:Gem::Version
44
41
  version: '3.5'
45
- - - "<"
46
- - !ruby/object:Gem::Version
47
- version: '6.0'
48
42
  description: It's an admin, obviously.
49
43
  email:
50
44
  - excid3@gmail.com
@@ -139,6 +133,7 @@ files:
139
133
  - app/views/madmin/fields/time/_form.html.erb
140
134
  - app/views/madmin/fields/time/_index.html.erb
141
135
  - app/views/madmin/fields/time/_show.html.erb
136
+ - app/views/madmin/pagy/_nav.html.erb
142
137
  - app/views/madmin/shared/_label.html.erb
143
138
  - lib/generators/madmin/field/field_generator.rb
144
139
  - lib/generators/madmin/field/templates/_form.html.erb
@@ -211,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
206
  - !ruby/object:Gem::Version
212
207
  version: '0'
213
208
  requirements: []
214
- rubygems_version: 3.2.32
209
+ rubygems_version: 3.4.12
215
210
  signing_key:
216
211
  specification_version: 4
217
212
  summary: A modern admin for Ruby on Rails apps