zutils 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb9fbee3e13adc079053d6032d70630ed0f938e71920d4eda97bf70d02f3782a
4
- data.tar.gz: df73b3dfbb243a58158381b77a162d21e6293df27842525c0b724e6a7fa1e91a
3
+ metadata.gz: 8be8be9b23d0b07e71f9220bd0e9f82307dd0f7773131b3c1311b89c51b7c85b
4
+ data.tar.gz: 7bebbfaa4e9d73d00481114102dbce38a3133c271d973a0609f6682c8a19a9e1
5
5
  SHA512:
6
- metadata.gz: f46bf277afe2a9a1442304f02c8d110fa5f62d52b9a8951bfdb9f713829a190dd06838e5b2d9417117b8b7a07900f08ac91f9ddb42edc59a3a46afc5e8efcee6
7
- data.tar.gz: 1d079455ec44773a71ad0b73ed6f6b34d21d9844c2672de62a090623b5cc3510db34ddc1fb987089cf3f347d4d287ba35fd7ae974de544485af178cb5c8d7d8c
6
+ metadata.gz: 0f4f46044490cd2ed3b086e6e8aaeb69c34cf4ac9aa0fe17c35c94e621164321e6e038385fc0e8c03148892bc0c46d62e60dda3bcadde8156d617a059efe288c
7
+ data.tar.gz: 2530d2dfaf3104c1c27eb2ec5984e899f4cecdc991f4b51f8a84602274c4833ab1f6c65a64dc07ef782648b11c2fa210d3f490afdb01b513712efb159dc17f3b
@@ -0,0 +1,44 @@
1
+ <% exceptions ||= ['created_at', 'updated_at', 'deleted_at'] %>
2
+ <% show_columns ||= [] %>
3
+ <% table_class ||= 'datatables styletable' %>
4
+ <% card_class ||= 'primary' %>
5
+ <% sort_all ||= false %>
6
+ <% show_new &&= true %>
7
+ <% sort_fields ||= [] %>
8
+
9
+ <% hide_actions ||= false %>
10
+
11
+ <% if show_columns.empty? %>
12
+ <% show_columns = list.klass.column_names - exceptions %>
13
+ <% end %>
14
+
15
+ <div class="card card-outline card-<%= card_class %>">
16
+ <div class="card-header with-border">
17
+ <h3 class="card-title">
18
+ <strong>
19
+ <i class="fa fa-list"></i>
20
+ Listagem
21
+ </strong>
22
+ <% if show_new %>
23
+ <%= link_to eval("new_#{list.klass.model_name.singular}_path"), class: "btn btn-xs btn-#{card_class}" do %>
24
+ Cadastar <i class="fa fa-plus"></i>
25
+ <% end %>
26
+ <% end %>
27
+ <div class="text-muted text-xs">
28
+ <%= page_entries_info list, entry_name: '' %>
29
+ </div>
30
+ </h3>
31
+ <div class='card-tools'>
32
+ <%= paginate list, window: 1 %>
33
+ </div>
34
+ </div>
35
+ <div class="card-body p-0">
36
+ <%= render 'shared/list', list: list, show_columns: show_columns, box_class: card_class,
37
+ table_class: table_class, exceptions: exceptions, sort_all: sort_all, sort_fields: sort_fields,
38
+ hide_actions: hide_actions
39
+ %>
40
+ </div>
41
+ <div class="pagination justify-content-center pt-3">
42
+ <%= paginate list %>
43
+ </div>
44
+ </div>
@@ -9,7 +9,7 @@
9
9
  <% additional_actions ||= [] %>
10
10
  <% box_class ||= 'primary' %>
11
11
  <% table_no_padding ||= false %>
12
- <% table_class ||= 'datatables styletable' %>
12
+ <% table_class ||= 'datatables' %>
13
13
 
14
14
  <% hide_links ||= false %>
15
15
  <% hide_actions ||= false %>
@@ -27,24 +27,24 @@
27
27
  <strong>
28
28
  <%= list.klass.model_name.human.pluralize %>
29
29
  </strong>
30
- <% if block_given? %>
31
- <%= yield %>
32
- <% end %>
33
30
  </h3>
31
+ <% if block_given? %>
32
+ <%= yield %>
33
+ <% end %>
34
34
  </div>
35
35
  <% end %>
36
36
  <div class="box-body card-body <%= 'no-padding' if table_no_padding %> <%= 'p-0' if table_no_padding %>">
37
37
  <% unless search_fields.empty? %>
38
- <%= search_form_for @q, url: eval(nested_resource ? "#{parent_resource}_#{controller_name}_path" : "#{controller_name}_path") do |f| %>
39
- <div class="row">
38
+ <div class="row">
39
+ <%= search_form_for @q, url: eval(nested_resource ? "#{parent_resource}_#{controller_name}_path" : "#{controller_name}_path") do |f| %>
40
40
  <% search_fields.each do |sf| %>
41
41
  <%= f.input sf[:field], label: sf[:label], required: false, as: sf[:as], collection: sf[:collection], wrapper_html: { class: 'col-md-3' } %>
42
42
  <% end %>
43
- <div class="col-md-12 mb-3">
43
+ <div class="col-md-3 top-25 ">
44
44
  <%= f.submit "Pesquisar", class: "btn btn-#{box_class}" %>
45
45
  </div>
46
- </div>
47
- <% end %>
46
+ <% end %>
47
+ </div>
48
48
  <% end %>
49
49
  <%= render 'shared/list', list: list, exceptions: exceptions, excluded_columns: excluded_columns,
50
50
  additional_columns: additional_columns, sort_fields: sort_fields, sort_all: sort_all,
@@ -56,10 +56,10 @@
56
56
  <div class='col-md-4'>
57
57
  <%= page_entries_info list, entry_name: 'resultado(s)' %>
58
58
  </div>
59
- <div class='col-md-8 text-right hidden-xs d-none d-sm-block'>
59
+ <div class='col-md-8 text-right hidden-xs'>
60
60
  <%= paginate list, window: 4 %>
61
61
  </div>
62
- <div class='col-md-8 text-center visible-xs d-block d-sm-none'>
62
+ <div class='col-md-8 text-center visible-xs'>
63
63
  <%= paginate list, window: 1 %>
64
64
  </div>
65
65
  <% end %>
@@ -6,7 +6,10 @@
6
6
  <% sort_fields ||= [] %>
7
7
  <% sort_all ||= false %>
8
8
  <% table_class ||= 'datatables styletable' %>
9
+
9
10
  <% box_class ||= 'primary' %>
11
+ <% card_class ||= 'primary' %>
12
+
10
13
  <% show_columns ||= [] %>
11
14
 
12
15
  <% hide_read_action ||= false %>
@@ -17,29 +20,56 @@
17
20
  <% show_columns = list.klass.column_names - exceptions - excluded_columns + additional_columns %>
18
21
  <% end %>
19
22
 
20
- <table class="table table-striped <%= table_class %> table-bordered">
23
+ <table class="table table-striped <%= table_class %>">
21
24
  <thead>
22
25
  <tr>
23
26
  <% show_columns.each do |column| %>
24
- <% if sort_all || sort_fields.include?(column) %>
25
- <% if /_id$/ =~ column %>
26
- <th><%= sort_link(@q, column, list.klass.human_attribute_name(column.split("_id")[0])) %></th>
27
- <% elsif /_cents$/ =~ column %>
28
- <th><%= sort_link(@q, column, list.klass.human_attribute_name(column.split("_cents")[0])) %></th>
29
- <% elsif /_currency$/ =~ column %>
30
- <% else %>
31
- <th><%= sort_link(@q, column, list.klass.human_attribute_name(column)) %></th>
32
- <% end %>
33
- <% else %>
34
- <% if /_id$/ =~ column %>
35
- <th><%= list.klass.human_attribute_name(column.split("_id")[0]) %></th>
36
- <% elsif /_cents$/ =~ column %>
37
- <th><%= list.klass.human_attribute_name(column.split("_cents")[0]) %></th>
38
- <% elsif /_currency$/ =~ column %>
27
+
28
+ <% column_method = nil %>
29
+ <% column_name = column %>
30
+ <% column_align = ''%>
31
+ <% if column.class == Hash %>
32
+ <% column_name = column[:attribute] %>
33
+ <% column_method = column[:method] %>
34
+ <% column_align = column[:align] %>
35
+ <% end %>
36
+
37
+ <% next if /_currency$/ =~ column_name %>
38
+
39
+ <th data-field="<%= column_method || column_name %>" data-align="<%= column_align %>">
40
+ <% if sort_all || sort_fields.include?(column_name) %>
41
+ <% if column_name.include?('.') %>
42
+ <% s_name = column_method || column_name %>
43
+ <%= sort_link(@q, s_name.split('.').join('_'),
44
+ "#{s_name.split('.')[-2]&.camelize} (#{s_name.split('.')[-1]})")
45
+ %>
46
+ <% elsif /_id$/ =~ column_name %>
47
+ <%= sort_link(@q, column_name, list.klass.human_attribute_name(column_name.split("_id")[0])) %>
48
+ <% elsif /_cents$/ =~ column_name %>
49
+ <%= sort_link(@q, column_name, list.klass.human_attribute_name(column_name.split("_cents")[0])) %>
50
+ <% elsif /_currency$/ =~ column_name %>
51
+ <!-- faz nada -->
52
+ <% elsif column_name == 'id' %>
53
+ <%= sort_link(@q, column_name, '#') %>
54
+ <% else %>
55
+ <%= sort_link(@q, column_name, list.klass.human_attribute_name(column_name)) %>
56
+ <% end %>
39
57
  <% else %>
40
- <th><%= list.klass.human_attribute_name(column) %></th>
58
+ <% if column_name.include?('.') %>
59
+ <% s_name = column_method || column_name %>
60
+ <%= "#{s_name.split('.')[-2]&.camelize} (#{s_name.split('.')[-1]})" %>
61
+ <% elsif /_id$/ =~ column_name %>
62
+ <%= list.klass.human_attribute_name(column_name.split("_id")[0]) %>
63
+ <% elsif /_cents$/ =~ column_name %>
64
+ <%= list.klass.human_attribute_name(column_name.split("_cents")[0]) %>
65
+ <% elsif /_currency$/ =~ column_name %>
66
+ <% elsif column_name == 'id' %>
67
+ #
68
+ <% else %>
69
+ <%= list.klass.human_attribute_name(column_name) %>
70
+ <% end %>
41
71
  <% end %>
42
- <% end %>
72
+ </th>
43
73
  <% end %>
44
74
  <% unless hide_actions %>
45
75
  <th>Ações</th>
@@ -48,50 +78,59 @@
48
78
  </thead>
49
79
  <tbody>
50
80
  <% list.each do |object| %>
51
- <tr>
52
- <% show_columns.each do |column| %>
53
- <% next if /_currency$/ =~ column %>
54
- <td>
55
- <% if column.include?('.') %>
56
- <% o = object %>
57
- <% column.split('.').each{|m| o = o.send(m) if o } %>
58
- <%= o %>
59
- <% elsif object.send(column).class == Date or
60
- object.send(column).class == DateTime or
61
- object.send(column).class == ActiveSupport::TimeWithZone or
62
- object.send(column).class == Time %>
63
- <%=l object.send(column) %>
64
- <% elsif object.send(column).respond_to? 'attached?' %>
65
- <% if object.send(column).class == ActiveStorage::Attached::One %>
66
- <% if object.send(column).attached? %>
67
- <%= link_to rails_blob_path(object.send(column)), class: "btn btn-#{box_class} btn-xs", target: '_blank' do %>
68
- <i class="fa fa-file-o"></i> Arquivo
81
+ <tr>
82
+ <% show_columns.each do |column| %>
83
+
84
+ <% column_method = nil %>
85
+ <% column_name = column %>
86
+ <% if column.class == Hash %>
87
+ <% column_name = column[:attribute] %>
88
+ <% column_method = column[:method] %>
89
+ <% end %>
90
+
91
+ <% next if /_currency$/ =~ column_name %>
92
+
93
+ <td>
94
+ <% if column_name.include?('.') %>
95
+ <% o = object %>
96
+ <% column_name.split('.').each{|m| o = o.send(m) if o } %>
97
+ <%= o %>
98
+ <% elsif object.send(column_name).class == Date or
99
+ object.send(column_name).class == DateTime or
100
+ object.send(column_name).class == ActiveSupport::TimeWithZone or
101
+ object.send(column_name).class == Time %>
102
+ <%=l object.send(column_name) %>
103
+ <% elsif object.send(column_name).respond_to? 'attached?' %>
104
+ <% if object.send(column_name).class == ActiveStorage::Attached::One %>
105
+ <% if object.send(column_name).attached? %>
106
+ <%= link_to rails_blob_path(object.send(column_name)), class: "btn btn-#{box_class} #{card_class} btn-xs", target: '_blank' do %>
107
+ <i class="fa fa-file-o"></i> Arquivo
108
+ <% end %>
109
+ <% end %>
69
110
  <% end %>
111
+ <% elsif /_id$/ =~ column_name && object.respond_to?(column_name.split('_id')[0]) %>
112
+ <%= object.send(column_name.split("_id")[0])&.name %>
113
+ <% elsif /_cents$/ =~ column_name %>
114
+ <%= number_to_currency object.send(column_name.split("_cents")[0]) %>
115
+ <% elsif /_currency$/ =~ column_name %>
116
+ <!-- faz nada -->
117
+ <% elsif column_name.include?(".") %>
118
+ <%= eval("object.#{column_name}") %>
119
+ <% elsif column_name == 'id' %>
120
+ <%= link_to object.id, object %>
121
+ <% else %>
122
+ <%= object.send(column_method || column_name) %>
70
123
  <% end %>
71
- <% end %>
72
- <% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
73
- <%= object.send(column.split("_id")[0])&.name %>
74
- <% elsif /_cents$/ =~ column %>
75
- <%= number_to_currency object.send(column.split("_cents")[0]) %>
76
- <% elsif /_currency$/ =~ column %>
77
- <!-- faz nada -->
78
- <% elsif column.include?(".") %>
79
- <%= eval("object.#{column}") %>
80
- <% elsif column == 'id' %>
81
- <%= link_to object.id, object %>
82
- <% else %>
83
- <%= object.send(column) %>
124
+ </td>
84
125
  <% end %>
85
- </td>
86
- <% end %>
87
- <% unless hide_actions %>
88
- <td>
89
- <%= render 'shared/action_links', object: object, additional_actions: additional_actions,
90
- hide_read_action: hide_read_action, hide_edit_action: hide_edit_action, hide_destroy_action: hide_destroy_action
91
- %>
92
- </td>
93
- <% end %>
94
- </tr>
126
+ <% unless hide_actions %>
127
+ <td>
128
+ <%= render 'shared/action_links', object: object, additional_actions: additional_actions,
129
+ hide_read_action: hide_read_action, hide_edit_action: hide_edit_action, hide_destroy_action: hide_destroy_action
130
+ %>
131
+ </td>
132
+ <% end %>
133
+ </tr>
95
134
  <% end %>
96
135
  </tbody>
97
136
  </table>
@@ -35,7 +35,7 @@
35
35
  <% end %>
36
36
  <% if show_actions.include?('edit') && can?(:edit, object) %>
37
37
  <%= link_to eval_with_rescue("edit_#{object.class.model_name.singular}_path(#{object.id})"), class: "btn btn-warning btn-xs", data: { toggle: 'tooltip', placement: 'top', title: 'Editar' } do %>
38
- Editar <i class="fa fa-pencil fa-pen"></i>
38
+ Editar <i class="fa fa-pencil"></i>
39
39
  <% end %>
40
40
  <% end %>
41
41
  <% if show_actions.include?('index') %>
@@ -52,8 +52,8 @@
52
52
  </h3>
53
53
  </div>
54
54
  <% end %>
55
- <div class="box-body card-body p-0 no-padding">
56
- <table class="table table-bordered table-striped datatables styletable">
55
+ <div class="box-body no-padding">
56
+ <table class="table table-bordered table-striped no-padding datatables">
57
57
  <% unless hide_table_header %>
58
58
  <thead>
59
59
  <tr>
@@ -111,14 +111,14 @@
111
111
  <% relationships.each do |key, value| %>
112
112
  <% if object.association(key.to_s).kind_of?(ActiveRecord::Associations::BelongsToAssociation) ||
113
113
  object.association(key.to_s).kind_of?(ActiveRecord::Associations::HasOneAssociation) %>
114
- <div class="box box-<%= box_class %> card card-outline card-<%= box_class %>">
115
- <div class="box-header with-border card-header">
116
- <h3 class="box-title card-title">
114
+ <div class="box box-<%= box_class %>">
115
+ <div class="box-header with-border">
116
+ <h3 class="box-title">
117
117
  <%= Kernel.const_get(key.to_s.singularize.camelize).model_name.human %>
118
118
  </h3>
119
119
  </div>
120
- <div class="box-body card-body p-0 no-padding">
121
- <table class="table table-bordered table-striped datatables styletable">
120
+ <div class="box-body no-padding">
121
+ <table class="table table-bordered table-striped no-padding datatables">
122
122
  <% unless hide_table_header %>
123
123
  <thead>
124
124
  <tr>
@@ -162,14 +162,14 @@
162
162
  </div>
163
163
  </div>
164
164
  <% else %>
165
- <div class="box box-<%= box_class %> card card-outline card-<%= box_class %>">
166
- <div class="box-header with-border card-header">
167
- <h3 class="box-title card-title">
165
+ <div class="box box-<%= box_class %>">
166
+ <div class="box-header with-border">
167
+ <h3 class="box-title">
168
168
  <%= Kernel.const_get(key.to_s.singularize.camelize).model_name.human.pluralize %>
169
169
  </h3>
170
170
  </div>
171
- <div class="box-body no-padding card-body p-0">
172
- <table class="table table-bordered table-striped datatables styletable">
171
+ <div class="box-body no-padding">
172
+ <table class="table table-bordered table-striped no-padding datatables">
173
173
  <thead>
174
174
  <tr>
175
175
  <% value.each do |v| %>
@@ -1,3 +1,3 @@
1
1
  module Zutils
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Viana
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-23 00:00:00.000000000 Z
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -68,6 +68,7 @@ files:
68
68
  - app/assets/javascripts/zutils.js
69
69
  - app/assets/stylesheets/zutils.scss
70
70
  - app/views/shared/_action_links.html.erb
71
+ - app/views/shared/_card_list.html.erb
71
72
  - app/views/shared/_fields.html.erb
72
73
  - app/views/shared/_form.html.erb
73
74
  - app/views/shared/_index.html.erb