madmin 3.0.0 → 3.1.1

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: 502a8cbe4b6c86b1fa6f45d2f4d0f1f5b7852b48805a8d980cfb177ed4151c51
4
- data.tar.gz: 41d8fbfd222f0758f81e2b90762d54ddbefd279ebd18b455ac2def6bd2a60e1e
3
+ metadata.gz: f115a8b369e2c84e6eda3dd65cd7734f9fc3ba4ec6c49679552202af4b651d66
4
+ data.tar.gz: 18b426fbe6ae3f17945d57b9bf6be94d7e063ea4f6fb71669443cce95ec38b02
5
5
  SHA512:
6
- metadata.gz: c390c0a27fcfe25bee8b1ab32f7d53644cc68cad9ee386f17adf810839a511212dfa7fe821cf275edd63a95d1dccbdbeffb22bad56f1ffa5db6c0e67e56d3a74
7
- data.tar.gz: be7ec1e7fa71db380147c44f154e539e56719b35be488f7068473dfccfeeba44175abb58ee281bf4eb1089ab8a188eb5b66c0e5d46d847f639f1bbe15895107d
6
+ metadata.gz: a044fdc4cd021c9bb2d68586a07f2fbb446ac8722ffba771278a8778171b99172cafa97ccc05871cfbef7a95cc3b779ea4a78bb823b90aafc56fbabd52a217a3
7
+ data.tar.gz: 6b287859f38758d12edb7a4dcc50161b1f7147c233fc8ffc3aed30cfc9c6dd9d71c55d82edf258096210c6001b5b476a9e0350cdbe32b23233a79162ba668383
data/README.md CHANGED
@@ -229,6 +229,19 @@ end
229
229
 
230
230
  A nested has one shows its fields when the record exists, or an "Add" link when it doesn't, so saving the parent doesn't create an empty record.
231
231
 
232
+ ### Direct Uploads
233
+
234
+ File fields upload through the form by default. Add `direct_upload: true` to upload straight from the browser to your Active Storage service instead, which keeps large files off your app servers and avoids request timeouts:
235
+
236
+ ```ruby
237
+ class PostResource < Madmin::Resource
238
+ attribute :image, direct_upload: true
239
+ attribute :attachments, direct_upload: true
240
+ end
241
+ ```
242
+
243
+ Cloud services like S3 need CORS configured to accept uploads from the browser. See the [Active Storage guide](https://guides.rubyonrails.org/active_storage_overview.html#cross-origin-resource-sharing-cors-configuration).
244
+
232
245
  ## Custom Fields
233
246
 
234
247
  You can generate a custom field with:
@@ -47,12 +47,25 @@ module Madmin
47
47
  end
48
48
 
49
49
  def destroy
50
- @record.destroy
51
- redirect_to resource.index_path
50
+ if @record.destroy
51
+ redirect_to resource.index_path, status: :see_other
52
+ else
53
+ destroy_failed destroy_errors
54
+ end
55
+ rescue ActiveRecord::DeleteRestrictionError, ActiveRecord::InvalidForeignKey
56
+ destroy_failed t("madmin.flash.destroy_restricted", name: resource.friendly_name)
52
57
  end
53
58
 
54
59
  private
55
60
 
61
+ def destroy_failed(message)
62
+ redirect_back_or_to resource.index_path, alert: message, status: :see_other
63
+ end
64
+
65
+ def destroy_errors
66
+ @record.errors.full_messages.to_sentence.presence || t("madmin.flash.destroy_failed", name: resource.friendly_name)
67
+ end
68
+
56
69
  def set_record
57
70
  @record = resource.model_find(params[:id])
58
71
  end
@@ -1,3 +1,7 @@
1
1
  import "@hotwired/turbo-rails"
2
2
  import "@rails/actiontext"
3
+ import * as ActiveStorage from "@rails/activestorage"
3
4
  import "controllers"
5
+
6
+ // Uploads files straight to storage for fields with `direct_upload: true`. Other file fields submit with the form
7
+ ActiveStorage.start()
@@ -7,6 +7,3 @@ application.debug = false
7
7
  window.Stimulus = application
8
8
 
9
9
  export { application }
10
-
11
- import { Dropdown } from "tailwindcss-stimulus-components"
12
- application.register("dropdown", Dropdown)
@@ -1,4 +1,4 @@
1
- <%= form.file_field field.to_param, class: "form-input"%>
1
+ <%= form.file_field field.to_param, direct_upload: field.options.direct_upload, class: "form-input" %>
2
2
 
3
3
  <% if form.object.persisted? %>
4
4
  <div class="mt-2">
@@ -1 +1 @@
1
- <%= form.file_field field.attribute_name, multiple: true, class: "form-input" %>
1
+ <%= form.file_field field.attribute_name, multiple: true, direct_upload: field.options.direct_upload, class: "form-input" %>
@@ -1 +1 @@
1
- <%= form.file_field field.attribute_name, class: "form-input" %>
1
+ <%= form.file_field field.attribute_name, direct_upload: field.options.direct_upload, class: "form-input" %>
data/config/importmap.rb CHANGED
@@ -10,5 +10,3 @@ pin "lexxy", to: "lexxy.js" if defined?(::Lexxy)
10
10
 
11
11
  pin_all_from Madmin::Engine.root.join("app/javascript/madmin/controllers"), under: "controllers", to: "madmin/controllers"
12
12
  pin_all_from Rails.root.join("app/javascript/madmin/controllers"), under: "controllers", to: "madmin/controllers"
13
-
14
- pin "tailwindcss-stimulus-components", to: "https://ga.jspm.io/npm:tailwindcss-stimulus-components@6.1.2/dist/tailwindcss-stimulus-components.module.js"
@@ -28,6 +28,8 @@ el:
28
28
  other: Υπήρξαν %{count} σφάλματα με την υποβολή σας
29
29
  flash:
30
30
  readonly: "%{name}: μόνο για ανάγνωση"
31
+ destroy_failed: "%{name}: η διαγραφή απέτυχε"
32
+ destroy_restricted: "%{name}: η διαγραφή απέτυχε επειδή άλλες εγγραφές εξαρτώνται από αυτήν"
31
33
  confirmations:
32
34
  delete: Είστε σίγουροι;
33
35
  remove_with_changes: Είστε σίγουροι; Θα χάσετε όλες τις άλλες αλλαγές.
@@ -28,6 +28,8 @@ en:
28
28
  other: There were %{count} errors with your submission
29
29
  flash:
30
30
  readonly: "%{name} is read-only"
31
+ destroy_failed: "%{name} could not be deleted"
32
+ destroy_restricted: "%{name} could not be deleted because other records depend on it"
31
33
  confirmations:
32
34
  delete: Are you sure?
33
35
  remove_with_changes: Are you sure? You will lose any other changes.
@@ -28,6 +28,8 @@ fr:
28
28
  other: Il y a eu %{count} erreurs dans votre soumission
29
29
  flash:
30
30
  readonly: "%{name} est en lecture seule"
31
+ destroy_failed: "%{name} n'a pas pu être supprimé"
32
+ destroy_restricted: "%{name} n'a pas pu être supprimé car d'autres enregistrements en dépendent"
31
33
  confirmations:
32
34
  delete: Êtes-vous sûr ?
33
35
  remove_with_changes: Êtes-vous sûr ? Vous perdrez toutes les autres modifications.
@@ -26,6 +26,9 @@ ko:
26
26
  errors:
27
27
  one: 제출한 내용에 오류가 1개 있습니다
28
28
  other: 제출한 내용에 오류가 %{count}개 있습니다
29
+ flash:
30
+ destroy_failed: "%{name}을(를) 삭제할 수 없습니다"
31
+ destroy_restricted: "다른 레코드가 참조하고 있어 %{name}을(를) 삭제할 수 없습니다"
29
32
  confirmations:
30
33
  delete: 정말 삭제하시겠습니까?
31
34
  remove_with_changes: 정말 제거하시겠습니까? 다른 변경 사항도 함께 사라집니다.
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.1"
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: 3.0.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver