From 72508d459b01120a713f662898aeec80eadbe094 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 23 Apr 2013 15:06:13 -0400 Subject: [PATCH] Use heat map on views column in topic lists --- app/assets/javascripts/discourse/models/topic.js | 8 ++++++++ .../templates/list/topic_list_item.js.handlebars | 2 +- app/models/site_setting.rb | 5 +++++ config/locales/server.en.yml | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 5626efdc1..3060364dd 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -117,6 +117,14 @@ Discourse.Topic = Discourse.Model.extend({ return null; }).property('age', 'created_at'), + viewsHeat: function() { + var v = this.get('views'); + if( v >= Discourse.SiteSettings.topic_views_heat_high ) return 'heatmap-high'; + if( v >= Discourse.SiteSettings.topic_views_heat_medium ) return 'heatmap-med'; + if( v >= Discourse.SiteSettings.topic_views_heat_low ) return 'heatmap-low'; + return null; + }.property('views'), + archetypeObject: (function() { return Discourse.get('site.archetypes').findProperty('id', this.get('archetype')); }).property('archetype'), diff --git a/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars b/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars index 172c62666..187df13b3 100644 --- a/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars +++ b/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars @@ -48,7 +48,7 @@ {{/if}} - {{number views numberKey="views_long"}} + {{number views numberKey="views_long"}} {{#if bumped}} diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 4544d7eec..cc0edd69c 100755 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -180,6 +180,11 @@ class SiteSetting < ActiveRecord::Base setting(:max_similar_results, 7) + # Settings for topic heat + client_setting(:topic_views_heat_low, 1000) + client_setting(:topic_views_heat_medium, 2000) + client_setting(:topic_views_heat_high, 5000) + def self.generate_api_key! self.api_key = SecureRandom.hex(32) end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 990d65599..ad61dfbee 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -533,6 +533,10 @@ en: title_prettify: "Prevent common title typos and errors, including all caps, lowercase first character, multiple ! and ?, extra . at end, etc." + topic_views_heat_low: "The number of views after which a topic's heat level is low." + topic_views_heat_medium: "The number of views after which a topic's heat level is medium." + topic_views_heat_high: "The number of views after which a topic's heat level is high." + notification_types: mentioned: "%{display_username} mentioned you in %{link}" liked: "%{display_username} liked your post in %{link}"