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: [1200, 600] }) ⇒ 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, options: { resize_to_fill: [1560, 877.5] }) ⇒ 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, material_icon_name: nil, image_attachment: nil) ⇒ Object
- #mw_list_search_suggestion(id: self.id, text:, section_name:, sf_symbol_name: 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
52 53 54 55 56 57 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 52 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
59 60 61 62 63 64 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 59 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: [1200, 600] }) ⇒ Object
33 34 35 36 37 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 33 def mw_display_image(, content_mode: :scale_aspect_fill, options: { resize_to_fill: [1200, 600] }) 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:
82 83 84 85 86 87 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 82 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:
74 75 76 77 78 79 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 74 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' if android_deep_link && !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
29 30 31 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 29 def mw_display_text(text:, label: nil) {type: :text, label: label, text: text.to_s}.compact end |
#mw_display_unsplash_image(image_url) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 39 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:
66 67 68 69 70 71 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 66 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
48 49 50 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 48 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, options: { resize_to_fill: [1560, 877.5] }) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 113 def mw_grid_item(id: self.id, text:, image_attachment: nil, options: { resize_to_fill: [1560, 877.5] }) raise 'Missing id' if id.nil? raise 'Missing text' if text.nil? item = { id: id, text: text, type: :item } item[:imageURL] = preview_url(, options: ) if item end |
#mw_grid_large_section(id:, text:) ⇒ Object
99 100 101 102 103 104 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 99 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
106 107 108 109 110 111 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 106 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, material_icon_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, material_icon_name: nil, image_attachment: nil) mw_list_item = {id: id, text: text, detailText: detail_text, sfSymbolName: sf_symbol_name, materialIconName: material_icon_name} mw_list_item[:imageURL] = preview_url(, options: { resize_to_fill: [200, 200] }) if mw_list_item.compact end |
#mw_list_search_suggestion(id: self.id, text:, section_name:, sf_symbol_name: nil) ⇒ Object
17 18 19 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 17 def mw_list_search_suggestion(id: self.id, text:, section_name:, sf_symbol_name: nil) {id: id.to_s, text: text, sectionName: section_name, sfSymbolName: sf_symbol_name}.compact end |
#mw_map_item(id: self.id, text:, detail_text: nil, latitude:, longitude:) ⇒ Object
21 22 23 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 21 def mw_map_item(id: self.id, text:, detail_text: nil, latitude:, longitude:) {id: id.to_s, text: text, detailText: detail_text, latitude: latitude, longitude: longitude}.compact end |
#mw_pie_chart_item(id: self.id, label:, value:) ⇒ Object
25 26 27 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 25 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
90 91 92 93 94 95 96 97 |
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 90 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 |