Module: RocketJobMissionControl::ApplicationHelper
- Defined in:
- app/helpers/rocket_job_mission_control/application_helper.rb
Constant Summary collapse
- STATE_ICON_MAP =
{ aborted: 'fas fa-stop', completed: 'fas fa-check', disabled: 'fas fa-stop', enabled: 'fas fa-check', failed: 'fas fa-exclamation-triangle', paused: 'fas fa-pause', pending: 'fas fa-inbox', queued: 'fas fa-inbox', running: 'fas fa-play', sleeping: 'fas fa-hourglass', scheduled: 'fas fa-clock', starting: 'fas fa-cogs', stopping: 'fas fa-stop', zombie: 'fas fa-hourglass' }
Instance Method Summary collapse
- #active_page(path) ⇒ Object
-
#editable_field_html(klass, field_name, value, f, include_nil_selectors = false) ⇒ Object
Returns the editable field as html for use in editing dynamic fields from a Job class.
-
#extract_inclusion_values(klass, attribute) ⇒ Object
Returns [Array] list of inclusion values for this attribute.
- #pretty_print_array_or_hash(arguments) ⇒ Object
- #site_title ⇒ Object
- #state_icon(state) ⇒ Object
- #title ⇒ Object
Instance Method Details
#active_page(path) ⇒ Object
33 34 35 |
# File 'app/helpers/rocket_job_mission_control/application_helper.rb', line 33 def active_page(path) 'active' if current_page?(path) end |
#editable_field_html(klass, field_name, value, f, include_nil_selectors = false) ⇒ Object
Returns the editable field as html for use in editing dynamic fields from a Job class.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/rocket_job_mission_control/application_helper.rb', line 59 def editable_field_html(klass, field_name, value, f, include_nil_selectors = false) # When editing a job the values are of the correct type. # When editing a dirmon entry values are strings. field = klass.fields[field_name.to_s] return unless field && field.type placeholder = field.default_val placeholder = nil if placeholder.is_a?(Proc) case field.type.name when 'Symbol', 'String', 'Integer' = extract_inclusion_values(klass, field_name) str = "[#{field.type.name}]\n".html_safe if str + f.select(field_name, , { include_blank: .include?(nil) || include_nil_selectors, selected: value }, { class: 'selectize form-control' }) else if field.type.name == 'Integer' str + f.number_field(field_name, value: value, class: 'form-control', placeholder: placeholder) else str + f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder) end end when 'Hash' "[JSON Hash]\n".html_safe + f.text_field(field_name, value: value ? value.to_json : '', class: 'form-control', placeholder: '{"key1":"value1", "key2":"value2", "key3":"value3"}') when 'Array' = Array(value) "[Array]\n".html_safe + f.select(field_name, (, ), { include_hidden: false }, { class: 'selectize form-control', multiple: true }) when 'Mongoid::Boolean' name = "#{field_name}_true".to_sym value = value.to_s str = '<div class="radio-buttons">'.html_safe str << f.(field_name, 'true', checked: value == 'true') str << ' '.html_safe + f.label(name, 'true') str << ' '.html_safe + f.(field_name, 'false', checked: value == 'false') str << ' '.html_safe + f.label(name, 'false') # Allow this field to be unset (nil). if include_nil_selectors str << ' '.html_safe + f.(field_name, '', checked: value == '') str << ' '.html_safe + f.label(name, 'nil') end str << '</div>'.html_safe else "[#{field.type.name}]".html_safe + f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder) end end |
#extract_inclusion_values(klass, attribute) ⇒ Object
Returns [Array] list of inclusion values for this attribute. Returns nil when there are no inclusion values for this attribute.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/rocket_job_mission_control/application_helper.rb', line 45 def extract_inclusion_values(klass, attribute) values = nil klass.validators_on(attribute).each do |validator| case validator when ActiveModel::Validations::InclusionValidator values = validator.[:in] end end values end |
#pretty_print_array_or_hash(arguments) ⇒ Object
37 38 39 40 41 |
# File 'app/helpers/rocket_job_mission_control/application_helper.rb', line 37 def pretty_print_array_or_hash(arguments) return arguments unless arguments.kind_of?(Array) || arguments.kind_of?(Hash) = {space: ' ', indent: ' ', array_nl: '<br />', object_nl: '<br />'} JSON.generate(arguments, ).html_safe end |
#site_title ⇒ Object
24 25 26 |
# File 'app/helpers/rocket_job_mission_control/application_helper.rb', line 24 def site_title 'Rocket Job Mission Control' end |
#state_icon(state) ⇒ Object
20 21 22 |
# File 'app/helpers/rocket_job_mission_control/application_helper.rb', line 20 def state_icon(state) STATE_ICON_MAP[state.to_sym] + ' ' + state.to_s end |
#title ⇒ Object
28 29 30 31 |
# File 'app/helpers/rocket_job_mission_control/application_helper.rb', line 28 def title @page_title ||= params[:controller].to_s.titleize h(@full_title || [@page_title, site_title].compact.join(' | ')) end |