Module: MobileWorkflow::Displayable
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationRecord
- Defined in:
- app/models/concerns/mobile_workflow/displayable.rb
Constant Summary collapse
- ON_SUCCESS_OPTIONS =
[:none, :reload, :backward, :forward]
- BUTTON_STYLES =
[:primary, :outline, :danger]
- CONTENT_MODE_OPTIONS =
[:scale_aspect_fill, :scale_aspect_fit]
- QUESTION_STYLES =
[:single_choice, :multiple_choice]
Instance Method Summary collapse
- #mw_display_button(label:, style: :primary, on_success: :forward, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object
- #mw_display_delete_button(url:, label: "Delete", method: :delete, style: :danger, on_success: :backward) ⇒ Object
- #mw_display_image(attachment, content_mode: :scale_aspect_fill, options: { resize_to_fill: [600, 1200] }) ⇒ Object
- #mw_display_modal_workflow_button(label:, modal_workflow_name:, style: :primary, on_success: :none, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object (also: #mw_display_button_for_modal_workflow)
- #mw_display_system_url_button(label:, apple_system_url: nil, android_deep_link: nil, style: :primary, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object (also: #mw_display_button_for_system_url)
- #mw_display_text(text:, label: nil) ⇒ Object
- #mw_display_unsplash_image(image_url) ⇒ Object
- #mw_display_url_button(label:, url:, method: :put, style: :primary, confirm_title: nil, confirm_text: nil, on_success: :reload, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object (also: #mw_display_button_for_url)
- #mw_display_video(attachment, preview_options: { resize_to_fill: [600, 1200] }) ⇒ Object
- #mw_grid_item(id: self.id, text:, image_attachment: nil) ⇒ Object
- #mw_grid_large_section(id:, text:) ⇒ Object
- #mw_grid_small_section(id:, text:) ⇒ Object
- #mw_list_item(id: self.id, text:, detail_text: nil, sf_symbol_name: nil, image_attachment: nil) ⇒ Object
- #mw_map_item(id: self.id, text:, detail_text: nil, latitude:, longitude:) ⇒ Object
- #mw_pie_chart_item(id: self.id, label:, value:) ⇒ Object
- #mw_text_choice_question(question:, style:, text_choices:) ⇒ Object
Instance Method Details
#mw_display_button(label:, style: :primary, on_success: :forward, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object
48 49 50 51 52 53 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 48 def (label:, style: :primary, on_success: :forward, sf_symbol_name: nil, material_icon_name: nil) validate_on_success!(on_success) (style) {type: :button, label: label, style: style, onSuccess: on_success, sfSymbolName: sf_symbol_name, materialIconName: material_icon_name}.compact end |
#mw_display_delete_button(url:, label: "Delete", method: :delete, style: :danger, on_success: :backward) ⇒ Object
55 56 57 58 59 60 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 55 def (url:, label: "Delete", method: :delete, style: :danger, on_success: :backward) validate_on_success!(on_success) (style) {type: :button, label: label, url: url, method: method, style: style, onSuccess: on_success, sfSymbolName: 'trash', materialIconName: 'delete'}.compact end |
#mw_display_image(attachment, content_mode: :scale_aspect_fill, options: { resize_to_fill: [600, 1200] }) ⇒ Object
29 30 31 32 33 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 29 def mw_display_image(, content_mode: :scale_aspect_fill, options: { resize_to_fill: [600, 1200] }) validate_content_mode!(content_mode) {type: :image, contentMode: content_mode.to_s.camelize(:lower), previewURL: preview_url(, options: ), url: ()} end |
#mw_display_modal_workflow_button(label:, modal_workflow_name:, style: :primary, on_success: :none, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object Also known as:
78 79 80 81 82 83 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 78 def (label:, modal_workflow_name:, style: :primary, on_success: :none, sf_symbol_name: nil, material_icon_name: nil) validate_on_success!(on_success) (style) {type: :button, label: label, modalWorkflow: modal_workflow_name, style: style, onSuccess: on_success, sfSymbolName: sf_symbol_name, materialIconName: material_icon_name}.compact end |
#mw_display_system_url_button(label:, apple_system_url: nil, android_deep_link: nil, style: :primary, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object Also known as:
70 71 72 73 74 75 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 70 def (label:, apple_system_url: nil, android_deep_link: nil, style: :primary, sf_symbol_name: nil, material_icon_name: nil) (style) raise 'Invalid android_deep_link' unless android_deep_link.start_with?('http') {type: :button, label: label, appleSystemURL: apple_system_url, androidDeepLink: android_deep_link, style: style, sfSymbolName: sf_symbol_name, materialIconName: material_icon_name}.compact end |
#mw_display_text(text:, label: nil) ⇒ Object
25 26 27 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 25 def mw_display_text(text:, label: nil) {type: :text, label: label, text: text.to_s}.compact end |
#mw_display_unsplash_image(image_url) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 35 def mw_display_unsplash_image(image_url) if image_url.start_with? "https://unsplash.com/photos" unsplash_id = image_url.split('/').last image_url = "https://source.unsplash.com/#{unsplash_id}/800x600" end {type: :image, previewURL: image_url, url: image_url}.compact end |
#mw_display_url_button(label:, url:, method: :put, style: :primary, confirm_title: nil, confirm_text: nil, on_success: :reload, sf_symbol_name: nil, material_icon_name: nil) ⇒ Object Also known as:
62 63 64 65 66 67 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 62 def (label:, url:, method: :put, style: :primary, confirm_title: nil, confirm_text: nil, on_success: :reload, sf_symbol_name: nil, material_icon_name: nil) validate_on_success!(on_success) (style) {type: :button, label: label, url: url, method: method, style: style, confirmTitle: confirm_title, confirmText: confirm_text, onSuccess: on_success, sfSymbolName: sf_symbol_name, materialIconName: material_icon_name}.compact end |
#mw_display_video(attachment, preview_options: { resize_to_fill: [600, 1200] }) ⇒ Object
44 45 46 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 44 def mw_display_video(, preview_options: { resize_to_fill: [600, 1200] }) {type: :video, previewURL: preview_url(, options: ), url: ()} end |
#mw_grid_item(id: self.id, text:, image_attachment: nil) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 109 def mw_grid_item(id: self.id, text:, image_attachment: nil) raise 'Missing id' if id.nil? raise 'Missing text' if text.nil? item = { id: id, text: text, type: :item } item[:imageURL] = preview_url(, options: { resize_to_fill: [600, 600] }) if item end |
#mw_grid_large_section(id:, text:) ⇒ Object
95 96 97 98 99 100 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 95 def mw_grid_large_section(id:, text:) raise 'Missing id' if id.nil? raise 'Missing text' if text.nil? { id: id, text: text, type: :largeSection } end |
#mw_grid_small_section(id:, text:) ⇒ Object
102 103 104 105 106 107 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 102 def mw_grid_small_section(id:, text:) raise 'Missing id' if id.nil? raise 'Missing text' if text.nil? { id: id, text: text, type: :smallSection } end |
#mw_list_item(id: self.id, text:, detail_text: nil, sf_symbol_name: nil, image_attachment: nil) ⇒ Object
11 12 13 14 15 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 11 def mw_list_item(id: self.id, text:, detail_text: nil, sf_symbol_name: nil, image_attachment: nil) mw_list_item = {id: id, text: text, detailText: detail_text, sfSymbolName: sf_symbol_name} mw_list_item[:imageURL] = preview_url(, options: { resize_to_fill: [100, 100] }) if mw_list_item.compact end |
#mw_map_item(id: self.id, text:, detail_text: nil, latitude:, longitude:) ⇒ Object
17 18 19 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 17 def mw_map_item(id: self.id, text:, detail_text: nil, latitude:, longitude:) {id: id, text: text, detailText: detail_text, latitude: latitude, longitude: longitude}.compact end |
#mw_pie_chart_item(id: self.id, label:, value:) ⇒ Object
21 22 23 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 21 def mw_pie_chart_item(id: self.id, label:, value:) {id: id, label: label, value: value}.compact end |
#mw_text_choice_question(question:, style:, text_choices:) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 86 def mw_text_choice_question(question:, style:, text_choices:) raise 'Missing question' if question.blank? raise 'Text Choices should be a hash' unless text_choices.is_a?(Hash) validate_question_style!(style) text_choices_a = text_choices.map{|k, v| {_class: "ORKTextChoice", exclusive: false, text: k, value: v} }.to_a { question: question, answerFormat: { _class: "ORKTextChoiceAnswerFormat", style: style.to_s.camelize(:lower), textChoices: text_choices_a}} end |