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..8f6a20aee8f --- /dev/null +++ b/app/assets/javascripts/discourse/components/activity-column.js.es6 @@ -0,0 +1,43 @@ +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 > Discourse.SiteSettings.cold_age_days_high) { return 'coldmap-high'; } + if (delta > Discourse.SiteSettings.cold_age_days_medium) { return 'coldmap-med'; } + if (delta > Discourse.SiteSettings.cold_age_days_low) { return 'coldmap-low'; } + }.property('bumpedAt', 'createdAt'), + + title: function() { + 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("" + Discourse.Formatter.autoUpdatingRelativeAge(this.get('bumpedAt')) + ""); + } + +}); diff --git a/app/assets/javascripts/discourse/helpers/cold-age-class.js.es6 b/app/assets/javascripts/discourse/helpers/cold-age-class.js.es6 index 1727448e6fd..d7d644a79a0 100644 --- a/app/assets/javascripts/discourse/helpers/cold-age-class.js.es6 +++ b/app/assets/javascripts/discourse/helpers/cold-age-class.js.es6 @@ -8,25 +8,18 @@ export function daysSinceEpoch(dt) { **/ function coldAgeClass(property, options) { var dt = Em.Handlebars.get(this, property, options); - var className = (options && options.hash && options.hash.class !== undefined) ? options.hash.class : 'age'; - if (!dt) { return className; } - - var startDate = (options && options.hash && options.hash.startDate) || new Date(); - - if (typeof startDate === "string") { - startDate = Em.Handlebars.get(this, startDate, options); - } + if (!dt) { return 'age'; } // Show heat on age - var nowDays = daysSinceEpoch(startDate), + var nowDays = daysSinceEpoch(new Date()), epochDays = daysSinceEpoch(new Date(dt)); - if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_high) return className + ' coldmap-high'; - if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_medium) return className + ' coldmap-med'; - if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_low) return className + ' coldmap-low'; + if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_high) return 'age coldmap-high'; + if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_medium) return 'age coldmap-med'; + if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_low) return 'age coldmap-low'; - return className; + return 'age'; } Handlebars.registerHelper('cold-age-class', coldAgeClass); diff --git a/app/assets/javascripts/discourse/helpers/format-date.js.es6 b/app/assets/javascripts/discourse/helpers/format-date.js.es6 index 312d8947b01..1de71f4c22e 100644 --- a/app/assets/javascripts/discourse/helpers/format-date.js.es6 +++ b/app/assets/javascripts/discourse/helpers/format-date.js.es6 @@ -3,27 +3,19 @@ update the dates on a regular interval. **/ Handlebars.registerHelper('format-date', function(property, options) { - var leaveAgo, format = 'medium', title = true; - var hash = property.hash || (options && options.hash); - - if (hash) { - if (hash.leaveAgo) { - leaveAgo = hash.leaveAgo === "true"; + var leaveAgo; + if (property.hash) { + if (property.hash.leaveAgo) { + leaveAgo = property.hash.leaveAgo === "true"; } - if (hash.path) { - property = hash.path; - } - if (hash.format) { - format = hash.format; - } - if (hash.noTitle) { - title = false; + if (property.hash.path) { + property = property.hash.path; } } var val = Ember.Handlebars.get(this, property, options); if (val) { var date = new Date(val); - return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: format, title: title, leaveAgo: leaveAgo})); + return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', title: true, leaveAgo: leaveAgo})); } }); diff --git a/app/assets/javascripts/discourse/helpers/handlebars.js.es6 b/app/assets/javascripts/discourse/helpers/handlebars.js.es6 deleted file mode 100644 index 18931346b42..00000000000 --- a/app/assets/javascripts/discourse/helpers/handlebars.js.es6 +++ /dev/null @@ -1,19 +0,0 @@ -Handlebars.registerHelper('handlebars', function(property, options) { - - var template = Em.TEMPLATES[property + ".raw"]; - var params = options.hash; - - if(params) { - for(var prop in params){ - if(options.hashTypes[prop] === "ID") { - params[prop] = Em.Handlebars.get(this, params[prop], options); - } - } - } - - return new Handlebars.SafeString(template(params)); -}); - -Handlebars.registerHelper('get', function(property) { - return Em.get(this, property); -}); diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index f748e2b33e8..40c0d9eb877 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -1,24 +1,5 @@ Discourse.Topic = Discourse.Model.extend({ - // returns createdAt if there's no bumped date - bumpedAt: function() { - var bumpedAt = this.get('bumped_at'); - if (bumpedAt) { - return new Date(bumpedAt); - } else { - return this.get('createdAt'); - } - }.property('bumped_at', 'createdAt'), - - bumpedAtTitle: function() { - 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: function() { - return new Date(this.get('created_at')); - }.property('created_at'), - postStream: function() { return Discourse.PostStream.create({topic: this}); }.property(), diff --git a/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs index 1cdf72cd357..706b2ce3b1c 100644 --- a/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs @@ -48,7 +48,7 @@ {{number topic.views numberKey="views_long"}} - {{handlebars "list/activity_column" topic=topic class="num" tagName="td"}} + {{activity-column topic=topic class="num"}} {{/grouped-each}} diff --git a/app/assets/javascripts/discourse/templates/list/activity_column.raw.hbs b/app/assets/javascripts/discourse/templates/list/activity_column.raw.hbs deleted file mode 100644 index 7f532c9b57d..00000000000 --- a/app/assets/javascripts/discourse/templates/list/activity_column.raw.hbs +++ /dev/null @@ -1 +0,0 @@ -<{{this.tagName}} class="{{cold-age-class "topic.createdAt" startDate="topic.bumpedAt" class=this.class}} activity" title="{{get "topic.bumpedAtTitle"}}">{{format-date "topic.bumpedAt" format="tiny" noTitle=true}} diff --git a/app/assets/javascripts/discourse/templates/list/category_column.raw.hbs b/app/assets/javascripts/discourse/templates/list/category_column.raw.hbs deleted file mode 100644 index 5978e08b496..00000000000 --- a/app/assets/javascripts/discourse/templates/list/category_column.raw.hbs +++ /dev/null @@ -1,3 +0,0 @@ -{{#unless hideCategory}} -{{category-link "category" showParent=true}} -{{/unless}} diff --git a/app/assets/javascripts/discourse/templates/list/posters_column.raw.hbs b/app/assets/javascripts/discourse/templates/list/posters_column.raw.hbs deleted file mode 100644 index b091db1aac6..00000000000 --- a/app/assets/javascripts/discourse/templates/list/posters_column.raw.hbs +++ /dev/null @@ -1,5 +0,0 @@ - -{{#each posters}} -{{avatar this usernamePath="user.username" imageSize="small"}} -{{/each}} - diff --git a/app/assets/javascripts/discourse/templates/list/topic_list_item.hbs b/app/assets/javascripts/discourse/templates/list/topic_list_item.hbs index 3e108d328a3..6735b9b8c22 100644 --- a/app/assets/javascripts/discourse/templates/list/topic_list_item.hbs +++ b/app/assets/javascripts/discourse/templates/list/topic_list_item.hbs @@ -27,10 +27,13 @@ {{/if}} -{{handlebars "list/category_column" hideCategory=hideCategory category=category}} -{{handlebars "list/posters_column" posters=posters}} +{{#unless hideCategory}} +{{bound-category-link category showParent=true}} +{{/unless}} + +{{view 'posters-column' posters=posters}} {{posts-count-column topic=model class="num" action="showTopicEntrance"}} -{{number views numberKey="views_long"}} +{{number views numberKey="views_long"}} -{{handlebars "list/activity_column" topic=model class="num" tagName="td"}} +{{activity-column topic=model class="num"}} diff --git a/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs index 2b5f07508b1..3c03c87774f 100644 --- a/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs @@ -27,7 +27,7 @@
{{posts-count-column topic=topic tagName="div" class="num posts" action="clickedPosts"}} - {{handlebars "list/activity_column" topic=topic tagName="div" class="num activity last"}} + {{activity-column topic=topic tagName="div" class="num activity last"}}
{{#unless controller.hideCategory}}
diff --git a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs index 7ba927d93a6..670c9f5b140 100644 --- a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs @@ -31,7 +31,7 @@ {{posts-count-column topic=this tagName="div" class="num posts" action="showTopicEntrance"}}
{{last_poster_username}} - {{handlebars "list/activity_column" topic=this tagName="span" class="age"}} + {{activity-column topic=this tagName="span" class="age"}}