Module: PartyTopicsHelper

Defined in:
app/helpers/party_topics_helper.rb

Overview

View helper: party topics.

Instance Method Summary collapse

Instance Method Details

#party_topic_event_button(event) ⇒ Hash

Button treatment for a state-machine event: confirming events read green,
destructive ones red and ask first, everything else stays quiet. Unlisted
events still render, so adding a transition never leaves a bare button.

Parameters:

  • event (Symbol, String)

    the state-machine event

Returns:

  • (Hash)

    :class, :icon and, for destructive events, :confirm



25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/party_topics_helper.rb', line 25

def party_topic_event_button(event)
  {
    review_complete: { class: 'btn-success', icon: 'circle-check' },
    certify: { class: 'btn-primary', icon: 'diploma' },
    cancel: { class: 'btn-outline-danger', icon: 'ban', confirm: 'Cancel this training assignment?' },
    unassign: { class: 'btn-outline-secondary', icon: 'arrow-rotate-left' },
    assign: { class: 'btn-outline-secondary', icon: 'user-plus' },
    request: { class: 'btn-outline-secondary', icon: 'hand' }
  }.fetch(event.to_sym, { class: 'btn-outline-secondary', icon: 'circle-arrow-right' })
end

#party_topic_state_label(party_topic) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/party_topics_helper.rb', line 5

def party_topic_state_label(party_topic)
  state = party_topic.state&.to_sym
  css_class = {
    assigned: :danger,
    reviewed: :info,
    certified: :success,
    cancelled: :secondary,
    requested: :warning
  }.fetch(state, :secondary)
  label_value = state ? party_topic.human_state_name.titleize : 'Unknown'
  label_value = fa_icon('diploma', text: label_value) if state == :certified
  (:span, label_value, class: "badge bg-#{css_class}")
end