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]

Instance Method Summary collapse

Instance Method Details

#mw_display_button(label:, style: :primary, on_success: :forward) ⇒ Object



47
48
49
50
51
52
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 47

def mw_display_button(label:, style: :primary, on_success: :forward)
  validate_on_success!(on_success)
  validate_button_style!(style)
  
  {type: :button, label: label, style: style, onSuccess: on_success}.compact
end

#mw_display_delete_button(url:, label: "Delete", method: :delete, style: :danger, on_success: :backward) ⇒ Object



54
55
56
57
58
59
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 54

def mw_display_delete_button(url:, label: "Delete", method: :delete, style: :danger, on_success: :backward)
  validate_on_success!(on_success)
  validate_button_style!(style)
  
  {type: :button, label: label, url: url, method: method, style: style, onSuccess: on_success}.compact
end

#mw_display_image(attachment, content_mode: :scale_aspect_fill, options: { resize_to_fill: [600, 1200] }) ⇒ Object



28
29
30
31
32
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 28

def mw_display_image(attachment, 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(attachment, options: options), url: attachment_url(attachment)}
end

#mw_display_modal_workflow_button(label:, modal_workflow_name:, style: :primary, on_success: :none) ⇒ Object Also known as: mw_display_button_for_modal_workflow



77
78
79
80
81
82
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 77

def mw_display_modal_workflow_button(label:, modal_workflow_name:, style: :primary, on_success: :none)
  validate_on_success!(on_success)
  validate_button_style!(style)
  
  {type: :button, label: label, modalWorkflow: modal_workflow_name, style: style, onSuccess: on_success}.compact
end

#mw_display_system_url_button(label:, apple_system_url: nil, android_deep_link: nil, style: :primary) ⇒ Object Also known as: mw_display_button_for_system_url



69
70
71
72
73
74
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 69

def mw_display_system_url_button(label:, apple_system_url: nil, android_deep_link: nil, style: :primary)
  validate_button_style!(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}.compact
end

#mw_display_text(text:, label: nil) ⇒ Object



24
25
26
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 24

def mw_display_text(text:, label: nil)
  {type: :text, label: label, text: text.to_s}.compact
end

#mw_display_unsplash_image(image_url) ⇒ Object



34
35
36
37
38
39
40
41
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 34

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) ⇒ Object Also known as: mw_display_button_for_url



61
62
63
64
65
66
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 61

def mw_display_url_button(label:, url:, method: :put, style: :primary, confirm_title: nil, confirm_text: nil, on_success: :reload)
  validate_on_success!(on_success)
  validate_button_style!(style)
  
  {type: :button, label: label, url: url, method: method, style: style, confirmTitle: confirm_title, confirmText: confirm_text, onSuccess: on_success}.compact
end

#mw_display_video(attachment, preview_options: { resize_to_fill: [600, 1200] }) ⇒ Object



43
44
45
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 43

def mw_display_video(attachment, preview_options: { resize_to_fill: [600, 1200] })
  {type: :video, previewURL: preview_url(attachment, options: preview_options), url: attachment_url(attachment)}
end

#mw_list_item(id: self.id, text:, detail_text: nil, sf_symbol_name: nil, image_attachment: nil) ⇒ Object



10
11
12
13
14
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 10

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(image_attachment, options: { resize_to_fill: [100, 100] }) if image_attachment
  mw_list_item.compact
end

#mw_map_item(id: self.id, text:, detail_text: nil, latitude:, longitude:) ⇒ Object



16
17
18
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 16

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



20
21
22
# File 'app/models/concerns/mobile_workflow/displayable.rb', line 20

def mw_pie_chart_item(id: self.id, label:, value:)
  {id: id, label: label, value: value}.compact
end