zutils 0.4.4 → 0.4.5

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: df6c3780c457eeaa243e2ad25e0b3f353fc8e9901bcef670cbda4fb446cda471
4
- data.tar.gz: afcf7a3976c562678cbced427916b0ffe22b536c8a205bf6e161b8b29997dd75
3
+ metadata.gz: e1e2951ef16b864b5c89d7e59c3218cb039d1a2a346e0beb06a86e8af897fa2b
4
+ data.tar.gz: 504f657bb23981540599fa840021a0b7d051306f425728b21948dba1fdac8f1e
5
5
  SHA512:
6
- metadata.gz: f392ba6d0989f76f4fbcc34920d3f446d7f233965845118df10931431ddfc9a3334b3940b7971a80d100722e5c5a48aae408c74daf984ccb71dda25d421b9048
7
- data.tar.gz: 3a58ed27dadb041688132507c7d42455b76b50b7a34f874b132df1c17e96005c2e578c5446f6a3c89e4311be88a272f5a1cea245d95a33ef62fb9f48cfee1493
6
+ metadata.gz: e6c01ff42e72d2f2c5a6324848397133153024852c8505e1b23e0a148fdb0d982306f9f918ae15fec1ee60d6ed8386b8f252896cfb456a4cf66fcbfed7034701
7
+ data.tar.gz: 78a06d0e450914380028662375e453f5fd59a41885683077d8940377409225c8f1f8ecf9e1f7615e666feea9683d125720053c5fdbc9aa7f967fb81ca4902ae1
@@ -1,22 +1,27 @@
1
1
  <% excluded_columns ||= [] %>
2
+ <% additional_columns ||= [] %>
3
+ <% show_columns ||= [] %>
4
+
2
5
  <% nested_resource ||= false %>
3
6
  <% relationships ||= {} %>
4
7
  <% box_class ||= 'primary' %>
5
- <% display_mode ||= 'table' %>
6
8
  <% hide_links ||= false %>
9
+ <% show_actions ||= ['new', 'edit', 'index'] %>
7
10
  <% hide_header ||= false %>
8
11
  <% hide_table_header ||= false %>
9
- <% additional_columns ||= [] %>
10
12
 
11
- <% form_fields ||= (object.class.respond_to?('form_fields') ? object.class.form_fields : {}) %>
12
- <% form_ordered_fields ||= (form_fields.empty? ? object.class.column_names : form_fields.keys) %>
13
+ <% if show_columns.empty? %>
14
+ <% form_fields ||= (object.class.respond_to?('form_fields') ? object.class.form_fields : {}) %>
15
+ <% form_ordered_fields ||= (form_fields.empty? ? object.class.column_names : form_fields.keys) %>
16
+ <% show_columns = form_ordered_fields - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns + additional_columns %>
17
+ <% end %>
13
18
 
14
19
  <div class="box box-<%= box_class %>">
15
20
  <% unless hide_header %>
16
21
  <div class="box-header with-border">
17
22
  <h3 class="box-title"><%= object.class.model_name.human %></h3>
18
23
  <% unless hide_links %>
19
- <% if can? :new, object.class %> <!--verificando se o usuario esta logado-->
24
+ <% if show_actions.include?('new') && can?(:new, object.class) %>
20
25
  <% if nested_resource %>
21
26
  <%= link_to eval_with_rescue("new_#{parent_resource.class.model_name.singular}_#{object.class.model_name.singular}_path(#{parent_resource.id})"), class: "btn btn-#{box_class} btn-xs", data: { toggle: 'tooltip', placement: 'top', title: 'Cadastrar' } do %>
22
27
  Cadastrar <i class="fa fa-plus"></i>
@@ -27,94 +32,74 @@
27
32
  <% end %>
28
33
  <% end %>
29
34
  <% end %>
30
- <% if can? :edit, object %> <!--verificando se o usuario esta logado-->
35
+ <% if show_actions.include?('edit') && can?(:edit, object) %>
31
36
  <%= 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 %>
32
37
  Editar <i class="fa fa-pencil"></i>
33
38
  <% end %>
34
39
  <% end %>
35
- <% if nested_resource %>
36
- <%= link_to 'Listagem', eval_with_rescue("#{parent_resource.class.model_name.singular}_#{object.class.model_name.plural}_path(#{parent_resource.id})"), class: "btn btn-default btn-xs" %>
37
- <% else %>
38
- <%= link_to 'Listagem', eval_with_rescue("#{object.class.model_name.plural}_path"), class: "btn btn-default btn-xs" %>
40
+ <% if show_actions.include?('index') %>
41
+ <% if nested_resource %>
42
+ <%= link_to 'Listagem', eval_with_rescue("#{parent_resource.class.model_name.singular}_#{object.class.model_name.plural}_path(#{parent_resource.id})"), class: "btn btn-default btn-xs" %>
43
+ <% else %>
44
+ <%= link_to 'Listagem', eval_with_rescue("#{object.class.model_name.plural}_path"), class: "btn btn-default btn-xs" %>
45
+ <% end %>
39
46
  <% end %>
40
47
  <% end %>
48
+ <% if block_given? %>
49
+ <%= yield %>
50
+ <% end %>
41
51
  </div>
42
52
  <% end %>
43
- <div class="box-body <%= 'no-padding' if display_mode == 'table' %>">
44
- <% if display_mode == 'dt' %>
45
- <div class="row">
46
- <dl>
47
- <% (form_ordered_fields - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns + additional_columns).each do |column| %>
48
- <% wphtml = "col-md-#{(form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:size] : form_fields[column.to_sym] ) || 12}" %>
49
- <% icon = (form_fields[column.to_sym].class == Hash ? (form_fields[column.to_sym][:icon].blank? ? 'id-card-o' : form_fields[column.to_sym][:icon]) : 'id-card-o') %>
50
- <div class="<%= wphtml %>">
51
- <dt>
52
- <i class="fa fa-<%= icon %> margin-r-5"></i>
53
- <% if /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
54
- <%= object.class.human_attribute_name(column.split("_id")[0]) %>
55
- <% else %>
56
- <%= object.class.human_attribute_name(column) %>
57
- <% end %>
58
- </dt>
59
- <dd>
60
- <% if object.send(column).class == Date or
61
- object.send(column).class == DateTime or
62
- object.send(column).class == ActiveSupport::TimeWithZone or
63
- object.send(column).class == Time %>
64
- <%=l object.send(column) %>
65
- <% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
66
- <%= object.send(column.split("_id")[0])&.name %>
67
- <% else %>
68
- <%= object.send(column) %>
69
- <% end %>
70
- &nbsp;
71
- </dd>
72
- </div>
73
- <% end %>
74
- </dl>
75
- </div>
76
- <% end %>
77
- <% if display_mode == 'table' %>
78
- <table class="table table-bordered table-striped no-padding datatables">
79
- <% unless hide_table_header %>
80
- <thead>
81
- <tr>
82
- <th width='15%'><%= t('field') %></th>
83
- <th><%= t('value') %></th>
84
- </tr>
85
- </thead>
86
- <% end %>
87
- <% (object.class.column_names - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns + additional_columns).each do |column| %>
88
- <% unless /_currency$/ =~ column %>
89
- <tr>
90
- <th>
91
- <% if /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
92
- <%= object.class.human_attribute_name(column.split("_id")[0]) %>
93
- <% elsif /_cents$/ =~ column %>
94
- <%= object.class.human_attribute_name(column.split("_cents")[0]) %>
95
- <% else %>
96
- <%= object.class.human_attribute_name(column) %>
97
- <% end %>
98
- </th>
99
- <td>
100
- <% if object.send(column).class == Date or
101
- object.send(column).class == DateTime or
102
- object.send(column).class == ActiveSupport::TimeWithZone or
103
- object.send(column).class == Time %>
104
- <%=l object.send(column) %>
105
- <% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
106
- <%= object.send(column.split("_id")[0])&.name %>
107
- <% elsif /_cents$/ =~ column %>
108
- <%= number_to_currency object.send(column.split("_cents")[0]) %>
109
- <% else %>
110
- <%= object.send(column) %>
53
+ <div class="box-body no-padding">
54
+ <table class="table table-bordered table-striped no-padding datatables">
55
+ <% unless hide_table_header %>
56
+ <thead>
57
+ <tr>
58
+ <th width='15%'><%= t('field') %></th>
59
+ <th><%= t('value') %></th>
60
+ </tr>
61
+ </thead>
62
+ <% end %>
63
+ <% show_columns.each do |column| %>
64
+ <% unless /_currency$/ =~ column %>
65
+ <tr>
66
+ <th>
67
+ <% if /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
68
+ <%= object.class.human_attribute_name(column.split("_id")[0]) %>
69
+ <% elsif /_cents$/ =~ column %>
70
+ <%= object.class.human_attribute_name(column.split("_cents")[0]) %>
71
+ <% else %>
72
+ <%= object.class.human_attribute_name(column) %>
73
+ <% end %>
74
+ </th>
75
+ <td>
76
+ <% if column.include?('.') %>
77
+ <% o = object %>
78
+ <% column.split('.').each{|m| o = o.send(m) if o } %>
79
+ <%= o %>
80
+ <% elsif object.send(column).class == Date or
81
+ object.send(column).class == DateTime or
82
+ object.send(column).class == ActiveSupport::TimeWithZone or
83
+ object.send(column).class == Time %>
84
+ <%=l object.send(column) %>
85
+ <% elsif object.send(column).respond_to? 'attached?' %>
86
+ <% if object.send(column).class == ActiveStorage::Attached::One %>
87
+ <%= link_to rails_blob_path(object.send(column)), class: "btn btn-#{box_class} btn-xs", target: '_blank' do %>
88
+ <i class="fa fa-file-o"></i> Arquivo
89
+ <% end %>
111
90
  <% end %>
112
- </td>
113
- </tr>
114
- <% end %>
91
+ <% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
92
+ <%= object.send(column.split("_id")[0])&.name %>
93
+ <% elsif /_cents$/ =~ column %>
94
+ <%= number_to_currency object.send(column.split("_cents")[0]) %>
95
+ <% else %>
96
+ <%= object.send(column) %>
97
+ <% end %>
98
+ </td>
99
+ </tr>
115
100
  <% end %>
116
- </table>
117
- <% end %>
101
+ <% end %>
102
+ </table>
118
103
  </div>
119
104
  </div>
120
105
 
@@ -199,11 +184,21 @@
199
184
  <tr>
200
185
  <% value.each do |v| %>
201
186
  <td>
202
- <% if r.send(v).class == Date or
187
+ <% if v.include?('.') %>
188
+ <% o = r %>
189
+ <% v.split('.').each{|m| o = o.send(m) if o } %>
190
+ <%= o %>
191
+ <% elsif r.send(v).class == Date or
203
192
  r.send(v).class == DateTime or
204
193
  r.send(v).class == ActiveSupport::TimeWithZone or
205
194
  r.send(v).class == Time %>
206
195
  <%=l r.send(v) %>
196
+ <% elsif r.send(v).respond_to? 'attached?' %>
197
+ <% if r.send(v).class == ActiveStorage::Attached::One %>
198
+ <%= link_to rails_blob_path(r.send(v)), class: "btn btn-#{box_class} btn-xs", target: '_blank' do %>
199
+ <i class="fa fa-file-o"></i> Arquivo
200
+ <% end %>
201
+ <% end %>
207
202
  <% elsif /_id$/ =~ v && r.respond_to?(v.split('_id')[0]) %>
208
203
  <%= r.send(v.split("_id")[0])&.name %>
209
204
  <% else %>
@@ -1,3 +1,3 @@
1
1
  module Zutils
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
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: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Viana
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-08 00:00:00.000000000 Z
11
+ date: 2019-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.0.3
102
+ rubygems_version: 3.0.1
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Utilidades gerais para aplicações rails