five-two-nw-olivander 0.2.0.2 → 0.2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76ede3e2ce50954cf786b9b30fabed5c294bb1b174a78f8493e331be73eb1b14
4
- data.tar.gz: 7f23d18fe4144d9a0ce8829be386033a8e29e116186590d00c66339adbfdbddc
3
+ metadata.gz: 2e9d0ccea420078110d4af7de4d7eec3c0ac04e8a8a2533302d5792a1d599c58
4
+ data.tar.gz: '09b69957d70478ef092e8eff4a979ee867ac74c903fe1572793016d8ab26f531'
5
5
  SHA512:
6
- metadata.gz: 9fffc213421e65a2c263771e6071d7ff4f8ca97b74b2f9bb30eb7be49180cb97da2beda9bebd2b68e7117504a35b8ecfadfa39056ab17950a69d5dc076ba837f
7
- data.tar.gz: 17a316a14e4406b136158ef9100bca6de6249e3ac96eb600dab8983d7f8b6cd21d5a6723e6d2ee3d1715ee4d0529151b82a5948402de517b5af37565f45f6832
6
+ metadata.gz: 07ce6181e19ada53a8d78cf650c8b4cef82ccb4d38b33a09cca9b340d71567d2a4889f613c5986afb85fb6cc32b0b6010999f9af05fe40ab1ff7ff3a45f291e5
7
+ data.tar.gz: 67fbcc49d403734676c0f8d46052585ed70e127878bd6f4490f7d94f104d02aa8bcd7827da5d39957182a4a7b9dcc3947b41e69425189844a34e1812684efe15
@@ -0,0 +1,42 @@
1
+ (function() {
2
+ var destroySelect2s, logEvent;
3
+
4
+ $.extend(true, $.fn.dataTable.Buttons.defaults, {
5
+ dom: {
6
+ button: {
7
+ className: 'btn btn-outline-primary btn-sm'
8
+ }
9
+ }
10
+ });
11
+
12
+ $.extend(true, $.fn.dataTable.ext.classes, {
13
+ sProcessing: "dataTables_processing card overlay-wrapper"
14
+ });
15
+
16
+ destroySelect2s = function() {
17
+ $('.effective-datatables-filters').find('select').select2('destroy');
18
+ return $('.dataTables_wrapper').each(function(_, o) {
19
+ try {
20
+ return $(o).find('.dataTables_length select.select2-hidden-accessible').addClass('no-select2').removeAttr('name').select2('destroy');
21
+ } catch (error) {}
22
+ });
23
+ };
24
+
25
+ logEvent = function(e) {
26
+ return console.log(e);
27
+ };
28
+
29
+ $(document).ready(function(e) {
30
+ return destroySelect2s();
31
+ });
32
+
33
+ // $(document).ready(function(e) {
34
+ // return $('.effective-datatables-filters input').click(function() {
35
+ // var $form, $table;
36
+ // $form = $(event.currentTarget).closest('.effective-datatables-filters');
37
+ // $table = $('#' + $form.attr('aria-controls'));
38
+ // return $table.DataTable().draw();
39
+ // });
40
+ // });
41
+
42
+ }).call(this);
@@ -12,7 +12,11 @@ $.fn.select2.defaults.set('dropdownParent', $('#modal-root'))
12
12
  # TODO: Recheck with the select2 GH issue and remove once this is fixed on their side
13
13
  #
14
14
  $(document).on 'select2:open', (evt) =>
15
- evt.target.parent.querySelector('.select2-search__field').focus()
15
+ try
16
+ evt.target.parent.querySelector('.select2-search__field').focus()
17
+ catch ex
18
+ evt.target.parentElement.querySelector('.select2-search__field').focus()
19
+
16
20
 
17
21
  initSelect2s = () -> $('select').not('.no-select2').each (k,v) =>
18
22
  $(v).select2({ dropdownParent: $(v).parent() })
@@ -21,3 +25,11 @@ initSelect2s = () -> $('select').not('.no-select2').each (k,v) =>
21
25
  $(document).on 'show.bs.modal', (e) =>
22
26
  $('select').not('.no-select2').each (k,v) =>
23
27
  $(v).select2({ dropdownParent: $(v).parent() })
28
+
29
+ $(document).ready =>
30
+ $('.effective-datatables-filters').find('select').select2('destroy');
31
+ $('.dataTables_wrapper').each (_, o) =>
32
+ try
33
+ return $(o).find('.dataTables_length select.select2-hidden-accessible').addClass('no-select2').removeAttr('name').select2('destroy');
34
+ catch error
35
+ # don't care
@@ -19,3 +19,4 @@
19
19
  //= require "adminlte/dist/js/adminlte.js"
20
20
  //= require 'olivander/flash_toast'
21
21
  //= require "effective_datatables"
22
+ //= require "adminlte/datatable.fix.js"
@@ -5,10 +5,19 @@
5
5
  - section.fields.each do |field|
6
6
  %div{ class: section.column_class }
7
7
  - case field.type
8
- - when :association
9
- - controllers = "#{field.type}-#{@resource.class.name.underscore}-#{field.sym} input-control-#{field.type}"
10
- - collection_path = polymorphic_path(@resource.class.reflect_on_association(field.sym).klass, format: :json)
11
- = @f.association field.sym, collection: [@f.object.send(field.sym)].flatten, disabled: !field.editable, input_html: { data: { collection_path: collection_path, controller: controllers } }
8
+ - when :association, :belongs_to_association, :has_many_association, :has_many_through_association, :has_and_belongs_to_many_reflection, :has_one_through_association
9
+ - reflection = @f.object.class.reflect_on_association(field.sym)
10
+ - controllers = "#{field.type}-#{@resource.class.name.underscore.gsub('/', '_')}-#{field.sym} input-control-association"
11
+ - begin
12
+ - collection_path = polymorphic_path(@resource.class.reflect_on_association(field.sym).klass, format: :json)
13
+ - rescue
14
+ - collection_path = ''
15
+ - collection = @f.object.send(field.sym)
16
+ - case field.type
17
+ - when :has_one_through_association
18
+ = @f.input field.sym, selected: collection, collection: [collection].flatten, disabled: !field.editable, input_html: { data: { collection_path: collection_path, controller: controllers } }
19
+ -else
20
+ = @f.association field.sym, collection: [collection].flatten, disabled: !field.editable, input_html: { data: { collection_path: collection_path, controller: controllers } }
12
21
  - when :boolean
13
22
  = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { data: { controller: "input-control-#{field.type}" } }, wrapper: :checkbox
14
23
  - else
@@ -23,14 +23,20 @@
23
23
  - when :boolean
24
24
  - icon_class = val ? 'fa-check text-success' : 'fa-times text-danger'
25
25
  %i.fa{ class: icon_class }
26
- - when :association
26
+ - when :association, :belongs_to_association, :has_many_association, :has_many_through_association, :has_and_belongs_to_many_reflection, :has_one_through_association
27
27
  - if val.present?
28
28
  - if val.is_a?(ActiveRecord::Associations::CollectionProxy)
29
29
  %ul
30
30
  - val.each do |val1|
31
- %li= link_to val1
31
+ - begin
32
+ %li= link_to val1
33
+ - rescue
34
+ %li= val1
32
35
  - else
33
- = link_to val if val.present?
36
+ - begin
37
+ = link_to val if val.present?
38
+ - rescue
39
+ = val if val.present?
34
40
  - when :file
35
41
  - if val.present?
36
42
  - if val.content_type.include?('image')
@@ -38,7 +44,6 @@
38
44
  - else
39
45
  = link_to val, val.expiring_url
40
46
  - else
41
- = f.type
42
47
  = val
43
48
  - (section.columns-slice.size).times do
44
49
  %th
@@ -33,16 +33,16 @@ module Olivander
33
33
  self.resource_field_group_collection
34
34
  end
35
35
 
36
- def self.auto_resource_fields(columns: 2, only: [], editable: true)
36
+ def self.auto_resource_fields(columns: 2, only: [], except: [], editable: true)
37
37
  return unless ActiveRecord::Base.connection.table_exists?(table_name)
38
38
 
39
39
  if current_resource_field_group.nil?
40
40
  resource_field_group do
41
- auto_resource_fields(columns: columns, only: only, editable: editable)
41
+ auto_resource_fields(columns: columns, only: only, except: except, editable: editable)
42
42
  end
43
43
  elsif current_resource_field_group.forced_section.nil?
44
44
  resource_field_section(columns) do
45
- auto_resource_fields(columns: columns, only: only, editable: editable)
45
+ auto_resource_fields(columns: columns, only: only, except: except, editable: editable)
46
46
  end
47
47
  else
48
48
  if only.size.zero?
@@ -53,6 +53,7 @@ module Olivander
53
53
  only << attachment_definitions.select{ |x| x[0] } if respond_to?(:attachment_definitions)
54
54
  only = only.flatten - SKIPPED_ATTRIBUTES
55
55
  end
56
+ only = only - except
56
57
  only.each do |inc|
57
58
  self.columns.each do |att|
58
59
  sym = att.name.to_sym
@@ -65,7 +66,11 @@ module Olivander
65
66
  reflections.map{ |x| x[1] }
66
67
  .filter{ |x| x.foreign_key == inc || x.name == inc }
67
68
  .each do |r|
68
- resource_field r.name, :association, editable: editable
69
+ begin
70
+ resource_field(r.name, r.association_class.name.demodulize.underscore.to_sym, editable: editable)
71
+ rescue NotImplementedError
72
+ resource_field(r.name, :association, editable: editable)
73
+ end
69
74
  end
70
75
 
71
76
  next unless respond_to?(:attachment_definitions)
@@ -8,7 +8,7 @@ module Olivander
8
8
  layout 'olivander/adminlte/main'
9
9
 
10
10
  def index
11
- if params[:term].present?
11
+ if request.format == :json && params[:_type].present? && params[:_type] == 'query'
12
12
  index_search
13
13
  else
14
14
  super
@@ -27,6 +27,7 @@ module Olivander
27
27
  orders = fields.join(', ')
28
28
  self.resources = self.resources.where(clauses).order(orders) if clauses.length.positive?
29
29
  end
30
+ self.resources = self.resources.limit(25)
30
31
  end
31
32
 
32
33
  def permitted_params
@@ -3,12 +3,12 @@ module Olivander
3
3
  class ResourceAction
4
4
  attr_accessor :sym, :action, :verb, :confirm, :turbo_frame, :collection,
5
5
  :controller, :crud_action, :show_in_form, :show_in_datatable,
6
- :no_route, :path_helper, :confirm_with
6
+ :no_route, :path_helper, :confirm_with, :primary
7
7
 
8
8
  def initialize(sym, action: nil, controller: nil, verb: :get, confirm: false,
9
9
  turbo_frame: nil, collection: false, crud_action: false,
10
10
  show_in_form: true, show_in_datatable: true, no_route: false,
11
- path_helper: nil, confirm_with: nil)
11
+ path_helper: nil, confirm_with: nil, primary: nil)
12
12
  self.sym = sym
13
13
  self.action = action || sym
14
14
  self.controller = controller
@@ -22,6 +22,7 @@ module Olivander
22
22
  self.no_route = no_route
23
23
  self.path_helper = path_helper
24
24
  self.confirm_with = confirm_with
25
+ self.primary = primary || crud_action
25
26
  end
26
27
 
27
28
  def args_hash(options = nil)
@@ -131,7 +132,7 @@ module Olivander
131
132
 
132
133
  def action(sym, verb: :get, confirm: false, turbo_frame: nil, collection: false, show_in_datatable: true,
133
134
  show_in_form: true, no_route: false, controller: nil, action: nil, path_helper: nil,
134
- confirm_with: nil
135
+ confirm_with: nil, primary: nil
135
136
  )
136
137
  raise 'Must be invoked in a resource block' unless current_resource.present?
137
138
 
@@ -139,7 +140,7 @@ module Olivander
139
140
  current_resource.actions << ResourceAction.new(
140
141
  sym, action: action, controller: controller, verb: verb, confirm: confirm, turbo_frame: turbo_frame, collection: collection,
141
142
  show_in_datatable: show_in_datatable, show_in_form: show_in_form, no_route: no_route, path_helper: path_helper,
142
- confirm_with: confirm_with
143
+ confirm_with: confirm_with, primary: primary
143
144
  )
144
145
  end
145
146
 
@@ -73,6 +73,14 @@ module Olivander
73
73
  render partial: 'resource_form_actions', locals: { actions: authorized_resource_actions(resource, for_action: for_action).select(&:show_in_form) }
74
74
  end
75
75
 
76
+ def resource_form_action_tooltip(resource, action)
77
+ key = resource.class.name.underscore
78
+ return I18n.t("activerecord.actions.#{key}.#{action}-tooltip") if I18n.exists?("activerecord.actions.#{key}.#{action}-tooltip")
79
+ return I18n.t("activerecord.actions.#{action}-tooltip") if I18n.exists?("activerecord.actions.#{action}-tooltip")
80
+
81
+ action.to_s.titleize
82
+ end
83
+
76
84
  def resource_form_action_label(resource, action)
77
85
  key = resource.class.name.underscore
78
86
  return I18n.t("activerecord.actions.#{key}.#{action}") if I18n.exists?("activerecord.actions.#{key}.#{action}")
@@ -95,7 +103,7 @@ module Olivander
95
103
  end
96
104
 
97
105
  def current_user
98
- Olivander::CurrentContext.user || OpenStruct.new({ display_name: 'No User Set' })
106
+ Olivander::CurrentContext.user
99
107
  end
100
108
 
101
109
  def current_ability
@@ -4,21 +4,27 @@
4
4
  -# - data = a.turbo_frame.present? ? { turbo: true, turbo_frame: a.turbo_frame } : {}
5
5
  -# = dropdown_link_to resource_form_action_label(resource, a.sym), path, data: data
6
6
  - actions = authorized_resource_actions(resource, for_action: action_name).select{ |x| x.show_in_datatable }
7
- - crud_actions = actions.select{ |a| a.crud_action }
8
- - non_crud_actions = actions.select{ |a| !a.crud_action }
7
+ - primary_actions = actions.select{ |a| a.primary }
8
+ - non_primary_actions = actions.select{ |a| !a.primary }
9
9
  .btn-group
10
- - if non_crud_actions.size.positive?
10
+ - if non_primary_actions.size.positive?
11
11
  .btn-group
12
12
  %button.btn.btn-sm.dropdown-toggle{ type: :button, data: { toggle: 'dropdown' }}
13
13
  %ul.dropdown-menu
14
- - non_crud_actions.each do |a|
14
+ - non_primary_actions.each do |a|
15
15
  - path = a.path_helper.is_a?(Proc) ? a.path_helper.call(resource) : send(a.path_helper, resource.id)
16
- - data = a.turbo_frame.present? ? { turbo: true, turbo_frame: a.turbo_frame } : {}
16
+ - hash = {}
17
+ - data = a.turbo_frame.present? ? { turbo: true, turbo_frame: a.turbo_frame, turbo_method: a.verb } : {}
18
+ - hash[:data] = data
19
+ - hash[:method] = a.verb unless a.turbo_frame.present?
17
20
  %li
18
- = dropdown_link_to resource_form_action_label(resource, a.sym), path, data: data, method: a.verb
19
- - crud_actions.each do |a|
21
+ = dropdown_link_to resource_form_action_label(resource, a.sym), path, hash
22
+ - primary_actions.each do |a|
20
23
  - path = a.path_helper.is_a?(Proc) ? a.path_helper.call(resource) : send(a.path_helper, resource.id)
21
24
  - icon_class = (a.verb == :delete ? '' : '')
22
- = link_to path, a.args_hash(title: resource_form_action_label(resource, a.sym), class: "btn btn-sm #{icon_class}") do
23
- %i{ class: resource_form_action_icon(resource, a.sym), style: 'display: block; font-size: 10px' }
24
- %span{ style: 'font-size: 12px' }= resource_form_action_label(resource, a.sym)
25
+ = link_to path, a.args_hash(title: resource_form_action_tooltip(resource, a.sym), class: "btn btn-sm #{icon_class}") do
26
+ - action_label = resource_form_action_label(resource, a.sym)
27
+ - icon_font_size = action_label.blank? ? '18px' : '10px'
28
+ %i{ class: resource_form_action_icon(resource, a.sym), style: "display: block; font-size: #{icon_font_size}" }
29
+ - unless action_label.blank?
30
+ %span{ style: 'font-size: 12px' }= action_label
@@ -101,20 +101,21 @@
101
101
  -# %a.dropdown-item.dropdown-footer{:href => "#"} See All Notifications
102
102
  %li.nav-item.dropdown.user-menu
103
103
  %a.nav-link.dropdown-toggle{"data-toggle" => "dropdown", :href => "#"}
104
- %img.user-image.img-circle.elevation-2{:alt => "User Image", :src => image_path(user_image_path(current_user))}/
104
+ %img.user-image.img-circle.elevation-2{:alt => "User Image", :src => image_path(user_image_path(Olivander::CurrentContext.user))}/
105
105
 
106
- %span.d-none.d-md-inline= current_user.display_name
106
+ %span.d-none.d-md-inline= Olivander::CurrentContext.user.display_name
107
107
  %ul.dropdown-menu.dropdown-menu-lg.dropdown-menu-right
108
108
  / User image
109
109
  %li.user-header.bg-primary
110
- %img.img-circle.elevation-2{:alt => "User Image", src: image_path(user_image_path(current_user))}/
111
- %p= current_user.display_name
110
+ %img.img-circle.elevation-2{:alt => "User Image", src: image_path(user_image_path(Olivander::CurrentContext.user))}/
111
+ %p= Olivander::CurrentContext.user.display_name
112
112
  / Menu Footer
113
- %li.user-footer
114
- = link_to user_path(current_user), class: 'btn btn-default btn-flat' do
115
- Profile
116
- = link_to Olivander::CurrentContext.application_context.sign_out_path, method: :delete, class: 'btn btn-default btn-flat float-right' do
117
- Sign out
113
+ - unless Olivander::CurrentContext.user.is_a?(OpenStruct)
114
+ %li.user-footer
115
+ = link_to polymorphic_path(Olivander::CurrentContext.user), class: 'btn btn-default btn-flat' do
116
+ Profile
117
+ = link_to Olivander::CurrentContext.application_context.sign_out_path, method: :delete, class: 'btn btn-default btn-flat float-right' do
118
+ Sign out
118
119
  %li.nav-item
119
120
  %a.nav-link{title: 'Full Screen Mode', "data-widget" => "fullscreen", :href => "#", :role => "button"}
120
121
  %i.fas.fa-expand-arrows-alt
@@ -11,7 +11,7 @@ module Olivander
11
11
  begin
12
12
  self.route_builder = RouteBuilder.new
13
13
  rescue NameError
14
- self.route_builder = OpenStruct.new(resources: [])
14
+ self.route_builder = OpenStruct.new(resources: {})
15
15
  end
16
16
  end
17
17
 
@@ -55,8 +55,30 @@ module Olivander
55
55
  attribute :application_context
56
56
  attribute :user, :ability
57
57
 
58
- def application_context
59
- @application_context ||= ::Olivander::ApplicationContext.new
58
+ def build(&block)
59
+ self.application_context ||= ::Olivander::ApplicationContext.new
60
+ self.user ||= build_dummy_user
61
+ self.ability ||= build_dummy_ability
62
+ yield(self, application_context, user, ability) if block_given?
63
+ self
64
+ end
65
+
66
+ private
67
+
68
+ def build_dummy_user
69
+ OpenStruct.new({ display_name: 'No User Set' })
70
+ end
71
+
72
+ def build_dummy_ability
73
+ Class.new do
74
+ def can?(_action, _resource)
75
+ true
76
+ end
77
+
78
+ def authorize!(_action, _resource)
79
+ true
80
+ end
81
+ end.new
60
82
  end
61
83
  end
62
84
  end
@@ -1,3 +1,3 @@
1
1
  module Olivander
2
- VERSION = '0.2.0.2'.freeze
2
+ VERSION = '0.2.0.3'.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.2.0.2
4
+ version: 0.2.0.3
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-02-13 00:00:00.000000000 Z
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick
@@ -175,6 +175,7 @@ files:
175
175
  - app/assets/images/default-150x150.png
176
176
  - app/assets/images/icons.png
177
177
  - app/assets/javascripts/adminlte.js
178
+ - app/assets/javascripts/adminlte/datatable.fix.js
178
179
  - app/assets/javascripts/adminlte/dist/css/adminlte.min.css
179
180
  - app/assets/javascripts/adminlte/dist/js/adminlte.js
180
181
  - app/assets/javascripts/adminlte/plugins/bootstrap/js/bootstrap.bundle.min.js