-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathviews.diff
142 lines (142 loc) · 6.15 KB
/
views.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
diff --git a/app/views/datagrid/_enum_checkboxes.html.erb b/app/views/datagrid/_enum_checkboxes.html.erb
index 9f48319..281bb6f 100644
--- a/app/views/datagrid/_enum_checkboxes.html.erb
+++ b/app/views/datagrid/_enum_checkboxes.html.erb
@@ -2,10 +2,12 @@
Indent in this file may cause extra space to appear.
You can add indent if whitespace doesn't matter for you
%>
-<%- elements.each do |value, text, checked| -%>
+<div class="datagrid-enum-checkboxes">
+<%- choices.each do |value, text| -%>
<%- id = [form.object_name, filter.name, value].join('_').underscore -%>
-<%= form.label filter.name, options.merge(for: id) do -%>
-<%= form.check_box(filter.name, {multiple: true, id: id, checked: checked, include_hidden: false}, value.to_s, nil) -%>
+<%= form.datagrid_label(filter.name, for: id, **options) do -%>
+<%= form.datagrid_filter_input(filter.name, id: id, value: value) -%>
<%= text -%>
<%- end -%>
<%- end -%>
+</div>
diff --git a/app/views/datagrid/_form.html.erb b/app/views/datagrid/_form.html.erb
index 7e175c1..fc4f4ae 100644
--- a/app/views/datagrid/_form.html.erb
+++ b/app/views/datagrid/_form.html.erb
@@ -1,12 +1,12 @@
-<%= form_for grid, options do |f| -%>
+<%= form_with model: grid, html: {class: 'datagrid-form'}, scope: grid.param_name, method: :get, **options do |f| %>
<% grid.filters.each do |filter| %>
- <div class="datagrid-filter filter">
+ <div class="datagrid-filter" data-filter="<%= filter.name %>" data-type="<%= filter.type %>">
<%= f.datagrid_label filter %>
<%= f.datagrid_filter filter %>
</div>
<% end %>
<div class="datagrid-actions">
- <%= f.submit I18n.t("datagrid.form.search").html_safe, class: "datagrid-submit" %>
- <%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => {}), class: "datagrid-reset" %>
+ <%= f.submit I18n.t("datagrid.form.search"), class: "datagrid-submit" %>
+ <%= link_to I18n.t('datagrid.form.reset'), url_for(grid.to_param => {}), class: "datagrid-reset" %>
</div>
<% end -%>
diff --git a/app/views/datagrid/_head.html.erb b/app/views/datagrid/_head.html.erb
index e939128..2c59aa7 100644
--- a/app/views/datagrid/_head.html.erb
+++ b/app/views/datagrid/_head.html.erb
@@ -1,8 +1,31 @@
<tr>
<% grid.html_columns(*options[:columns]).each do |column| %>
- <th class="<%= datagrid_column_classes(grid, column) %>">
+ <%= tag.th(
+ # Consider maintaining consistency with datagrid/rows partial
+ "data-column": column.name,
+ **column.tag_options,
+ class: [
+ column.tag_options[:class],
+ # Adding HTML classes based on condition
+ "datagrid-order-active-asc": grid.ordered_by?(column, false),
+ "datagrid-order-active-desc": grid.ordered_by?(column, true),
+ ]
+ ) do %>
<%= column.header %>
- <%= datagrid_order_for(grid, column, options) if column.supports_order? && options[:order]%>
- </th>
+ <% if column.supports_order? && options[:order] -%>
+ <div class="datagrid-order">
+ <%= link_to(
+ I18n.t("datagrid.table.order.asc"),
+ datagrid_order_path(grid, column, false),
+ class: "datagrid-order-control-asc"
+ ) %>
+ <%= link_to(
+ I18n.t("datagrid.table.order.desc"),
+ datagrid_order_path(grid, column, true),
+ class: "datagrid-order-control-desc"
+ ) %>
+ </div>
+ <% end -%>
+ <% end -%>
<% end %>
</tr>
diff --git a/app/views/datagrid/_range_filter.html.erb b/app/views/datagrid/_range_filter.html.erb
index 7a8a123..faa2575 100644
--- a/app/views/datagrid/_range_filter.html.erb
+++ b/app/views/datagrid/_range_filter.html.erb
@@ -1,3 +1,5 @@
-<%= form.datagrid_filter_input(filter, **from_options) %>
-<span class="separator <%= filter.type %>"><%= I18n.t('datagrid.filters.range.separator') %></span>
-<%= form.datagrid_filter_input(filter, **to_options) %>
+<%= form.datagrid_filter_input(filter, class: 'datagrid-range-from', **from_options) %>
+<span class="datagrid-range-separator"><%= I18n.t('datagrid.filters.range.separator') %></span>
+<%# Generating id only for "from" input to make sure -%>
+<%# there is no duplicate id in DOM and click on label focuses the first input -%>
+<%= form.datagrid_filter_input(filter, class: 'datagrid-range-to', **to_options, id: nil) %>
diff --git a/app/views/datagrid/_row.html.erb b/app/views/datagrid/_row.html.erb
index f54d21c..a2254b0 100644
--- a/app/views/datagrid/_row.html.erb
+++ b/app/views/datagrid/_row.html.erb
@@ -1,5 +1,16 @@
<tr>
<% grid.html_columns(*options[:columns]).each do |column| %>
- <td class="<%= datagrid_column_classes(grid, column) %>"><%= datagrid_value(grid, column, asset) %></td>
+ <%= tag.td(
+ datagrid_value(grid, column, asset),
+ # Consider maintaining consistency with datagrid/rows partial
+ "data-column": column.name,
+ **column.tag_options,
+ class: [
+ column.tag_options[:class],
+ # Adding HTML classes based on condition
+ "datagrid-order-active-asc": grid.ordered_by?(column, false),
+ "datagrid-order-active-desc": grid.ordered_by?(column, true),
+ ]
+ ) %>
<% end %>
</tr>
diff --git a/app/views/datagrid/_table.html.erb b/app/views/datagrid/_table.html.erb
index 8708c05..88eeafb 100644
--- a/app/views/datagrid/_table.html.erb
+++ b/app/views/datagrid/_table.html.erb
@@ -5,18 +5,18 @@ Local variables:
* options - passed options Hash
%>
<% if grid.html_columns(*options[:columns]).any? %>
- <%= content_tag :table, options[:html] do %>
+ <%= tag.table class: 'datagrid-table', **options.fetch(:html, {}) do %>
<thead>
- <%= datagrid_header(grid, options) %>
+ <%= datagrid_header(grid, **options) %>
</thead>
<tbody>
<% if assets.any? %>
<%= datagrid_rows(grid, assets, **options) %>
<% else %>
- <tr><td class="noresults" colspan="100%"><%= I18n.t('datagrid.no_results').html_safe %></td></tr>
+ <tr><td class="datagrid-no-results" colspan="100%"><%= I18n.t('datagrid.no_results') %></td></tr>
<% end %>
</tbody>
<% end %>
<% else -%>
- <%= I18n.t("datagrid.table.no_columns").html_safe %>
+ <%= I18n.t("datagrid.table.no_columns") %>
<% end %>