slash_admin 0.1.0 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -12
  3. data/app/assets/images/slash_admin/favicon.png +0 -0
  4. data/app/assets/images/slash_admin/logo.png +0 -0
  5. data/app/assets/javascripts/slash_admin/application.js +33 -25
  6. data/app/assets/stylesheets/slash_admin/application.scss +271 -146
  7. data/app/assets/stylesheets/slash_admin/colors.scss +16 -13
  8. data/app/controllers/slash_admin/models_controller.rb +166 -32
  9. data/app/controllers/slash_admin/security/sessions_controller.rb +1 -1
  10. data/app/controllers/slash_admin/selectize_controller.rb +21 -1
  11. data/app/helpers/slash_admin/application_helper.rb +45 -4
  12. data/app/helpers/slash_admin/widgets_helper.rb +1 -0
  13. data/app/views/layouts/slash_admin/application.html.erb +1 -1
  14. data/app/views/slash_admin/base/_data_belongs_to.html.erb +14 -16
  15. data/app/views/slash_admin/base/_data_list.html.erb +118 -121
  16. data/app/views/slash_admin/base/_data_nestable.html.erb +2 -2
  17. data/app/views/slash_admin/base/_data_new.html.erb +4 -1
  18. data/app/views/slash_admin/base/_filters.html.erb +63 -55
  19. data/app/views/slash_admin/base/index.html.erb +3 -3
  20. data/app/views/slash_admin/custom_fields/_google_map.html.erb +14 -11
  21. data/app/views/slash_admin/custom_fields/_select.html.erb +5 -1
  22. data/app/views/slash_admin/custom_fields/_timezone.html.erb +2 -0
  23. data/app/views/slash_admin/dashboard/widgets/_statistic_progress_tile.html.erb +1 -1
  24. data/app/views/slash_admin/fields/_belongs_to.html.erb +2 -2
  25. data/app/views/slash_admin/fields/_carrierwave.html.erb +107 -10
  26. data/app/views/slash_admin/fields/_has_many.html.erb +2 -2
  27. data/app/views/slash_admin/fields/_has_one.html.erb +9 -24
  28. data/app/views/slash_admin/fields/_json.html.erb +1 -1
  29. data/app/views/slash_admin/fields/_jsonb.html.erb +14 -0
  30. data/app/views/slash_admin/{custom_fields → fields}/_nested_belongs_to.html.erb +11 -10
  31. data/app/views/slash_admin/fields/_nested_has_one.html.erb +23 -0
  32. data/app/views/slash_admin/security/sessions/new.html.erb +6 -3
  33. data/app/views/slash_admin/shared/_batch_actions.html.erb +1 -1
  34. data/app/views/slash_admin/shared/_header.html.erb +2 -3
  35. data/app/views/slash_admin/shared/_menu.html.erb +33 -30
  36. data/app/views/slash_admin/shared/_new_form_buttons.html.erb +2 -2
  37. data/config/initializers/validators.rb +4 -0
  38. data/config/locales/{slash_admin.en.yml → en.yml} +3 -0
  39. data/config/locales/{slash_admin.fr.yml → fr.yml} +4 -1
  40. data/lib/batch_translation.rb +1 -1
  41. data/lib/generators/slash_admin/override_admin/override_admin_generator.rb +1 -0
  42. data/lib/generators/slash_admin/override_session/templates/session.erb +2 -2
  43. data/lib/slash_admin.rb +1 -3
  44. data/lib/slash_admin/version.rb +1 -1
  45. data/vendor/assets/javascripts/bootstrap-datepicker.fr.min.js +1 -0
  46. data/vendor/assets/javascripts/bootstrap-datepicker.min.js +8 -0
  47. data/vendor/assets/stylesheets/bootstrap-datepicker.min.css +7 -0
  48. metadata +19 -69
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SlashAdmin::WidgetsHelper
3
4
  # number, title, icon, progress_label, percent, status
4
5
  def statistic_progress_tile(options = {})
@@ -10,7 +10,7 @@
10
10
  I18n.defaultLocale = "<%= I18n.default_locale %>";
11
11
  I18n.locale = "<%= I18n.locale %>";
12
12
  </script>
13
- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.6.0/js/froala_editor.pkgd.min.js"></script>
13
+ <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.9.3/js/froala_editor.pkgd.min.js"></script>
14
14
  <%= csrf_meta_tags %>
15
15
  </head>
16
16
  <body id="admin-dashboard" class="<% if session[:compact].present? %>page-sidebar-closed<% end %>">
@@ -1,8 +1,8 @@
1
- <div class="modal-dialog modal-lg" role="document">
1
+ <div class="modal-dialog modal-xl" role="document">
2
2
  <div class="modal-content">
3
3
  <%= form_for [:slash_admin, class_name_from_association(f.object, a).constantize.new], remote: true, html: {'data-type': 'json'} do |fs| %>
4
4
  <div class="modal-header">
5
- <%= t('slash_admin.view.create') %>
5
+ <%= t('slash_admin.view.create', model_name: class_name_from_association(f.object, a).constantize.model_name.human.downcase) %>
6
6
  <%= class_name_from_association(f.object, a).constantize.model_name.human.downcase %>
7
7
  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
8
8
  <span aria-hidden="true">&times;</span>
@@ -11,26 +11,24 @@
11
11
  <div class="modal-body">
12
12
  <div class="errors-json"></div>
13
13
  <%= render 'slash_admin/shared/errors_data_new' %>
14
- <% if @model.id.blank? %>
15
- <% if a.is_a?(Hash) %>
16
- <% params_assoc = "SlashAdmin::Models::#{class_name_from_association(f.object, a).pluralize}Controller".constantize.new.create_params(from: @model_class).each %>
17
- <% else %>
18
- <% params_assoc = "SlashAdmin::Models::#{a.to_s.classify.pluralize}Controller".constantize.new.create_params(from: @model_class).each %>
19
- <% end %>
20
- <% else %>
21
- <% if a.is_a?(Hash) %>
22
- <% params_assoc = "SlashAdmin::Models::#{class_name_from_association(f.object, a).pluralize}Controller".constantize.new.update_params(from: @model_class).each %>
23
- <% else %>
24
- <% params_assoc = "SlashAdmin::Models::#{a.to_s.classify.pluralize}Controller".constantize.new.update_params(from: @model_class).each %>
25
- <% end %>
14
+ <% if f.object.id.blank? %>
15
+ <% method = 'create_params' %>
16
+ <% else %>
17
+ <% method = 'update_params' %>
26
18
  <% end %>
19
+ <% if a.is_a?(Hash) %>
20
+ <% params_assoc = "SlashAdmin::Models::#{class_name_from_association(f.object, a).pluralize}Controller".constantize.new.send(method, from: @model_class) %>
21
+ <% else %>
22
+ <% params_assoc = "SlashAdmin::Models::#{a.to_s.classify.pluralize}Controller".constantize.new.send(method) %>
23
+ <% end %>
24
+
27
25
  <% params_assoc.each do |attribute| %>
28
- <%= render 'slash_admin/fields/form_group', f: fs, a: attribute %>
26
+ <%= render 'slash_admin/fields/form_group', f: fs, a: attribute %>
29
27
  <% end %>
30
28
  </div>
31
29
  <div class="modal-footer">
32
30
  <a href="#" data-dismiss="modal"><%= t('slash_admin.view.cancel') %></a>
33
- <button type="submit" class="btn btn-primary pull-right"><%= t('slash_admin.view.save') %></button>
31
+ <button type="submit" class="btn btn-primary float-right"><%= t('slash_admin.view.save') %></button>
34
32
  </div>
35
33
  <% end %>
36
34
  </div>
@@ -1,5 +1,4 @@
1
1
  <div class="block head-data-list">
2
- <div class="fix-block-head"></div>
3
2
  <%= render 'slash_admin/shared/better_paginate' %>
4
3
  <%= render 'slash_admin/shared/batch_actions' %>
5
4
  </div>
@@ -10,139 +9,137 @@
10
9
  </form>
11
10
 
12
11
  <%= form_for :filters, url: '', method: 'GET', html: {id: 'filters'} do |form| %>
13
- <table class="table table-striped table-bordered table-hover table-data-list">
14
- <thead>
15
- <tr role="row" class="heading">
16
- <th>
17
- <input type="checkbox" class="toggle-all"/>
18
- </th>
19
- <th
20
- data-order-field="id"
21
- <% if params[:order_field].to_s == 'id' %>
22
- class="ordered <%= params[:order].downcase %>"
23
- data-order="<%= params[:order] %>"
24
- <% else %>
25
- class="ordered"
26
- <% end %>
27
- >#
28
- </th>
29
- <% list_params.each do |attr| %>
30
- <% if attr.is_a?(Hash) %>
31
- <th><%= @model_class.human_attribute_name(attr.keys.first) %></th>
12
+ <div class="table-responsive">
13
+ <table class="table table-striped table-bordered table-hover table-data-list" data-turbolinks="false">
14
+ <thead>
15
+ <tr role="row" class="heading">
16
+ <th>
17
+ <input type="checkbox" class="toggle-all"/>
18
+ </th>
19
+ <th
20
+ data-order-field="id"
21
+ <% if params[:order_field].to_s == 'id' %>
22
+ class="ordered <%= params[:order].downcase %>"
23
+ data-order="<%= params[:order] %>"
32
24
  <% else %>
33
- <th
34
- <% if orderable?(@model_class, attr) %>
35
- data-order-field="<%= attr %>"
36
- <% if params[:order_field].to_s == attr.to_s %>
37
- class="ordered <%= params[:order].downcase %>"
38
- data-order="<%= params[:order] %>"
25
+ class="ordered"
26
+ <% end %>
27
+ >#
28
+ </th>
29
+ <% list_params.each do |attr| %>
30
+ <% if attr.is_a?(Hash) %>
31
+ <th><%= @model_class.human_attribute_name(attr.keys.first) %></th>
39
32
  <% else %>
40
- class="ordered"
33
+ <th
34
+ <% if orderable?(@model_class, attr) %>
35
+ data-order-field="<%= attr %>"
36
+ <% if params[:order_field].to_s == attr.to_s %>
37
+ class="ordered <%= params[:order].downcase %>"
38
+ data-order="<%= params[:order] %>"
39
+ <% else %>
40
+ class="ordered"
41
+ <% end %>
42
+ <% end %>>
43
+ <%= @model_class.human_attribute_name(attr) %>
44
+ </th>
41
45
  <% end %>
42
- <% end %>>
43
- <%= @model_class.human_attribute_name(attr) %>
44
- </th>
45
46
  <% end %>
46
- <% end %>
47
- <th class="text-center"><%= t('slash_admin.view.actions') %></th>
48
- </tr>
47
+ <th class="text-center"><%= t('slash_admin.view.actions') %></th>
48
+ </tr>
49
49
 
50
- <%= render 'filters', model: @model_class %>
51
- </thead>
50
+ <%= render 'filters', model: @model_class %>
51
+ </thead>
52
52
 
53
- <tbody>
54
- <% @models.each do |m| %>
55
- <tr>
56
- <td class="fit"><input type="checkbox" name="<%= @model_name.pluralize.downcase %>[] %>" value="<%= m.id %>"></td>
57
- <td class="fit"><%= m.id %></td>
58
- <% list_params.each do |attr| %>
59
- <% if attr.is_a?(Hash) %>
60
- <% if attr[attr.keys.first][:type].to_s == 'image' %>
61
- <td class="text-center">
62
- <% if m.send(attr.keys.first).present? %>
63
- <img src="<%= m.send(attr.keys.first) %>" class="img-fluid"/>
53
+ <tbody>
54
+ <% @models.each do |m| %>
55
+ <tr>
56
+ <td class="fit"><input type="checkbox" name="<%= @model_name.pluralize.downcase %>[] %>" value="<%= m.id %>"></td>
57
+ <td class="fit"><%= m.id %></td>
58
+ <% list_params.each do |attr| %>
59
+ <% if attr.is_a?(Hash) %>
60
+ <% if attr[attr.keys.first][:type].to_s == 'image' %>
61
+ <td class="text-center <%= attr.to_s.parameterize.underscore.downcase %>">
62
+ <% if m.send(attr.keys.first).present? %>
63
+ <img src="<%= m.send(attr.keys.first) %>" class="img-fluid"/>
64
+ <% else %>
65
+ <em><%= t('slash_admin.view.no_image') %></em>
66
+ <% end %>
67
+ </td>
64
68
  <% else %>
65
- <em><%= t('slash_admin.view.no_image') %></em>
66
- <% end %>
67
- </td>
68
- <% else %>
69
- <td>
70
- <%= render attr.keys.first.to_s, model: m %>
71
- </td>
72
- <% end %>
73
- <% else %>
74
- <% if m.send(attr).is_a?(TrueClass) || m.send(attr).is_a?(FalseClass) %>
75
- <td class="text-center">
76
- <span class="tag tag-<%= m.send(attr) ? 'sucess' : 'danger' %> tag-boolean"><%= m.send(attr) ? 'Oui' : 'Non' %></span>
77
- </td>
78
- <% elsif @belongs_to_fields.include?(attr) || @has_one_fields.include?(attr) %>
79
- <td>
80
- <%= link_to(edit_polymorphic_url([:slash_admin, m.send(attr)]), class: 'link', target: '_blank') do %>
69
+ <td class="<%= attr.to_s.parameterize.underscore.downcase %>"><%= render attr.keys.first.to_s, model: m %></td>
70
+ <% end %>
71
+ <% else %>
72
+ <% if m.send(attr).is_a?(TrueClass) || m.send(attr).is_a?(FalseClass) %>
73
+ <td class="text-center <%= attr.to_s.underscore.downcase %>">
74
+ <span class="tag tag-<%= m.send(attr) ? 'sucess' : 'danger' %> tag-boolean"><%= m.send(attr) ? 'Oui' : 'Non' %></span>
75
+ </td>
76
+ <% elsif @belongs_to_fields.include?(attr) || @has_one_fields.include?(attr) %>
77
+ <td class="<%= attr.to_s.underscore.downcase %>">
78
+ <%= link_to(edit_polymorphic_url([:slash_admin, m.send(attr)]), class: 'link', target: '_blank') do %>
81
79
  <%= show_object(m.send(attr)) %>
82
- <% end rescue nil %>
83
- </td>
84
- <% elsif @has_many_fields.include?(attr) %>
85
- <td>
86
- <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modal-see-assoc-<%= attr.to_s %>-<%= m.id %>">
87
- <i class="fa fa-list"></i> <%= t('slash_admin.view.see') %>
88
- </button>
89
- <div class="modal fade" id="modal-see-assoc-<%= attr.to_s %>-<%= m.id %>" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
90
- <div class="modal-dialog" role="document">
91
- <div class="modal-content">
92
- <div class="modal-header">
93
- <h5 class="modal-title" id="exampleModalLabel"><%= t('slash_admin.view.associations') %></h5>
94
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
95
- <span aria-hidden="true">&times;</span>
96
- </button>
97
- </div>
98
- <div class="modal-body">
99
- <% if m.send(attr).length == 0 %>
100
- <%= t('slash_admin.view.no_associations') %>
101
- <% else %>
102
- <% m.send(attr).each do |a| %>
103
- <%= link_to(edit_polymorphic_url([:slash_admin, a]), class: 'link', target: '_blank') do %>
104
- <%= show_object(a) %><br />
105
- <% end rescue nil %>
80
+ <% end rescue show_object(m.send(attr)) %>
81
+ </td>
82
+ <% elsif @has_many_fields.include?(attr) %>
83
+ <td class="<%= attr.to_s.parameterize.underscore.downcase %>">
84
+ <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modal-see-assoc-<%= attr.to_s %>-<%= m.id %>">
85
+ <i class="fa fa-list"></i> <%= t('slash_admin.view.see') %>
86
+ </button>
87
+ <div class="modal fade" id="modal-see-assoc-<%= attr.to_s %>-<%= m.id %>" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
88
+ <div class="modal-dialog" role="document">
89
+ <div class="modal-content">
90
+ <div class="modal-header">
91
+ <h5 class="modal-title" id="exampleModalLabel"><%= t('slash_admin.view.associations') %> <strong>(<%= m.send(attr).length %>)</strong></h5>
92
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
93
+ <span aria-hidden="true">&times;</span>
94
+ </button>
95
+ </div>
96
+ <div class="modal-body">
97
+ <% if m.send(attr).length == 0 %>
98
+ <%= t('slash_admin.view.no_associations') %>
99
+ <% else %>
100
+ <% m.send(attr).each do |a| %>
101
+ <%= link_to(edit_polymorphic_url([:slash_admin, a]), class: 'link', target: '_blank') do %>
102
+ <%= show_object(a) %><br />
103
+ <% end rescue show_object(a) %>
104
+ <% end %>
106
105
  <% end %>
107
- <% end %>
108
- </div>
109
- <div class="modal-footer">
110
- <button type="button" class="btn btn-secondary" data-dismiss="modal"><%= t('slash_admin.view.close') %></button>
106
+ </div>
107
+ <div class="modal-footer">
108
+ <button type="button" class="btn btn-secondary" data-dismiss="modal"><%= t('slash_admin.view.close') %></button>
109
+ </div>
111
110
  </div>
112
111
  </div>
113
112
  </div>
114
- </div>
115
- </td>
116
- <% else %>
117
- <td>
118
- <%= m.send(attr) %>
119
- </td>
113
+ </td>
114
+ <% else %>
115
+ <td class="<%= attr.to_s.parameterize.underscore.downcase %>"><%= m.send(attr) %></td>
116
+ <% end %>
120
117
  <% end %>
121
118
  <% end %>
122
- <% end %>
123
- <td class="actions fit">
124
- <div class="btn-group">
125
- <% if can? :show, @model_class %>
126
- <%= link_to(polymorphic_url([:slash_admin, m]), class: 'btn btn-primary btn-sm') do %>
127
- <i class="icon-magnifier"></i>
128
- <% end rescue nil %>
129
- <% end %>
130
- <% if can? :edit, @model_class %>
131
- <%= link_to(edit_polymorphic_url([:slash_admin, m]), class: 'btn btn-warning btn-sm') do %>
132
- <i class="icon-note"></i>
133
- <% end rescue nil %>
134
- <% end %>
135
- <% if can? :destroy, @model_class %>
136
- <%= link_to(polymorphic_url([:slash_admin, m]), class: 'single-delete btn btn-danger btn-sm') do %>
137
- <i class="icon-trash"></i>
138
- <% end rescue nil %>
139
- <% end %>
140
- </div>
141
- </td>
142
- </tr>
143
- <% end %>
144
- </tbody>
145
- </table>
119
+ <td class="actions fit">
120
+ <div class="btn-group">
121
+ <% if can? :show, @model_class %>
122
+ <%= link_to(polymorphic_url([:slash_admin, m]), class: 'btn btn-info btn-sm') do %>
123
+ <i class="icon-magnifier"></i>
124
+ <% end rescue nil %>
125
+ <% end %>
126
+ <% if can? :edit, @model_class %>
127
+ <%= link_to(edit_polymorphic_url([:slash_admin, m]), class: 'btn btn-warning btn-sm') do %>
128
+ <i class="icon-note"></i>
129
+ <% end rescue nil %>
130
+ <% end %>
131
+ <% if can? :destroy, @model_class %>
132
+ <%= link_to(polymorphic_url([:slash_admin, m]), class: 'single-delete btn btn-danger btn-sm') do %>
133
+ <i class="icon-trash"></i>
134
+ <% end rescue nil %>
135
+ <% end %>
136
+ </div>
137
+ </td>
138
+ </tr>
139
+ <% end %>
140
+ </tbody>
141
+ </table>
142
+ </div>
146
143
  <% end %>
147
144
 
148
145
  <%= render 'slash_admin/shared/better_paginate' %>
@@ -195,7 +192,7 @@
195
192
  var a = [];
196
193
  var k = e.which;
197
194
  var val = $(this).val();
198
-
195
+
199
196
  // Allow Backspace
200
197
  a.push(8);
201
198
 
@@ -13,13 +13,13 @@
13
13
 
14
14
  <br />
15
15
 
16
- <%= form_tag('', method: 'post') do %>
16
+ <%= form_tag(nil, method: 'post') do %>
17
17
  <%= hidden_field(:nestable, :data) %>
18
18
 
19
19
  <%= button_tag(type: 'submit', class: 'btn btn btn-success', name: 'submit_redirect') do %>
20
20
  <i class="fa fa-save"></i> <i class="icon-action-undo"></i> <%= t('slash_admin.view.save_and_return_html') %>
21
21
  <% end %>
22
- <button type="submit" class="btn btn-primary pull-right">
22
+ <button type="submit" class="btn btn-primary float-right">
23
23
  <i class="fa fa-save"></i> <%= t('slash_admin.view.save') %>
24
24
  </button>
25
25
  <% end %>
@@ -1,5 +1,7 @@
1
1
  <%= form_for [:slash_admin, @model] do |f| %>
2
2
  <%#= render 'slash_admin/shared/debug', params: params %>
3
+ <%= render 'slash_admin/shared/new_form_buttons' %>
4
+ <div class="separator"></div>
3
5
 
4
6
  <%= render 'slash_admin/shared/errors_data_new' %>
5
7
 
@@ -10,7 +12,8 @@
10
12
 
11
13
  <%= render 'slash_admin/base/translatable_fields', f: f %>
12
14
 
13
- <%= render 'slash_admin/shared/new_form_buttons' %>
15
+ <div class="separator"></div>
16
+ <%= render'slash_admin/shared/new_form_buttons' %>
14
17
  <% end %>
15
18
 
16
19
  <div class="modal-belongs-to modal"></div>
@@ -1,60 +1,68 @@
1
- <tr role="row" class="filters">
2
- <td>&nbsp;</td>
3
- <td class="fit">
4
- <input type="text" name="filters[id]" value="<%= params[:filters]['id'] rescue nil %>" class="form-control form-control-sm fix-id-search"/>
5
- </td>
6
- <% list_params.each do |attr| %>
7
- <% if !attr.is_a?(Hash) && sortable?(model, attr) %>
8
- <td>
9
- <% case guess_field_type(model, attr)
10
- when 'string', 'text' %>
11
- <input type="text" name="filters[<%= attr %>]" value="<%= params[:filters][attr] rescue nil %>" class="form-control form-control-sm"/>
12
- <% when 'integer', 'number', 'decimal' %>
13
- <input type="text" name="filters[<%= attr %>][from]" value="<%= params[:filters][attr]['from'] rescue nil %>" class="form-control form-control-sm" placeholder="De"/>
14
- <input type="text" name="filters[<%= attr %>][to]" value="<%= params[:filters][attr]['to'] rescue nil %>" class="form-control form-control-sm" placeholder="À"/>
15
- <% when 'date', 'datetime' %>
16
- <div class="input-group">
17
- <input type="text" name="filters[<%= attr %>][from]" value="<%= params[:filters][attr]['from'] rescue nil %>" class="form-control form-control-sm bootstrap-datepicker" placeholder="Du"/>
18
- <span class="input-group-addon"><i class="icon-calendar"></i></span>
19
- </div>
20
- <div class="input-group">
21
- <input type="text" name="filters[<%= attr %>][to]" value="<%= params[:filters][attr]['to'] rescue nil %>" class="form-control form-control-sm bootstrap-datepicker" placeholder="Au"/>
22
- <span class="input-group-addon"><i class="icon-calendar"></i></span>
23
- </div>
24
- <% when 'boolean' %>
25
- <select name="filters[<%= attr %>]" class="form-control form-control-sm">
26
- <option value="" <%= params[:filters][attr] == '' ? 'selected' : nil rescue nil %>></option>
27
- <option value="true" <%= params[:filters][attr] == 'true' ? 'selected' : nil rescue nil %>>Oui</option>
28
- <option value="false" <%= params[:filters][attr] == 'false' ? 'selected' : nil rescue nil %>>Non</option>
29
- </select>
30
- <% end %>
31
- </td>
32
- <% elsif @belongs_to_fields.include?(attr) || @has_one_fields.include?(attr) %>
33
- <% if "SlashAdmin::Models::#{attr.to_s.classify.pluralize}Controller".constantize.new.autocomplete_params.present? %>
1
+ <div data-turbolinks="false">
2
+ <tr role="row" class="filters">
3
+ <td>&nbsp;</td>
4
+ <td class="fit">
5
+ <input type="text" name="filters[id]" value="<%= params[:filters]['id'] rescue nil %>" class="form-control form-control-sm fix-id-search"/>
6
+ </td>
7
+ <% list_params.each do |attr| %>
8
+ <% if !attr.is_a?(Hash) && sortable?(model, attr) %>
34
9
  <td>
35
- <select name="filters[<%= attr %>][]" class="selectize-model-multiple" multiple data-model="<%= attr.to_s.classify.constantize.model_name.to_s.underscore %>" data-fields='<%= "SlashAdmin::Models::#{attr.to_s.classify.pluralize}Controller".constantize.new.autocomplete_params.join(' ') %>' placeholder="<%= t('slash_admin.view.select_model', model_name: attr.to_s.classify.constantize.model_name.human.downcase) %>">
36
- <% attr.to_s.classify.constantize.all.limit(20).each do |model_row| %>
37
- <% if params[:filter].present? %>
38
- <% if params[:filters][attr]&.include? model_row.id.to_s %>
39
- <option value="<%= model_row.id %>" selected><%= show_object(model_row) %></option>
40
- <% else %>
41
- <option value="<%= model_row.id %>"><%= show_object(model_row) %></option>
10
+ <% case guess_field_type(model, attr)
11
+ when 'string', 'text' %>
12
+ <input type="text" name="filters[<%= attr %>]" value="<%= params[:filters][attr] rescue nil %>" class="form-control form-control-sm"/>
13
+ <% when 'integer', 'number', 'decimal' %>
14
+ <input type="text" name="filters[<%= attr %>][from]" value="<%= params[:filters][attr]['from'] rescue nil %>" class="form-control form-control-sm" placeholder="De"/>
15
+ <input type="text" name="filters[<%= attr %>][to]" value="<%= params[:filters][attr]['to'] rescue nil %>" class="form-control form-control-sm" placeholder="À"/>
16
+ <% when 'date', 'datetime' %>
17
+ <div class="input-group">
18
+ <input type="text" name="filters[<%= attr %>][from]" value="<%= params[:filters][attr]['from'] rescue nil %>" class="form-control form-control-sm bootstrap-datepicker" placeholder="Du"/>
19
+ <span class="input-group-prepend"><i class="icon-calendar"></i></span>
20
+ </div>
21
+ <div class="input-group">
22
+ <input type="text" name="filters[<%= attr %>][to]" value="<%= params[:filters][attr]['to'] rescue nil %>" class="form-control form-control-sm bootstrap-datepicker" placeholder="Au"/>
23
+ <span class="input-group-prepend"><i class="icon-calendar"></i></span>
24
+ </div>
25
+ <% when 'boolean' %>
26
+ <select name="filters[<%= attr %>]" class="form-control form-control-sm">
27
+ <option value="" <%= params[:filters][attr] == '' ? 'selected' : nil rescue nil %>></option>
28
+ <option value="true" <%= params[:filters][attr] == 'true' ? 'selected' : nil rescue nil %>>Oui</option>
29
+ <option value="false" <%= params[:filters][attr] == 'false' ? 'selected' : nil rescue nil %>>Non</option>
30
+ </select>
31
+ <% end %>
32
+ </td>
33
+ <% elsif @belongs_to_fields.include?(attr) || @has_one_fields.include?(attr) %>
34
+ <% if "SlashAdmin::Models::#{attr.to_s.classify.pluralize}Controller".constantize.new.autocomplete_params.present? %>
35
+ <td>
36
+ <select name="filters[<%= attr %>][]" class="selectize-model-multiple" multiple data-model="<%= attr.to_s.classify.constantize.model_name.to_s.underscore %>" data-fields='<%= "SlashAdmin::Models::#{attr.to_s.classify.pluralize}Controller".constantize.new.autocomplete_params.join(' ') %>' placeholder="<%= t('slash_admin.view.select_model', model_name: attr.to_s.classify.constantize.model_name.human.downcase) %>">
37
+ <% if params[:filters].present? && params[:filters][attr].present? %>
38
+ <% params[:filters][attr].each do |value| %>
39
+ <option value="<%= value %>" selected><%= attr.to_s.classify.constantize.find(value).name %></option>
42
40
  <% end %>
43
41
  <% else %>
44
- <option value="<%= model_row.id %>"><%= show_object(model_row) %></option>
42
+ <% attr.to_s.classify.constantize.all.limit(20).each do |model_row| %>
43
+ <% if params[:filter].present? %>
44
+ <% if params[:filters][attr]&.include? model_row.id.to_s %>
45
+ <option value="<%= model_row.id %>" selected><%= show_object(model_row) %></option>
46
+ <% else %>
47
+ <option value="<%= model_row.id %>"><%= show_object(model_row) %></option>
48
+ <% end %>
49
+ <% else %>
50
+ <option value="<%= model_row.id %>"><%= show_object(model_row) %></option>
51
+ <% end %>
52
+ <% end %>
45
53
  <% end %>
46
- <% end %>
47
- </select>
48
- </td>
49
- <% else %>
50
- <td>&nbsp;</td>
51
- <% end %>
52
- <% else %>
53
- <td>&nbsp;</td>
54
+ </select>
55
+ </td>
56
+ <% else %>
57
+ <td>&nbsp;</td>
58
+ <% end %>
59
+ <% else %>
60
+ <td>&nbsp;</td>
61
+ <% end %>
54
62
  <% end %>
55
- <% end %>
56
- <td>
57
- <button type="submit" class="btn btn-sm btn-block btn-primary"><i class='fa fa-filter'></i> <%= t('slash_admin.view.filter') %></button>
58
- <button id="reset-filters" class="btn btn-sm btn-block btn-secondary"><i class='fa fa-times'></i> <%= t('slash_admin.view.reset') %></button>
59
- </td>
60
- </tr>
63
+ <td>
64
+ <button type="submit" class="btn btn-sm btn-block btn-primary no-break"><i class='fa fa-filter'></i> <%= t('slash_admin.view.filter') %></button>
65
+ <button id="reset-filters" class="btn btn-sm btn-block btn-secondary no-break"><i class='fa fa-times'></i> <%= t('slash_admin.view.reset') %></button>
66
+ </td>
67
+ </tr>
68
+ </div>