Class: DateTimeField
- Defined in:
- lib/generators/hot_glue/fields/date_time_field.rb
Instance Attribute Summary
Attributes inherited from Field
#alt_lookup, #assoc_class, #assoc_label, #assoc_model, #assoc_name, #associations, #attachment_data, #auth, #class_name, #default_boolean_display, #display_as, #form_labels_position, #form_placeholder_labels, #god, #hawk_keys, #hidden_create, #hidden_update, #layout_strategy, #limit, #modify_as, #name, #namespace, #object, #ownership_field, #plural, #polymorphic_parents, #pundit, #sample_file_path, #self_auth, #singular, #singular_class, #sql_type, #stimmify, #update_show_only
Instance Method Summary collapse
- #form_field_output ⇒ Object
- #form_show_only_output ⇒ Object
- #load_all_query_statement ⇒ Object
- #search_field_output ⇒ Object
- #spec_list_view_assertion ⇒ Object
- #spec_list_view_natural_assertion ⇒ Object
- #spec_make_assertion ⇒ Object
- #spec_random_data ⇒ Object
- #spec_setup_and_change_act(which_partial = nil) ⇒ Object
- #spec_setup_let_arg ⇒ Object
- #viewable_output ⇒ Object
- #where_query_statement ⇒ Object
Methods inherited from Field
#code_to_reset_match_if_search_is_blank, #display_boolean_as, #field_error_name, #field_output, #field_view_output, #getName, #hidden_output, #initialize, #label_class, #label_for, #line_field_output, #modified_display_output, #modify_binary?, #newline_after_field?, #prelookup_syntax, #spec_related_column_lets, #testing_name, #text_area_output
Constructor Details
This class inherits a constructor from Field
Instance Method Details
#form_field_output ⇒ Object
42 43 44 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 42 def form_field_output "<%= f.datetime_field( :#{name}, value: #{singular}.#{name} && #{singular}.#{name}.in_time_zone(current_timezone), class: '#{@layout_strategy.form_input_class}' ) %><%= current_timezone %>" end |
#form_show_only_output ⇒ Object
7 8 9 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 7 def form_show_only_output viewable_output end |
#load_all_query_statement ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 88 def load_all_query_statement if !modify_binary? "#{name}_query = date_query_constructor(:#{name}, @q['0'][:#{name}_match], @q['0'][:#{name}_search_start], @q['0'][:#{name}_search_end])" else "#{name}_query = boolean_modified_datetime_constructor(:#{name}, @q['0'][:#{name}_match])" end end |
#search_field_output ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 61 def search_field_output if !modify_binary? " <div data-controller='date-range-picker' >"+ "\n <%= f.select 'q[0][#{name}_match]', options_for_select([['', ''], ['is on', 'is_on'], " + "\n ['is between', 'is_between'], ['is on or after', 'is_on_or_after'], " + "\n ['is before or on', 'is_before_or_on'], ['not on', 'not_on']], @q[\'0\']['#{name}_match'] ), {} ," + "\n { class: 'form-control match', 'data-action': 'change->date-range-picker#matchSelection' } %>"+ "\n <%= datetime_local_field 'q[0]', '#{name}_search_start', {value: @q[\'0\'][:#{name}_search_start], autocomplete: 'off', size: 40, class: 'form-control', placeholder: 'start', 'data-date-range-picker-target': 'start' } %>" + "\n <%= datetime_local_field 'q[0]', '#{name}_search_end', {value: @q[\'0\'][:#{name}_search_end], autocomplete: 'off', size: 40, class: 'form-control', placeholder: 'end' , 'data-date-range-picker-target': 'end' } %>" + "\n </div>" else " <%= f.radio_button('q[0][#{name}_match]', '-1', checked: @q[\'0\'][:#{name}_match]=='-1' ? 'checked' : '', class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" + " <%= f.label('All', value: '-1', for: 'q[0][#{name}_match]_-1' ) %>\n" + " <br /><%= f.radio_button('q[0][#{name}_match]', '0', checked: @q[\'0\'][:#{name}_match]=='0' ? 'checked' : '', class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" + " <%= f.label('#{modify_as[:binary][:falsy]}', value: '0', for: 'q[0][#{name}_match]_0') %>\n" + " <br /><%= f.radio_button('q[0][#{name}_match]', '1', checked: @q[\'0\'][:#{name}_match]=='1' ? 'checked' : '', class: '#{@layout_strategy.form_checkbox_input_class}') %>\n" + " <%= f.label('#{modify_as[:binary][:truthy]}', value: '1', for: 'q[0][#{name}_match]_1') %>\n" + "<br />" end end |
#spec_list_view_assertion ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 30 def spec_list_view_assertion if modify_binary? "expect(page).to have_content('#{modify_as[:binary][:truthy]}')" else spec_list_view_natural_assertion end end |
#spec_list_view_natural_assertion ⇒ Object
38 39 40 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 38 def spec_list_view_natural_assertion "expect(page).to have_content(#{singular}#{1}.#{name}.in_time_zone(testing_timezone).strftime('%m/%d/%Y @ %l:%M %p %Z').gsub(' ', ' '))" end |
#spec_make_assertion ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 18 def spec_make_assertion if !modify_binary? "expect(page).to have_content(new_#{name}.in_time_zone(testing_timezone).strftime('%m/%d/%Y @ %l:%M %p %Z').gsub(' ', ' '))" else "expect(page).to have_content('#{modify_as[:binary][:truthy]}'" end end |
#spec_random_data ⇒ Object
2 3 4 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 2 def spec_random_data Time.now + rand(1..5).days end |
#spec_setup_and_change_act(which_partial = nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 12 def spec_setup_and_change_act(which_partial = nil) " " + "new_#{name} = DateTime.current + 1.year \n" + ' ' + "find(\"[name='#{testing_name}[#{ name.to_s }]']\").fill_in(with: new_#{name.to_s})" end |
#spec_setup_let_arg ⇒ Object
26 27 28 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 26 def spec_setup_let_arg "#{name}: DateTime.current + 1.day" end |
#viewable_output ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 46 def viewable_output if modify_binary? modified_display_output else "<% unless #{singular}.#{name}.nil? %> <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p %Z') %> <% else %> <span class=''>MISSING</span> <% end %>" end end |
#where_query_statement ⇒ Object
84 85 86 |
# File 'lib/generators/hot_glue/fields/date_time_field.rb', line 84 def where_query_statement ".where(#{name}_query)" end |