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
- #filter_links(topic) ⇒ Object
- #party_topic_dom_id(party_topic) ⇒ Object
- #topic_applies_to_filter_list ⇒ Object
- #topic_breadcrumb(topic) ⇒ Object
- #topic_category_breadcrumb(topic_category) ⇒ Object
- #topic_category_state_label(topic_category) ⇒ Object
- #topic_category_tags(topic_category) ⇒ Object
- #topic_edit_link(topic, return_path = nil) ⇒ Object
- #topic_exam_breadcrumb(topic_exam) ⇒ Object
- #topic_response_link(party_topic) ⇒ Object
- #topic_state_label(topic) ⇒ Object
- #topic_survey_breadcrumb(survey) ⇒ Object
- #topic_tags(topic) ⇒ Object
Instance Method Details
#filter_links(topic) ⇒ Object
77 78 79 80 81 82 83 |
# File 'app/helpers/topics_helper.rb', line 77 def filter_links(topic) content_tag(: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_list ⇒ Object
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) capture do if topic.survey.present? concat (topic.survey) elsif topic.topic_category.present? concat (topic.topic_category) concat content_tag(:li, link_to(topic.topic_category.name, topic_category_path(topic.topic_category.id)), class: 'breadcrumb-item') elsif topic.topic_exam.present? concat (topic.topic_exam) concat content_tag(: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) [].tap do |bc| if topic_category.course bc << content_tag(:li, link_to('Courses', courses_path), class: 'breadcrumb-item') bc << content_tag(:li, link_to(topic_category.course.name, course_path(topic_category.course.id)), class: 'breadcrumb-item') else bc << content_tag(:li, link_to('Topics', topics_path), class: 'breadcrumb-item') bc << content_tag(: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] content_tag(: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) capture do topic_category..each do |t| concat content_tag(:span, t, class: 'badge bg-secondary ms-1') end end end |
#topic_edit_link(topic, return_path = nil) ⇒ Object
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) [].tap do |bc| if topic_exam.course bc << content_tag(:li, link_to('Courses', courses_path), class: 'breadcrumb-item') bc << content_tag(:li, link_to(topic_exam.course.name, course_path(topic_exam.course.id)), class: 'breadcrumb-item') else bc << content_tag(:li, link_to('Topics', topics_path), class: 'breadcrumb-item') bc << content_tag(:li, link_to('Topic Exams', topic_exams_path), class: 'breadcrumb-item') end end.join.html_safe end |
#topic_response_link(party_topic) ⇒ Object
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? content_tag(: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 content_tag(: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] content_tag(: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 (survey) [].tap do |bc| bc << content_tag(:li, link_to('Surveys', surveys_path), class: 'breadcrumb-item') bc << content_tag(: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) capture do topic..each do |t| concat content_tag(:span, t, class: 'badge bg-secondary ms-1') end end end |