diff --git a/app/assets/javascripts/discourse/components/activity-column.js.es6 b/app/assets/javascripts/discourse/components/activity-column.js.es6 new file mode 100644 index 00000000000..5a758902136 --- /dev/null +++ b/app/assets/javascripts/discourse/components/activity-column.js.es6 @@ -0,0 +1,45 @@ +import { daysSinceEpoch } from "discourse/helpers/cold-age-class"; + +export default Ember.Component.extend({ + tagName: 'td', + classNameBindings: [':activity', 'coldness'], + attributeBindings: ['title'], + + // returns createdAt if there's no bumped date + bumpedAt: function() { + var bumpedAt = this.get('topic.bumped_at'); + if (bumpedAt) { + return new Date(bumpedAt); + } else { + return this.get('createdAt'); + } + }.property('topic.bumped_at', 'createdAt'), + + createdAt: function() { + return new Date(this.get('topic.created_at')); + }.property('topic.created_at'), + + coldness: function() { + var bumpedAt = this.get('bumpedAt'), + createdAt = this.get('createdAt'); + + if (!bumpedAt) { return; } + var delta = daysSinceEpoch(bumpedAt) - daysSinceEpoch(createdAt); + + if (delta > 120) { return 'coldmap-high'; } + if (delta > 60) { return 'coldmap-med'; } + if (delta > 14) { return 'coldmap-low'; } + }.property('bumpedAt', 'createdAt'), + + title: function() { + // return {{i18n last_post}}: {{{raw-date topic.bumped_at}}} + return I18n.t('first_post') + ": " + Discourse.Formatter.longDate(this.get('createdAt')) + "\n" + + I18n.t('last_post') + ": " + Discourse.Formatter.longDate(this.get('bumpedAt')); + }.property('bumpedAt', 'createdAt'), + + render: function(buffer) { + buffer.push(''); + buffer.push(Discourse.Formatter.autoUpdatingRelativeAge(this.get('bumpedAt'))); + buffer.push(""); + } +}); diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index 2023c817dce..b10286832f2 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -1,33 +1,5 @@ -// helper function for dates -function daysSinceEpoch(dt) { - // 1000 * 60 * 60 * 24 = days since epoch - return dt.getTime() / 86400000; -} - var safe = Handlebars.SafeString; -/** - Converts a date to a coldmap class - - @method cold-age-class - @for Handlebars -**/ -Handlebars.registerHelper('cold-age-class', function(property, options) { - var dt = Em.Handlebars.get(this, property, options); - - if (!dt) { return 'age'; } - - // Show heat on age - var nowDays = daysSinceEpoch(new Date()), - epochDays = daysSinceEpoch(new Date(dt)); - if (nowDays - epochDays > 60) return 'age coldmap-high'; - if (nowDays - epochDays > 30) return 'age coldmap-med'; - if (nowDays - epochDays > 14) return 'age coldmap-low'; - - return 'age'; -}); - - /** Truncates long strings diff --git a/app/assets/javascripts/discourse/helpers/cold-age-class.js.es6 b/app/assets/javascripts/discourse/helpers/cold-age-class.js.es6 new file mode 100644 index 00000000000..a3bfaf6ea0e --- /dev/null +++ b/app/assets/javascripts/discourse/helpers/cold-age-class.js.es6 @@ -0,0 +1,25 @@ +export function daysSinceEpoch(dt) { + // 1000 * 60 * 60 * 24 = days since epoch + return dt.getTime() / 86400000; +} + +/** + Converts a date to a coldmap class +**/ +function coldAgeClass(property, options) { + var dt = Em.Handlebars.get(this, property, options); + + if (!dt) { return 'age'; } + + // Show heat on age + var nowDays = daysSinceEpoch(new Date()), + epochDays = daysSinceEpoch(new Date(dt)); + if (nowDays - epochDays > 60) return 'age coldmap-high'; + if (nowDays - epochDays > 30) return 'age coldmap-med'; + if (nowDays - epochDays > 14) return 'age coldmap-low'; + + return 'age'; +} + +Handlebars.registerHelper('cold-age-class', coldAgeClass); +export default coldAgeClass; diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 318c8cb3ae3..05663e913cc 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -1,11 +1,3 @@ -/** - A data model representing a Topic - - @class Topic - @extends Discourse.Model - @namespace Discourse - @module Discourse -**/ Discourse.Topic = Discourse.Model.extend({ postStream: function() { diff --git a/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars b/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars index 1ac50166b70..db42f78a7fd 100644 --- a/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars +++ b/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars @@ -12,7 +12,7 @@