Module: TopicsHelper

Defined in:
app/helpers/topics_helper.rb

Overview

== Schema Information

Table name: topics

id :integer not null, primary key
topic_category_id :integer
title :string(255) not null
description :text
state :string(255) not null
created_at :datetime not null
creator_id :integer
updated_at :datetime not null
updater_id :integer
integer :integer is an Array
contact_roles :string(255) is an Array
string :string(255) is an Array
applies_to_company :boolean default(FALSE)
multiple_responses_allowed :boolean
applies_to_contact :boolean default(FALSE)
email_snippet :text
position :integer
customer_filter_id :integer
applies_to_employee :boolean default(FALSE)

Instance Method Summary collapse

Instance Method Details



77
78
79
80
81
82
83
# File 'app/helpers/topics_helper.rb', line 77

def filter_links(topic)
	(:ul, class: 'list-inline') do
			concat(link_to(fa_icon('pen-to-square', text: "Edit Filter #{topic.customer_filter.name}"), edit_customer_filter_path(topic.customer_filter), class: 'btn btn-link')) if topic.customer_filter
		concat link_to(fa_icon('filter', text: 'Manage customer filters'), customer_filters_path, class: 'btn btn-link')
   	concat link_to(fa_icon('circle-plus', text: "New Filter"), new_customer_filter_path, class: 'btn btn-link')
   end
end

#party_topic_dom_id(party_topic) ⇒ Object



141
142
143
# File 'app/helpers/topics_helper.rb', line 141

def party_topic_dom_id(party_topic)
	"topic_#{party_topic.topic_id}_party_#{party_topic.party_id}"
end

#topic_applies_to_filter_listObject



73
74
75
# File 'app/helpers/topics_helper.rb', line 73

def topic_applies_to_filter_list
	[['Company','company'], ['Contact','contact'], ['Company or Contact','company_or_contact'], ['Employee','employee']]
end

#topic_breadcrumb(topic) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/topics_helper.rb', line 59

def topic_breadcrumb(topic)
  capture do
    if topic.survey.present?
      concat topic_survey_breadcrumb(topic.survey)
 elsif topic.topic_category.present?
      concat topic_category_breadcrumb(topic.topic_category)
      concat (:li, link_to(topic.topic_category.name, topic_category_path(topic.topic_category.id)), class: 'breadcrumb-item')
 elsif topic.topic_exam.present?
      concat topic_exam_breadcrumb(topic.topic_exam)
      concat (:li, link_to(topic.topic_exam.name, topic_exam_path(topic.topic_exam.id)), class: 'breadcrumb-item')
    end
  end
end

#topic_category_breadcrumb(topic_category) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/topics_helper.rb', line 28

def topic_category_breadcrumb(topic_category)
  [].tap do |bc|
    if topic_category.course
      bc << (:li, link_to('Courses', courses_path), class: 'breadcrumb-item')
      bc << (:li, link_to(topic_category.course.name, course_path(topic_category.course.id)), class: 'breadcrumb-item')
    else
      bc << (:li, link_to('Topics', topics_path), class: 'breadcrumb-item')
      bc << (:li, link_to('Topic Categories', topic_categories_path), class: 'breadcrumb-item')
    end
  end.join.html_safe
end

#topic_category_state_label(topic_category) ⇒ Object



164
165
166
167
168
169
170
# File 'app/helpers/topics_helper.rb', line 164

def topic_category_state_label(topic_category)
  css_state = {
    active: 'success',
    inactive: 'warning'
  }[topic_category.state.to_sym]
  (:span, topic_category.state, class: "badge bg-#{css_state}")
end

#topic_category_tags(topic_category) ⇒ Object



93
94
95
96
97
98
99
# File 'app/helpers/topics_helper.rb', line 93

def topic_category_tags(topic_category)
  capture do
    topic_category.tags.each do |t|
      concat (:span, t, class: 'badge bg-secondary ms-1')
    end
  end
end


146
147
148
149
150
151
152
153
# File 'app/helpers/topics_helper.rb', line 146

def topic_edit_link(topic, return_path = nil)
	if can?(:update,topic)
		link_to(fa_icon('pen-to-square', text: topic.title),
						edit_topic_path(topic), return_path: return_path )
	else
		topic.title
	end
end

#topic_exam_breadcrumb(topic_exam) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/topics_helper.rb', line 47

def topic_exam_breadcrumb(topic_exam)
  [].tap do |bc|
    if topic_exam.course
      bc << (:li, link_to('Courses', courses_path), class: 'breadcrumb-item')
      bc << (:li, link_to(topic_exam.course.name, course_path(topic_exam.course.id)), class: 'breadcrumb-item')
    else
      bc << (:li, link_to('Topics', topics_path), class: 'breadcrumb-item')
      bc << (:li, link_to('Topic Exams', topic_exams_path), class: 'breadcrumb-item')
    end
  end.join.html_safe
end


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/helpers/topics_helper.rb', line 101

def topic_response_link(party_topic)
	dom_id = party_topic_dom_id(party_topic)
	if party_topic.new_record?
		(:span, fa_icon("square", class: 'fa-2x', family: 'far'),
											 id: "link_#{dom_id}", class: 'topic-link',
											 title: "Please click to respond",
											 style: 'color: gray;',
											 'data-bs-toggle': 'modal',
                        'data-bs-target': "##{dom_id}"
     )
	else
		title = []
		title << party_topic.topic_responses.first.try(:response)
		title << party_topic.comments
		title = title.compact.join(', ')
		#Determine style color based on aging
		if party_topic.follow_up
			style_color = '#03A9F4' #blue
		else
			days_ago = Date.current - (party_topic.updated_at || party_topic.created_at || Date.current).to_date
			style_color = case days_ago
			when 0..183
				'#6e8840' #green
			when 184..365
				'#eb7808' #orange
			else
				'#f44336' #red
			end
		end
		(:span, fa_icon("square-check", class: 'fa-2x'),
											 id: "link_#{dom_id}",
											 class: 'topic-link',
											 title: title,
											 style: "color:#{style_color};",
                        'data-bs-toggle': 'modal',
                        'data-bs-target': "##{dom_id}"
     )
	end
end

#topic_state_label(topic) ⇒ Object



155
156
157
158
159
160
161
162
# File 'app/helpers/topics_helper.rb', line 155

def topic_state_label(topic)
	css_state = {
		active: 'success',
		archived: 'warning',
		draft: 'secondary'
	}[topic.state.to_sym]
	(:span, topic.human_state_name, class: "badge bg-#{css_state}")
end

#topic_survey_breadcrumb(survey) ⇒ Object



40
41
42
43
44
45
# File 'app/helpers/topics_helper.rb', line 40

def topic_survey_breadcrumb(survey)
  [].tap do |bc|
      bc << (:li, link_to('Surveys', surveys_path), class: 'breadcrumb-item')
      bc << (:li, link_to(survey.name, survey_path(survey.id)), class: 'breadcrumb-item')
  end.join.html_safe
end

#topic_tags(topic) ⇒ Object



85
86
87
88
89
90
91
# File 'app/helpers/topics_helper.rb', line 85

def topic_tags(topic)
  capture do
    topic.tags.each do |t|
      concat (:span, t, class: 'badge bg-secondary ms-1')
    end
  end
end