Module: Sileo::ControllerMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/sileo/controller_methods.rb

Instance Method Summary collapse

Instance Method Details

#sileo_action(title, **options) ⇒ Object



65
66
67
# File 'lib/sileo/controller_methods.rb', line 65

def sileo_action(title, **options)
  sileo_notify(title, type: :action, **options)
end

#sileo_error(title, **options) ⇒ Object



53
54
55
# File 'lib/sileo/controller_methods.rb', line 53

def sileo_error(title, **options)
  sileo_notify(title, type: :error, **options)
end

#sileo_info(title, **options) ⇒ Object



61
62
63
# File 'lib/sileo/controller_methods.rb', line 61

def sileo_info(title, **options)
  sileo_notify(title, type: :info, **options)
end

#sileo_loading(title, **options) ⇒ Object



69
70
71
# File 'lib/sileo/controller_methods.rb', line 69

def sileo_loading(title, **options)
  sileo_notify(title, type: :loading, duration: nil, **options)
end

#sileo_notify(title, type: :info, description: nil, **options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sileo/controller_methods.rb', line 9

def sileo_notify(title, type: :info, description: nil, **options)
  include_icon = options.key?(:icon)
  icon = options.delete(:icon) if include_icon
  include_duration = options.key?(:duration)
  duration = options.delete(:duration) if include_duration
  include_roundness = options.key?(:roundness)
  roundness = options.delete(:roundness) if include_roundness
  include_position = options.key?(:position)
  position = options.delete(:position) if include_position
  include_autopilot = options.key?(:autopilot)
  autopilot = options.delete(:autopilot) if include_autopilot
  include_autopilot_expand = options.key?(:autopilot_expand)
  autopilot_expand = options.delete(:autopilot_expand) if include_autopilot_expand
  include_autopilot_collapse = options.key?(:autopilot_collapse)
  autopilot_collapse = options.delete(:autopilot_collapse) if include_autopilot_collapse
  include_title_color = options.key?(:title_color) || options.key?(:titleColor)
  title_color = options.key?(:title_color) ? options.delete(:title_color) : options.delete(:titleColor)
  include_icon_color = options.key?(:icon_color) || options.key?(:iconColor)
  icon_color = options.key?(:icon_color) ? options.delete(:icon_color) : options.delete(:iconColor)

  notification = {
    title: title,
    state: normalize_sileo_state(type),
    description: description,
    position: normalize_sileo_position(include_position ? position : sileo_defaults.default_position),
    duration: include_duration ? duration : sileo_defaults.default_duration,
    roundness: include_roundness ? roundness : sileo_defaults.default_roundness,
    autopilot: include_autopilot ? autopilot : sileo_defaults.enable_autopilot,
    autopilotExpand: include_autopilot_expand ? autopilot_expand : sileo_defaults.autopilot_expand_delay,
    autopilotCollapse: include_autopilot_collapse ? autopilot_collapse : sileo_defaults.autopilot_collapse_delay,
    **options
  }
  notification[:icon] = icon if include_icon
  notification[:titleColor] = title_color if include_title_color
  notification[:iconColor] = icon_color if include_icon_color

  flash[:sileo_notifications] ||= []
  flash[:sileo_notifications] << notification
end

#sileo_success(title, **options) ⇒ Object



49
50
51
# File 'lib/sileo/controller_methods.rb', line 49

def sileo_success(title, **options)
  sileo_notify(title, type: :success, **options)
end

#sileo_warning(title, **options) ⇒ Object



57
58
59
# File 'lib/sileo/controller_methods.rb', line 57

def sileo_warning(title, **options)
  sileo_notify(title, type: :warning, **options)
end