five-two-nw-olivander 0.1.2.22 → 0.1.2.24

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: cf9c0144387ec2d459f02dadea4b96402dac9698093cc3fd897de95fc787ba7d
4
- data.tar.gz: 84c801572bdec84621c76e8c34c0b640dcbc0f9b106edf4c0425d683455e7673
3
+ metadata.gz: 9898ba669152317001f7f33540a9367bb177c57ab66a7141599e2d813334c505
4
+ data.tar.gz: f39570a4bd11aedbf8f30dd60fbde534263b080297bfd057dafc3ae8ff2fbe9f
5
5
  SHA512:
6
- metadata.gz: e2cae3668e04550b11d6514e73cd914d29aab621e3b63b3ddaf1d0f79af52bb1d6b92e24d9a1747f0cf8af5e043ccc6a288b4e64a5fc4c960893db417e37d932
7
- data.tar.gz: a6dd96121cec897f2639f147fca0737fdb20fc4dab3e8879635b6d41bf385dfe9303ece99333687c9e51041d383a051bca081f1896c640eafb73e201ca3ef1de
6
+ metadata.gz: 442950a337255b5c53805f09f58eed5bd0cc2185f55977cedad2f2000783c5d04dfc9624f0b89cbdb9520446ee3c73914b5bd788f03a6af38f99273b893abfe7
7
+ data.tar.gz: 8afccfa400c2512f2beab92b60e2758017f9fbce51d240f05b4d2128b3e89dea80eb81d9d551ce68d574efabe9060f72fc6419c21af94acf0fe5b9e2ef34e282
@@ -4,7 +4,8 @@
4
4
  .row
5
5
  - section.fields.each do |field|
6
6
  %div{ class: section.column_class }
7
- - if field.type == :association
8
- = @f.association field.sym, disabled: !field.editable
7
+ - case field.type
8
+ - when :association
9
+ = @f.association field.sym, disabled: !field.editable, input_html: { data: { controller: "input-control-#{field.type}" } }
9
10
  - else
10
- = @f.input field.sym, disabled: !field.editable
11
+ = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { data: { controller: "input-control-#{field.type}" } }
@@ -84,5 +84,34 @@ module Olivander
84
84
 
85
85
  sym.to_s.titleize
86
86
  end
87
+
88
+ def is_dev_environment?
89
+ sidebar_context_suffix != 'production'
90
+ end
91
+
92
+ def sidebar_context_name
93
+ [@context.name, sidebar_context_suffix&.upcase].reject(&:blank?).join(' ')
94
+ end
95
+
96
+ def sidebar_context_suffix
97
+ suffix = nil
98
+ suffix ||= ENV['CLIENT_ENVIRONMENT']
99
+ parts = request.host.split('.')
100
+ suffix ||= parts.first.split('-').last.downcase if request.host.include?('-')
101
+ suffix ||= 'local' if %w[localhost test].include?(parts.last.downcase)
102
+ suffix ||= 'production'
103
+ suffix
104
+ end
105
+
106
+ def sidebar_background_class
107
+ @context.sidebar_background_class ||
108
+ ENV['SIDEBAR_BACKGROUND_CLASS'] ||
109
+ (is_dev_environment? ? 'bg-danger' : 'bg-info')
110
+ end
111
+
112
+ def favicon_link
113
+ favicon_path = is_dev_environment? ? '/images/favicon-dev.png' : '/images/favicon.ico'
114
+ favicon_link_tag(image_path(favicon_path))
115
+ end
87
116
  end
88
117
  end
@@ -0,0 +1,43 @@
1
+ class CustomFormBuilder < SimpleForm::FormBuilder
2
+ def initialize(*)
3
+ Rails.logger.warn "instantiating this class"
4
+ super
5
+ end
6
+
7
+ def association(association, options = {}, &block)
8
+ Rails.logger.warn "making an association"
9
+ resolve_custom_input_association(association, options)
10
+ super(association, options, &block)
11
+ end
12
+
13
+ def resolve_custom_input_association(association, options)
14
+ return if options[:as].present?
15
+
16
+ [
17
+ "#{object.class.name.demodulize}#{association.to_s.titleize}", "#{association.to_s.titleize}"
18
+ ].each do |key|
19
+ Rails.logger.debug "trying for #{key}"
20
+ next unless attempt_mapping_with_custom_namespace("#{key}Input").present?
21
+
22
+ options[:as] = key.to_sym
23
+ break
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def fetch_association_collection(reflection, options)
30
+ Rails.logger.warn "we got into here"
31
+
32
+ options_method = "options_for_#{reflection.name}".to_sym
33
+ if object.respond_to?(options_method) then
34
+ Rails.logger.info "using specific method"
35
+ options.fetch(:collection) do
36
+ object.send(options_method)
37
+ end
38
+ else
39
+ Rails.logger.info "doing it old school"
40
+ super(reflection, options)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,38 @@
1
+ class DateTimeInput < SimpleForm::Inputs::Base
2
+ def input(wrapper_options)
3
+ date_format = options[:date_format] || '%m/%d/%Y'
4
+ raw_value = object.public_send(attribute_name)
5
+ raw_value = raw_value.strftime(date_format) if raw_value.present?
6
+
7
+ disabled = options[:disabled] || false
8
+
9
+ field = @builder.text_field(attribute_name, id: "#{attribute_name}_datetimepicker", class: 'form-control', value: raw_value, disabled: disabled, 'data-toggle': 'datetimepicker', 'data-target': "##{attribute_name}_datetimepicker")
10
+
11
+ add_on_class = options[:add_on_class] || "fa fa-calendar"
12
+
13
+ add_on = template.content_tag(:div, class: "input-group-prepend") do
14
+ add_on = template.content_tag(:div, class: "input-group-text") do
15
+ template.content_tag(:i, '', :class => add_on_class, 'data-toggle': 'datetimepicker', 'data-target': "##{attribute_name}_datetimepicker")
16
+ end
17
+ end
18
+
19
+ all = content_tag(:div, add_on + field, class: 'input-group')
20
+
21
+ script = "".html_safe
22
+ unless disabled then
23
+ picker_options = options[:picker_options] || { "format" => "MM/DD/YYYY" }
24
+
25
+ script = """
26
+ <script>
27
+ $(document).ready(function() {
28
+ $('##{attribute_name}_datetimepicker').datetimepicker(
29
+ #{picker_options.to_json}
30
+ );
31
+ });
32
+ </script>
33
+ """.html_safe
34
+ end
35
+
36
+ all + script
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  - read_only = action_name != 'edit'
2
- = simple_form_for(@resource) do |f|
2
+ = simple_form_for(@resource, builder: CustomFormBuilder) do |f|
3
3
  .card.card-primary
4
4
  .card-header
5
5
  %h3.card-title= @resource
@@ -18,6 +18,8 @@
18
18
  .card-header
19
19
  %h3.card-title= I18n.t([@datatable.class.name.underscore, 'charts', k].join('.'))
20
20
  .card-tools.text-right
21
+ %button.btn.btn-tool{ type: :button, 'data-card-widget': :collapse }
22
+ %i.fas.fa-minus
21
23
  %button.btn.btn-tool{ type: :button, 'data-card-widget': :maximize }
22
24
  %i.fas.fa-expand
23
25
  .card-body{ style: 'height: 220px' }
@@ -0,0 +1,4 @@
1
+ resource = (@_effective_resource || Effective::Resource.new(controller_path))
2
+ @resources = instance_variable_get('@' + resource.plural_name)
3
+
4
+ json.array! @resources
@@ -2,6 +2,7 @@
2
2
  %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
3
3
  %title= page_title
4
4
  %meta{:content => "width=device-width,initial-scale=1", :name => "viewport"}/
5
+ = favicon_link
5
6
  = csrf_meta_tags
6
7
  = csp_meta_tag
7
8
  %link{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback' }
@@ -1,9 +1,9 @@
1
1
  / Main Sidebar Container
2
2
  %aside.main-sidebar.sidebar-dark-primary.elevation-4{ data: { controller: 'left-nav' }}
3
3
  / Brand Logo
4
- %a.brand-link.bg-info{:href => "/"}
4
+ %a.brand-link{ href: "/", class: sidebar_background_class }
5
5
  %img.brand-image.img-circle.elevation-3{:alt => @context.logo.alt, :src => @context.logo.url, :style => "opacity: .8"}/
6
- %span.brand-text.font-weight-light= @context.name
6
+ %span.brand-text.font-weight-light= sidebar_context_name
7
7
  / Sidebar
8
8
  .sidebar
9
9
  / Sidebar user panel (optional)
@@ -13,7 +13,7 @@ SimpleForm.setup do |config|
13
13
  # wrapper, change the order or even add your own to the
14
14
  # stack. The options given below are used to wrap the
15
15
  # whole input.
16
- config.wrappers :default, class: :input,
16
+ config.wrappers :default, class: "form-group",
17
17
  hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
18
18
  ## Extensions enabled by default
19
19
  # Any of these extensions can be disabled for a
@@ -52,16 +52,82 @@ SimpleForm.setup do |config|
52
52
  b.optional :readonly
53
53
 
54
54
  ## Inputs
55
- # b.use :input, class: 'input', error_class: 'is-invalid', valid_class: 'is-valid'
56
- b.use :label_input
55
+ # b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
56
+ b.use :label #, class: 'form-control'
57
+ b.use :input, class: 'form-control'
57
58
  b.use :hint, wrap_with: { tag: :span, class: :hint }
58
- b.use :error, wrap_with: { tag: :span, class: :error }
59
+ b.use :error, wrap_with: { tag: :span, class: "text-danger" }
59
60
 
60
61
  ## full_messages_for
61
62
  # If you want to display the full error message for the attribute, you can
62
63
  # use the component :full_error, like:
63
64
  #
64
65
  # b.use :full_error, wrap_with: { tag: :span, class: :error }
66
+
67
+ # b.wrapper
68
+ end
69
+
70
+ config.wrappers :checkbox, class: "form-check",
71
+ hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
72
+ b.use :html5
73
+ b.optional :readonly
74
+ b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
75
+ ba.use :label_text
76
+ end
77
+ b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
78
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
79
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
80
+ end
81
+
82
+ # vertical input for boolean
83
+ config.wrappers :vertical_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
84
+ b.use :html5
85
+ b.optional :readonly
86
+ b.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb|
87
+ bb.use :input, class: 'form-check-input' #, error_class: 'is-invalid', valid_class: 'is-valid'
88
+ bb.use :label, class: 'form-check-label'
89
+ bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
90
+ bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
91
+ end
92
+ end
93
+
94
+ # vertical input for radio buttons and check boxes
95
+ config.wrappers :vertical_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
96
+ b.use :html5
97
+ b.optional :readonly
98
+ b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
99
+ ba.use :label_text
100
+ end
101
+ b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
102
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
103
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
104
+ end
105
+
106
+ # vertical input for inline radio buttons and check boxes
107
+ config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
108
+ b.use :html5
109
+ b.optional :readonly
110
+ b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
111
+ ba.use :label_text
112
+ end
113
+ b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
114
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
115
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
116
+ end
117
+
118
+ config.wrappers :switch, class: "custom-control custom-switch",
119
+ hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
120
+ b.use :html5
121
+ b.use :placeholder
122
+ b.optional :maxlength
123
+ b.optional :minlength
124
+ b.optional :pattern
125
+ b.optional :min_max
126
+ b.optional :readonly
127
+ b.use :input, class: 'custom-control-input'
128
+ #b.use :label, class: 'custom-control-label'
129
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
130
+ b.use :error, wrap_with: { tag: :span, class: "text-danger" }
65
131
  end
66
132
 
67
133
  # The default wrapper to be used by the FormBuilder.
@@ -71,7 +137,7 @@ SimpleForm.setup do |config|
71
137
  # Defaults to :nested for bootstrap config.
72
138
  # inline: input + label
73
139
  # nested: label > input
74
- config.boolean_style = :nested
140
+ config.boolean_style = :inline
75
141
 
76
142
  # Default class for buttons
77
143
  config.button_class = 'btn'
@@ -137,10 +203,24 @@ SimpleForm.setup do |config|
137
203
  # Custom wrappers for input types. This should be a hash containing an input
138
204
  # type as key and the wrapper that will be used for all inputs with specified type.
139
205
  # config.wrapper_mappings = { string: :prepend }
206
+ config.wrapper_mappings = {
207
+ boolean: :vertical_boolean,
208
+ check_boxes: :check_box,
209
+ # date: :horizontal_multi_select,
210
+ # datetime: :horizontal_multi_select,
211
+ # file: :horizontal_file,
212
+ # radio_buttons: :horizontal_collection,
213
+ # range: :horizontal_range,
214
+ # time: :horizontal_multi_select
215
+ }
140
216
 
141
217
  # Namespaces where SimpleForm should look for custom input classes that
142
218
  # override default inputs.
143
- # config.custom_inputs_namespaces << "CustomInputs"
219
+ Dir.glob('app/inputs/**/')
220
+ .map{ |x| x.gsub('app/inputs/', '').split('/').reject(&:blank?).join('/').camelize }
221
+ .reject(&:blank?).each do |d|
222
+ config.custom_inputs_namespaces << d
223
+ end
144
224
 
145
225
  # Default priority for time_zone inputs.
146
226
  # config.time_zone_priority = nil
@@ -1,6 +1,6 @@
1
1
  module Olivander
2
2
  class ApplicationContext
3
- attr_accessor :name, :logo, :company, :menu_items, :route_builder, :sign_out_path
3
+ attr_accessor :name, :logo, :company, :menu_items, :route_builder, :sign_out_path, :sidebar_background_class
4
4
 
5
5
  def self.default
6
6
  ctx = ApplicationContext.new
@@ -1,3 +1,3 @@
1
1
  module Olivander
2
- VERSION = "0.1.2.22"
2
+ VERSION = '0.1.2.24'.freeze
3
3
  end
@@ -0,0 +1,15 @@
1
+ <%# frozen_string_literal: true %>
2
+ <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
3
+ <%%= f.error_notification %>
4
+ <%%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
5
+
6
+ <div class="form-inputs">
7
+ <%- attributes.each do |attribute| -%>
8
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
9
+ <%- end -%>
10
+ </div>
11
+
12
+ <div class="form-actions">
13
+ <%%= f.button :submit %>
14
+ </div>
15
+ <%% 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.22
4
+ version: 0.1.2.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-19 00:00:00.000000000 Z
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick
@@ -194,6 +194,8 @@ files:
194
194
  - app/controllers/olivander/application_controller.rb
195
195
  - app/datatables/olivander/datatable.rb
196
196
  - app/helpers/olivander/application_helper.rb
197
+ - app/inputs/custom_form_builder.rb
198
+ - app/inputs/date_time_input.rb
197
199
  - app/jobs/olivander/application_job.rb
198
200
  - app/mailers/olivander/application_mailer.rb
199
201
  - app/models/olivander/application_record.rb
@@ -201,6 +203,7 @@ files:
201
203
  - app/views/application/_resource_form_actions.html.haml
202
204
  - app/views/application/edit.html.haml
203
205
  - app/views/application/index.html.haml
206
+ - app/views/application/index.json.jbuilder
204
207
  - app/views/application/new.html.haml
205
208
  - app/views/application/show.html.haml
206
209
  - app/views/effective/resource/_actions_dropleft.html.haml
@@ -228,6 +231,7 @@ files:
228
231
  - lib/olivander/menus/menu_item.rb
229
232
  - lib/olivander/version.rb
230
233
  - lib/tasks/olivander_tasks.rake
234
+ - lib/templates/erb/scaffold/_form.html.erb
231
235
  - lib/templates/erb/scaffold/_form.html.haml
232
236
  homepage: https://rubygems.org/gems/olivander
233
237
  licenses: