yummy-guide-generic-administrate 0.6.1 → 0.6.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 19e487e3834d936ad510df92a00a47f99447a31efd61145fd31798b5a44cbaec
|
|
4
|
+
data.tar.gz: ec73a8e829f7533ac79ebe3d4cca687b0d519c6e048940e2978b3ad25d44f0cc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9d3da1b8ec25f8a3b0e4c01ef625f35a9e2d369c8a2656cb98f0813ec6ffe6343c375cfa91d42038c4d3527eafb3b61cdff8446cb508124a68c585a80fd5f834
|
|
7
|
+
data.tar.gz: d590ff5f0b427417f86a5951bdb514ab16ee27659ddccbfd22b84737a4f34ce7b78964ae5dc4bd10b4ba075df6363c634f87f274b2489945589fb1df44100561
|
data/README.md
CHANGED
|
@@ -355,13 +355,14 @@ dashboard の `FILTER_PATH` / `FILTER_CLEAR_PATH` より優先されます。
|
|
|
355
355
|
) %>
|
|
356
356
|
```
|
|
357
357
|
|
|
358
|
-
標準 Field は `Text`, `Select`, `Checkbox`, `RadioGroup`, `
|
|
359
|
-
`DateRange`, `DatetimeRange`, `DatetimeLocalRange`, `Custom` です。
|
|
358
|
+
標準 Field は `Text`, `Select`, `Checkbox`, `RadioGroup`, `BooleanRadioGroup`,
|
|
359
|
+
`CheckboxGroup`, `DateRange`, `DatetimeRange`, `DatetimeLocalRange`, `Custom` です。
|
|
360
360
|
主な option は次のとおりです。
|
|
361
361
|
|
|
362
362
|
- 共通: `label`, `default`, `if`, `class`, `id`, `placeholder`, `inputmode`, `pattern`
|
|
363
363
|
- 選択系: `collection` または `options`, `select_options`
|
|
364
364
|
- checkbox: `checked_value`, `unchecked_value`
|
|
365
|
+
- boolean radio group: `unspecified_label`, `true_label`, `false_label`
|
|
365
366
|
- checkbox group: `group`
|
|
366
367
|
- range: `from`, `to`, `from_default`, `to_default`, `css_class`
|
|
367
368
|
|
|
@@ -379,6 +380,12 @@ FILTER_ATTRIBUTES = {
|
|
|
379
380
|
label: "Status",
|
|
380
381
|
collection: ->(_view, locals) { locals[:status_collection] },
|
|
381
382
|
select_options: { include_blank: true }
|
|
383
|
+
),
|
|
384
|
+
visible: YummyGuide::Administrate::Filters::BooleanRadioGroup.with_options(
|
|
385
|
+
label: "Visible",
|
|
386
|
+
unspecified_label: "-",
|
|
387
|
+
true_label: "Visible",
|
|
388
|
+
false_label: "Hidden"
|
|
382
389
|
)
|
|
383
390
|
}.freeze
|
|
384
391
|
```
|
|
@@ -152,6 +152,39 @@ module YummyGuide
|
|
|
152
152
|
end
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
+
class BooleanRadioGroup < Base
|
|
156
|
+
protected
|
|
157
|
+
|
|
158
|
+
def input_cell(view_context, _form, scope, current_values, locals)
|
|
159
|
+
selected = current_value(current_values).to_s
|
|
160
|
+
controls = boolean_options(view_context, locals).map do |label, value|
|
|
161
|
+
value_string = value.to_s
|
|
162
|
+
id = "#{scope}_#{name}_#{value_string.presence || "unspecified"}".parameterize(separator: "_")
|
|
163
|
+
|
|
164
|
+
view_context.content_tag(:label, style: "display: inline-flex; align-items: center; gap: 6px;") do
|
|
165
|
+
view_context.safe_join([
|
|
166
|
+
view_context.radio_button_tag("#{scope}[#{name}]", value, selected == value_string, id: id),
|
|
167
|
+
view_context.content_tag(:span, label)
|
|
168
|
+
])
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
view_context.content_tag(:td) do
|
|
173
|
+
view_context.content_tag(:div, view_context.safe_join(controls), style: "display: flex; align-items: center; gap: 12px; flex-wrap: wrap;")
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
private
|
|
178
|
+
|
|
179
|
+
def boolean_options(view_context, locals)
|
|
180
|
+
[
|
|
181
|
+
[evaluate_option(options.fetch(:unspecified_label, "Unspecified"), view_context, locals), ""],
|
|
182
|
+
[evaluate_option(options.fetch(:true_label, "true"), view_context, locals), "true"],
|
|
183
|
+
[evaluate_option(options.fetch(:false_label, "false"), view_context, locals), "false"]
|
|
184
|
+
]
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
155
188
|
class CheckboxGroup < Base
|
|
156
189
|
protected
|
|
157
190
|
|
|
@@ -49,6 +49,38 @@ RSpec.describe YummyGuide::Administrate::FilterControlsHelper do
|
|
|
49
49
|
expect(document.at_css('select[name="search_options[status]"] option[selected]')["value"]).to eq("closed")
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
# boolean radio group が未指定・true・falseを横並びで描画し、ラベルと選択状態を反映することを確認する
|
|
53
|
+
it "renders boolean radio group controls with custom labels" do
|
|
54
|
+
dashboard = Class.new
|
|
55
|
+
dashboard.const_set(
|
|
56
|
+
:FILTER_ATTRIBUTES,
|
|
57
|
+
{
|
|
58
|
+
visible: YummyGuide::Administrate::Filters::BooleanRadioGroup.with_options(
|
|
59
|
+
label: "Visible",
|
|
60
|
+
unspecified_label: "-",
|
|
61
|
+
true_label: "Visible",
|
|
62
|
+
false_label: "Hidden"
|
|
63
|
+
)
|
|
64
|
+
}.freeze
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
html = helper_host.admin_filter_controls(
|
|
68
|
+
dashboard: dashboard,
|
|
69
|
+
path: "/admin/resources",
|
|
70
|
+
search_options: { visible: "false" }
|
|
71
|
+
)
|
|
72
|
+
document = fragment(html)
|
|
73
|
+
|
|
74
|
+
wrapper = document.at_css('input[name="search_options[visible]"]').ancestors("div").first
|
|
75
|
+
|
|
76
|
+
expect(document.at_css('input[type="radio"][name="search_options[visible]"][value=""]')).to be_present
|
|
77
|
+
expect(document.at_css('input[type="radio"][name="search_options[visible]"][value="true"]')).to be_present
|
|
78
|
+
expect(document.at_css('input[type="radio"][name="search_options[visible]"][value="false"]')).to be_present
|
|
79
|
+
expect(document.at_css('input[type="radio"][name="search_options[visible]"][value="false"]')["checked"]).to eq("checked")
|
|
80
|
+
expect(wrapper["style"]).to include("display: flex")
|
|
81
|
+
expect(document.text).to include("-", "Visible", "Hidden")
|
|
82
|
+
end
|
|
83
|
+
|
|
52
84
|
# dashboard に定義した FILTER_PATH をフィルター送信先として利用できることを確認する
|
|
53
85
|
it "uses dashboard filter path when no explicit path is passed" do
|
|
54
86
|
dashboard = Class.new
|