Skip to content

Commit

Permalink
Fix cold colours in activity column of topic lists
Browse files Browse the repository at this point in the history
  • Loading branch information
nlalonde committed Jan 21, 2014
1 parent 564a7e5 commit 5f46ce7
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions app/assets/javascripts/discourse/models/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,22 @@ Discourse.Topic = Discourse.Model.extend({

// The coldmap class for the age of the topic
ageCold: function() {
var createdAt, createdAtDays, daysSinceEpoch, lastPost, nowDays;
if (!(lastPost = this.get('last_posted_at'))) return;
var createdAt, daysSinceEpoch, lastPost, lastPostDays, nowDays;
if (!(createdAt = this.get('created_at'))) return;
if (!(lastPost = this.get('last_posted_at'))) lastPost = createdAt;
daysSinceEpoch = function(dt) {
// 1000 * 60 * 60 * 24 = days since epoch
return dt.getTime() / 86400000;
};

// Show heat on age
nowDays = daysSinceEpoch(new Date());
createdAtDays = daysSinceEpoch(new Date(createdAt));
if (daysSinceEpoch(new Date(lastPost)) > nowDays - 90) {
if (createdAtDays < nowDays - 60) return 'coldmap-high';
if (createdAtDays < nowDays - 30) return 'coldmap-med';
if (createdAtDays < nowDays - 14) return 'coldmap-low';
}
lastPostDays = daysSinceEpoch(new Date(lastPost));
if (nowDays - lastPostDays > 60) return 'coldmap-high';
if (nowDays - lastPostDays > 30) return 'coldmap-med';
if (nowDays - lastPostDays > 14) return 'coldmap-low';
return null;
}.property('age', 'created_at'),
}.property('age', 'created_at', 'last_posted_at'),

viewsHeat: function() {
var v = this.get('views');
Expand Down

0 comments on commit 5f46ce7

Please sign in to comment.