five-two-nw-olivander 0.1.2.48 → 0.1.2.50

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: ec4a9fc8c9018030d6702854ee743538d76826f3b5d4c334e8b47f399281ad0e
4
- data.tar.gz: 7226f507c8129d6a28af91b86e371ae5b6fd68dd866bf406a8c9b088d90020c4
3
+ metadata.gz: 813bb7ec43d77ce06d78481a6fd41a8ceef88fff67dc898464dd8c2ab6f3486e
4
+ data.tar.gz: 054c82737ee7e9c01e86c016f1caca362d11e665eb4a5628fc09a4d27aa2c34b
5
5
  SHA512:
6
- metadata.gz: deee0c4028fec2dc2d1a277a1b470716799ebe36b63a342eaafcb78ce813e1ff6dfa7c11f128106360654d49fa57653932673ab0dc6de6471885ed0db3686e19
7
- data.tar.gz: e3f95336c8dde7c3d060e592410a53dff9e918f12827d417ce62d19a2b5bf5fbeb5f7d5fefc1da193d4cee90a22f2a773045450ec169583c6d959cc504b5ef2f
6
+ metadata.gz: 45b11c5971c38f84ed31f247e7c407ffd2df32a58be4e302ca4a5c8756ee4fd0e7c6648b5209a4e788c43322fa8d095d1133e2046f9961efc3f94e2d8f701c13
7
+ data.tar.gz: cfafb658d561858e330495178079e58c5e76a787c5d145ea0854ca2131eb10b1312ab2109bd5a004109d5c4a4a9ee976b832be672873b19e7f6dea0051c82ed6
@@ -7,5 +7,7 @@
7
7
  - case field.type
8
8
  - when :association
9
9
  = @f.association field.sym, disabled: !field.editable, input_html: { data: { controller: "input-control-#{field.type}" } }
10
+ - when :boolean
11
+ = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { data: { controller: "input-control-#{field.type}" } }, wrapper: :checkbox
10
12
  - else
11
13
  = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { data: { controller: "input-control-#{field.type}" } }
@@ -16,6 +16,8 @@
16
16
  %td{ colspan: colspan }
17
17
  - val = @resource.send(f.sym)
18
18
  - case f.type
19
+ - when :integer, :float
20
+ = val
19
21
  - when :string, :text
20
22
  = simple_format(val)
21
23
  - when :boolean
@@ -43,7 +43,14 @@ module Olivander
43
43
  auto_resource_fields(columns: columns, only: only)
44
44
  end
45
45
  else
46
- only = self.columns.collect{ |x| x.name.to_sym } - SKIPPED_ATTRIBUTES if only.size.zero?
46
+ if only.size.zero?
47
+ only = [
48
+ self.columns.collect{ |x| x.name.to_sym },
49
+ reflections.map{ |r| r[1].name },
50
+ ]
51
+ only << attachment_definitions.select{ |x| x[0] } if respond_to?(:attachment_definitions)
52
+ only = only.flatten - SKIPPED_ATTRIBUTES
53
+ end
47
54
  only.each do |inc|
48
55
  self.columns.each do |att|
49
56
  sym = att.name.to_sym
@@ -63,7 +70,7 @@ module Olivander
63
70
 
64
71
  next unless respond_to?(:attachment_definitions)
65
72
 
66
- attachment_definitions.filter{ |x| puts x; puts inc; x == inc }.each do |ad|
73
+ attachment_definitions.filter{ |x| x == inc }.each do |ad|
67
74
  resource_field ad[0], :file
68
75
  end
69
76
  end
@@ -18,14 +18,19 @@ module Olivander
18
18
  def self.auto_datatable(klazz, collection: nil, link_path: nil, only: [], except: [], hide: [], show: [], order_by: [], scopes: [])
19
19
  Rails.logger.debug "initializing datatable for #{klazz}"
20
20
 
21
- klazz_attributes = klazz.new.attributes.collect{ |x| x[0] }
21
+ instance = klazz.new
22
+ klazz_attributes = instance.attributes.collect{ |x| x[0] }
22
23
  column_attributes = klazz_attributes
23
24
  column_attributes &&= only if only.size.positive?
24
25
  column_attributes -= except if except.size.positive?
25
26
  resources_sym = klazz.table_name.to_sym
26
27
  bulk_action_list = self::ROUTE_BUILDER.resources[resources_sym]&.datatable_bulk_actions || []
27
28
 
28
- default_hidden = %w[id created updated created_at updated_at deleted_at current_user current_action]
29
+ default_hidden = %w[
30
+ id created updated created_at updated_at
31
+ deleted_at current_user current_action
32
+ application_tenant_id created_by_id updated_by_id
33
+ ]
29
34
 
30
35
  filters do
31
36
  scopes.each do |s|
@@ -60,6 +65,8 @@ module Olivander
60
65
  Rails.logger.debug "bulk actions size: #{datatable._bulk_actions.size}"
61
66
  Rails.logger.debug "bulk actions size: #{datatable._bulk_actions.size.positive?}"
62
67
  # bulk_actions_col if datatable._bulk_actions.size.positive?
68
+
69
+ #TODO: use columns from model here instead of attributes keys
63
70
  column_attributes.each do |key|
64
71
  label = field_label_for(klazz, key)
65
72
  sym = key.gsub('_id', '')
@@ -68,6 +75,12 @@ module Olivander
68
75
  col sym, visible: visible, action: :show
69
76
  elsif sym.include?('.')
70
77
  col sym, visible: visible, label: label
78
+ elsif klazz.columns.select{ |x| x.name == key }.first&.type == :boolean
79
+ col sym, visible: visible, label: label do |c|
80
+ val = c.send(sym)
81
+ icon_class = val ? 'fa-check text-success' : 'fa-times text-danger'
82
+ "<div class='text-center'><i class='fa fa-icon #{icon_class}'></div>".html_safe
83
+ end
71
84
  else
72
85
  col sym, visible: visible, label: label
73
86
  end
@@ -25,10 +25,16 @@ module Olivander
25
25
  routed_resource = route_builder.resources[plural_name.to_sym]
26
26
  return [] if routed_resource.nil?
27
27
 
28
- actions = resource.is_a?(Class) ?
29
- (routed_resource.unpersisted_crud_actions | routed_resource.collection_actions.select{ |x| !x.crud_action }) :
30
- (resource.persisted? ? (routed_resource.persisted_crud_actions | routed_resource.member_actions.select{ |x| !x.crud_action }): [])
31
- actions = actions.reject{ |a| a.sym == for_action || !EffectiveDatatables.authorization_method.call(controller, a.sym, resource) }
28
+ actions = if resource.is_a?(Class)
29
+ routed_resource.unpersisted_crud_actions | routed_resource.collection_actions.reject(&:crud_action)
30
+ else
31
+ if resource.persisted?
32
+ routed_resource.persisted_crud_actions | routed_resource.member_actions.reject(&:crud_action)
33
+ else
34
+ []
35
+ end
36
+ end
37
+ actions = actions.select{ |a| authorized_resource_action?(a.sym, resource, for_action) }
32
38
  preferred = %i[show edit destroy]
33
39
  [].tap do |arr|
34
40
  preferred.each do |p|
@@ -42,6 +48,12 @@ module Olivander
42
48
  end
43
49
  end
44
50
 
51
+ def authorized_resource_action?(action, resource, except = nil)
52
+ return false if action == except
53
+
54
+ respond_to?('can?') ? can?(action, resource) : true
55
+ end
56
+
45
57
  def resource_form_actions(route_builder, resource, for_action: :show)
46
58
  render partial: 'resource_form_actions', locals: { actions: authorized_resource_actions(route_builder, resource, for_action: for_action).select(&:show_in_form) }
47
59
  end
@@ -82,13 +94,12 @@ module Olivander
82
94
  resource.auto_form_attributes
83
95
  end
84
96
 
85
- def render_optional_partial partial
86
- begin
87
- render partial: partial
88
- rescue ActionView::MissingTemplate
89
- Rails.logger.debug "did not find partial: #{partial}"
90
- nil
91
- end
97
+ def render_optional_partial(partial, locals: {})
98
+ render partial: partial, locals: locals
99
+
100
+ rescue ActionView::MissingTemplate
101
+ Rails.logger.debug "did not find partial: #{partial}"
102
+ nil
92
103
  end
93
104
 
94
105
  def field_label_for(resource_class, sym)
@@ -1,16 +1,16 @@
1
- - read_only = !%w[edit new].include?(action_name)
1
+ - read_only = !%w[new create edit update].include?(action_name)
2
2
  = simple_form_for(@resource) do |f|
3
3
  .card.card-primary
4
4
  .card-header
5
- %h3.card-title= @resource
5
+ %h3.card-title= @resource.to_s.blank? ? @resource.model_name.human : @resource
6
6
  .card-tools
7
7
  = resource_form_actions(@context.route_builder, @resource, for_action: action_name.to_sym)
8
8
  .card-body
9
9
  =f.error_notification
10
10
  =f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present?
11
- = render_optional_partial 'form_inside_before'
11
+ = render_optional_partial 'form_inside_before', locals: {f: f}
12
12
  = render Olivander::Components::ResourceFormComponent.new(@resource, f)
13
- = render_optional_partial 'form_inside_after'
13
+ = render_optional_partial 'form_inside_after', locals: {f: f}
14
14
  .card-footer.text-right
15
15
  = link_to 'Cancel', @_effective_resource.action_path(:index), class: 'btn btn-secondary'
16
16
  - unless read_only
@@ -23,9 +23,11 @@
23
23
  :javascript
24
24
  $(document).ready(function(){
25
25
  function getUrl() {
26
- const reg = /\/new|\/[0-9]+[\/edit]*/,
27
- url = "" + window.location;
28
- return url.replace(reg, '');
26
+ const locationUrl = new URL(window.location),
27
+ reg = /\/new|\/[0-9]+[\/edit]*/;
28
+
29
+ locationUrl.pathname = locationUrl.pathname.replace(reg, '')
30
+ return locationUrl.href;
29
31
  }
30
32
  const url = getUrl();
31
33
 
@@ -1,3 +1,3 @@
1
1
  module Olivander
2
- VERSION = '0.1.2.48'.freeze
2
+ VERSION = '0.1.2.50'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: five-two-nw-olivander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.48
4
+ version: 0.1.2.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-25 00:00:00.000000000 Z
11
+ date: 2024-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick