Module: NewsHelper
- Defined in:
- app/helpers/news_helper.rb
Instance Method Summary collapse
- #closable_news?(news) ⇒ Boolean
- #closed_news_ids ⇒ Object
- #createable_news_types(user) ⇒ Object
- #label_for_news(news) ⇒ Object
- #navbar_css_class_for_news(news) ⇒ Object
- #news_tag(news) ⇒ Object
- #project_news_badges(project) ⇒ Object
- #project_news_count(project) ⇒ Object
- #system_news_bars ⇒ Object
Instance Method Details
#closable_news?(news) ⇒ Boolean
37 38 39 |
# File 'app/helpers/news_helper.rb', line 37 def closable_news?(news) news.type != 'News::Administration::Warning' end |
#closed_news_ids ⇒ Object
24 25 26 27 28 |
# File 'app/helpers/news_helper.rb', line 24 def closed_news_ids return [] unless [:closed_news] JSON.parse([:closed_news]) rescue [] end |
#createable_news_types(user) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/news_helper.rb', line 13 def createable_news_types(user) a = News::PROJECT_TYPES.invert.transform_keys{|k| k.to_s.humanize} if user.is_administrator? b = News::ADMINISTRATION_TYPES.invert.transform_keys{|k| k.to_s.humanize} a.merge b else a end end |
#label_for_news(news) ⇒ Object
8 9 10 11 |
# File 'app/helpers/news_helper.rb', line 8 def label_for_news(news) return nil if news.nil? news.title[0..30] end |
#navbar_css_class_for_news(news) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/news_helper.rb', line 67 def (news) case news.type when 'News::Administration::Warning' 'news-bar-warning' when 'News::Administration::Notice' 'news-bar-notice' when 'News::Administration::BlogPost' 'news-bar-info' else 'news-bar-default' end end |
#news_tag(news) ⇒ Object
3 4 5 6 |
# File 'app/helpers/news_helper.rb', line 3 def news_tag(news) return nil if news.nil? news.title[0..30] end |
#project_news_badges(project) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/news_helper.rb', line 54 def project_news_badges(project) project_news_count(project).map do |klass_sym, count| type = klass_sym.to_s.camelize css_type = klass_sym.to_s.delete('_') if (sessions_current_project_id == project.id) link_to("#{type} (#{count})", browse_news_task_path({ category: type, newspapper: 'project' }), class: "v-badge news-#{css_type}-color") else content_tag(:span, "#{type} (#{count})", class: "v-badge news-#{css_type}-color") end end.join.html_safe end |
#project_news_count(project) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/news_helper.rb', line 41 def project_news_count(project) counts = {} News::PROJECT_TYPES.each do |klass, key| counts[key] = News.where( project_id: project.id, type: klass.to_s ).count end counts end |
#system_news_bars ⇒ Object
30 31 32 33 34 35 |
# File 'app/helpers/news_helper.rb', line 30 def @system_news_bars ||= News.administration .current .where.not(id: closed_news_ids) .order(:display_start) end |