madmin 3.1.0 → 3.1.2
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 +4 -4
- data/app/controllers/madmin/resource_controller.rb +15 -2
- data/config/locales/el.yml +2 -0
- data/config/locales/en.yml +2 -0
- data/config/locales/fr.yml +2 -0
- data/config/locales/ko.yml +3 -0
- data/lib/madmin/filter.rb +21 -4
- data/lib/madmin/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dde4d963db323d7d26197c454095beed2eff86ff40dcd9359e85ee480dd3bc13
|
|
4
|
+
data.tar.gz: 68566f86e2163ce2b7bf2fd12f6289d786fa118639936eff1aeef5f84feea616
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c2206a2935ec06380389dbca3109acabf2a3f0af8d84105d964b9551bde50c30c8746403aa718b0acd9e397efecb7fe70e74f9b8704d5a2c3d7d8474898305f
|
|
7
|
+
data.tar.gz: eb2128311c6fd923d69f3d58955e7c9e0bdf322a8949532fc156ec8fec6bba4ab6afd6771d4b06df584a3939ef67ba5879dad16da75611d37816857b92d9582f
|
|
@@ -47,12 +47,25 @@ module Madmin
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def destroy
|
|
50
|
-
@record.destroy
|
|
51
|
-
|
|
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
|
data/config/locales/el.yml
CHANGED
|
@@ -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: Είστε σίγουροι; Θα χάσετε όλες τις άλλες αλλαγές.
|
data/config/locales/en.yml
CHANGED
|
@@ -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.
|
data/config/locales/fr.yml
CHANGED
|
@@ -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.
|
data/config/locales/ko.yml
CHANGED
|
@@ -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: 정말 제거하시겠습니까? 다른 변경 사항도 함께 사라집니다.
|
data/lib/madmin/filter.rb
CHANGED
|
@@ -12,6 +12,9 @@ module Madmin
|
|
|
12
12
|
|
|
13
13
|
WITHOUT_VALUE = %w[blank present true false].freeze
|
|
14
14
|
|
|
15
|
+
# Operators that match the value as text instead of casting it to the column's type
|
|
16
|
+
MATCHING_OPERATORS = %w[contains starts_with].freeze
|
|
17
|
+
|
|
15
18
|
attr_reader :field, :operator, :value
|
|
16
19
|
|
|
17
20
|
# Skips conditions for unknown columns or operators, and values that don't
|
|
@@ -45,15 +48,16 @@ module Madmin
|
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
def valid?
|
|
48
|
-
field&.filter_type.present? && OPERATORS[type].include?(operator) &&
|
|
51
|
+
field&.filter_type.present? && OPERATORS[type].include?(operator) &&
|
|
52
|
+
(!value? || (matching_operator? ? value.present? : typed_value.present?))
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
def apply(scope)
|
|
52
56
|
attribute = scope.arel_table[column]
|
|
53
57
|
|
|
54
58
|
case operator
|
|
55
|
-
when "contains" then scope.where(attribute.matches("%#{escaped_value}%"))
|
|
56
|
-
when "starts_with" then scope.where(attribute.matches("#{escaped_value}%"))
|
|
59
|
+
when "contains" then scope.where(as_text(attribute).matches("%#{escaped_value}%"))
|
|
60
|
+
when "starts_with" then scope.where(as_text(attribute).matches("#{escaped_value}%"))
|
|
57
61
|
when "eq" then scope.where(column => typed_value)
|
|
58
62
|
when "gt" then scope.where(attribute.gt(typed_value))
|
|
59
63
|
when "gte" then scope.where(attribute.gteq(typed_value))
|
|
@@ -85,12 +89,25 @@ module Madmin
|
|
|
85
89
|
(type == :array) ? attribute_type.subtype : attribute_type
|
|
86
90
|
end
|
|
87
91
|
|
|
92
|
+
def matching_operator?
|
|
93
|
+
MATCHING_OPERATORS.include?(operator)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def uuid?
|
|
97
|
+
value_type.type == :uuid
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def as_text(attribute)
|
|
101
|
+
uuid? ? Arel::Nodes::NamedFunction.new("CAST", [attribute.as("CHAR(36)")]) : attribute
|
|
102
|
+
end
|
|
103
|
+
|
|
88
104
|
def escaped_value
|
|
89
105
|
field.model.sanitize_sql_like(value)
|
|
90
106
|
end
|
|
91
107
|
|
|
92
108
|
def blank_values
|
|
93
|
-
|
|
109
|
+
# UUIDs cast "" to NULL, which would match nothing
|
|
110
|
+
(type == :string && !uuid?) ? [nil, ""] : nil
|
|
94
111
|
end
|
|
95
112
|
end
|
|
96
113
|
end
|
data/lib/madmin/version.rb
CHANGED