Module: RailsExecution::RenderingHelper
- Defined in:
- app/helpers/rails_execution/rendering_helper.rb
Constant Summary collapse
- AVATAR_CLASS =
'bd-placeholder-img flex-shrink-0 me-2 rounded'
- TRUNCATE_FILE_NAME_LENGTH =
20
Instance Method Summary collapse
- #re_attachment_file_acceptable_types ⇒ Object
- #re_badge_color(status) ⇒ Object
- #re_card_content(id: nil, &block) ⇒ Object
- #re_get_file_name(url) ⇒ Object
- #re_page_actions(&block) ⇒ Object
- #re_render_paging(relation) ⇒ Object
- #render_label(task_label) ⇒ Object
- #render_notification_message(mode, message) ⇒ Object
- #render_owner_avatar(owner, size: '32x32') ⇒ Object
- #render_owner_name(owner) ⇒ Object
- #render_task_labels(task) ⇒ Object
- #render_user_info(user, avatar_size: '40x40') ⇒ Object
- #task_reviewed_status(task) ⇒ Object
Instance Method Details
#re_attachment_file_acceptable_types ⇒ Object
88 89 90 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 88 def ::RailsExecution.configuration.acceptable_file_types.keys.join(',') end |
#re_badge_color(status) ⇒ Object
96 97 98 99 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 96 def re_badge_color(status) color = status_to_color(status.to_s.downcase.to_sym) content_tag :small, status.to_s.titleize, class: "fw-light badge rounded-pill text-bg-#{color}" end |
#re_card_content(id: nil, &block) ⇒ Object
78 79 80 81 82 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 78 def re_card_content(id: nil, &block) content_tag :div, id: id, class: 'my-3 p-3 bg-body rounded shadow-sm' do capture(&block) end end |
#re_get_file_name(url) ⇒ Object
92 93 94 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 92 def re_get_file_name(url) URI(url).path.split('/').last&.truncate(TRUNCATE_FILE_NAME_LENGTH) end |
#re_page_actions(&block) ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 70 def re_page_actions(&block) content_for :page_actions do content_tag :span, class: 'ms-2' do capture(&block) end end end |
#re_render_paging(relation) ⇒ Object
84 85 86 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 84 def re_render_paging(relation) render partial: 'rails_execution/shared/paging', locals: { page: relation.re_current_page, total_pages: relation.re_total_pages } end |
#render_label(task_label) ⇒ Object
44 45 46 47 48 49 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 44 def render_label(task_label) content_tag :div do concat content_tag :i, '', class: "bi bi-tag label-colors lc-#{task_label.color} bg-none" concat content_tag :span, task_label.name, class: "badge rounded-pill mx-1 label-colors lc-#{task_label.color}" end end |
#render_notification_message(mode, message) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 29 def (mode, ) case mode when 'alert' content_tag :div, class: 'alert alert-warning align-items-center' do concat content_tag(:i, nil, class: 'bi bi-x-octagon mr-2') concat content_tag(:span, , class: 'ms-2') end when 'notice' content_tag :div, class: 'alert alert-success align-items-center' do concat content_tag(:i, nil, class: 'bi bi-check-circle mr-2') concat content_tag(:span, , class: 'ms-2') end end end |
#render_owner_avatar(owner, size: '32x32') ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 13 def render_owner_avatar(owner, size: '32x32') return image_tag(asset_path('executions/robot.png'), size: size, class: AVATAR_CLASS) if owner.blank? avatar_url = RailsExecution.configuration.owner_avatar.call(owner) return nil if avatar_url.blank? image_tag avatar_url, size: size, class: AVATAR_CLASS end |
#render_owner_name(owner) ⇒ Object
22 23 24 25 26 27 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 22 def render_owner_name(owner) return 'System' if owner.blank? return nil if RailsExecution.configuration.owner_name_method.blank? content_tag :span, owner.public_send(RailsExecution.configuration.owner_name_method) end |
#render_task_labels(task) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 51 def render_task_labels(task) # to_a and sort_by instead of .order for avoid N+1 query to sort task labels for each task task.labels.to_a.sort_by(&:name).reduce(''.html_safe) do |result, label| case label.name when 'repeat' result + content_tag(:span, "repeat: #{task.repeat_mode}", class: "badge rounded-pill mx-1 label-tag label-colors lc-#{label.color}", data: { id: label.id }) when 'scheduled' result + content_tag(:span, 'scheduled', class: "badge rounded-pill mx-1 label-tag label-colors lc-#{label.color}", data: { id: label.id }) else result + content_tag(:span, label.name, class: "badge rounded-pill mx-1 label-tag label-colors lc-#{label.color}", data: { id: label.id }) end end end |
#render_user_info(user, avatar_size: '40x40') ⇒ Object
6 7 8 9 10 11 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 6 def render_user_info(user, avatar_size: '40x40') content_tag :div, class: 'user-info' do concat render_owner_avatar(user, size: avatar_size) concat render_owner_name(user) end end |
#task_reviewed_status(task) ⇒ Object
65 66 67 68 |
# File 'app/helpers/rails_execution/rendering_helper.rb', line 65 def task_reviewed_status(task) @task_reviewed_status ||= {} @task_reviewed_status[task] ||= task.task_reviews.find_by(owner_id: current_owner&.id)&.status&.inquiry end |