Module: MaintenanceTasks::TasksHelper Private
- Defined in:
- app/helpers/maintenance_tasks/tasks_helper.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Helpers for formatting data in the maintenance_tasks views.
Constant Summary collapse
- STATUS_COLOURS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ "new" => ["is-primary"], "enqueued" => ["is-primary is-light"], "running" => ["is-info"], "interrupted" => ["is-info", "is-light"], "pausing" => ["is-warning", "is-light"], "paused" => ["is-warning"], "succeeded" => ["is-success"], "cancelling" => ["is-light"], "cancelled" => ["is-dark"], "errored" => ["is-danger"], }
Instance Method Summary collapse
-
#csv_file_download_path(run) ⇒ Object
private
Returns a download link for a Run’s CSV attachment.
-
#format_backtrace(backtrace) ⇒ String
private
Formats a run backtrace.
-
#highlight_code(code) ⇒ ActiveSupport::SafeBuffer
private
Very simple syntax highlighter based on Ripper.
-
#parameter_field(form_builder, parameter_name) ⇒ Object
private
Return the appropriate field tag for the parameter.
-
#progress(run) ⇒ String?
private
Renders the progress bar.
-
#status_tag(status) ⇒ String
private
Renders a span with a Run’s status, with the corresponding tag class attached.
-
#time_running_in_words(run) ⇒ String
private
Reports the approximate elapsed time a Run has been processed so far based on the Run’s time running attribute.
Instance Method Details
#csv_file_download_path(run) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a download link for a Run’s CSV attachment
97 98 99 100 101 102 |
# File 'app/helpers/maintenance_tasks/tasks_helper.rb', line 97 def csv_file_download_path(run) Rails.application.routes.url_helpers.rails_blob_path( run.csv_file, only_path: true ) end |
#format_backtrace(backtrace) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Formats a run backtrace.
28 29 30 |
# File 'app/helpers/maintenance_tasks/tasks_helper.rb', line 28 def format_backtrace(backtrace) safe_join(backtrace.to_a, tag.br) end |
#highlight_code(code) ⇒ ActiveSupport::SafeBuffer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Very simple syntax highlighter based on Ripper.
It returns the same code except identifiers, keywords, etc. are wrapped in <span> tags with CSS classes that match the types returned by Ripper.lex.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/helpers/maintenance_tasks/tasks_helper.rb', line 84 def highlight_code(code) tokens = Ripper.lex(code).map do |(_position, type, content, _state)| case type when :on_nl, :on_sp, :on_ignored_nl content else tag.span(content, class: type.to_s.sub("on_", "ruby-").dasherize) end end safe_join(tokens) end |
#parameter_field(form_builder, parameter_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the appropriate field tag for the parameter
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/maintenance_tasks/tasks_helper.rb', line 105 def parameter_field(form_builder, parameter_name) case form_builder.object.class.attribute_types[parameter_name] when ActiveModel::Type::Integer, ActiveModel::Type::Decimal, ActiveModel::Type::Float form_builder.number_field(parameter_name) when ActiveModel::Type::DateTime form_builder.datetime_field(parameter_name) when ActiveModel::Type::Date form_builder.date_field(parameter_name) when ActiveModel::Type::Time form_builder.time_field(parameter_name) when ActiveModel::Type::Boolean form_builder.check_box(parameter_name) else form_builder.text_area(parameter_name, class: "textarea") end end |
#progress(run) ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Renders the progress bar.
The style of the progress tag depends on the Run status. It also renders an infinite progress when a Run is active but there is no total information to estimate completion.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/maintenance_tasks/tasks_helper.rb', line 42 def progress(run) return unless run.started? progress = Progress.new(run) = tag.progress( value: progress.value, max: progress.max, class: ["progress"] + STATUS_COLOURS.fetch(run.status) ) progress_text = tag.p(tag.i(progress.text)) tag.div( + progress_text, class: "block") end |
#status_tag(status) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Renders a span with a Run’s status, with the corresponding tag class attached.
62 63 64 |
# File 'app/helpers/maintenance_tasks/tasks_helper.rb', line 62 def status_tag(status) tag.span(status.capitalize, class: ["tag"] + STATUS_COLOURS.fetch(status)) end |
#time_running_in_words(run) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reports the approximate elapsed time a Run has been processed so far based on the Run’s time running attribute.
72 73 74 |
# File 'app/helpers/maintenance_tasks/tasks_helper.rb', line 72 def time_running_in_words(run) distance_of_time_in_words(0, run.time_running, include_seconds: true) end |