Create a cold age helper, make sure the first age column is strictly

`created_at`, add cold to the second column.
This commit is contained in:
Robin Ward 2014-03-10 15:02:39 -04:00
parent c430c6dd30
commit f5e6bcc585
6 changed files with 34 additions and 26 deletions

View File

@ -16,6 +16,33 @@ Handlebars.registerHelper('breakUp', function(property, hint, options) {
return new Handlebars.SafeString(Discourse.Formatter.breakUp(prop, hint)); return new Handlebars.SafeString(Discourse.Formatter.breakUp(prop, hint));
}); });
// helper function for dates
function daysSinceEpoch(dt) {
// 1000 * 60 * 60 * 24 = days since epoch
return dt.getTime() / 86400000;
}
/**
Converts a date to a coldmap class
@method coldDate
**/
Handlebars.registerHelper('coldAgeClass', 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 Truncates long strings

View File

@ -118,25 +118,6 @@ Discourse.Topic = Discourse.Model.extend({
return this.get('new_posts'); return this.get('new_posts');
}.property('new_posts', 'id'), }.property('new_posts', 'id'),
// The coldmap class for the age of the topic
ageCold: function() {
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());
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', 'last_posted_at'),
viewsHeat: function() { viewsHeat: function() {
var v = this.get('views'); var v = this.get('views');
if( v >= Discourse.SiteSettings.topic_views_heat_high ) return 'heatmap-high'; if( v >= Discourse.SiteSettings.topic_views_heat_high ) return 'heatmap-high';

View File

@ -57,10 +57,10 @@
<td {{bind-attr class=":num :views topic.viewsHeat"}}>{{number topic.views numberKey="views_long"}}</td> <td {{bind-attr class=":num :views topic.viewsHeat"}}>{{number topic.views numberKey="views_long"}}</td>
{{#if topic.bumped}} {{#if topic.bumped}}
<td class='num activity'> <td class='num activity'>
<a href="{{unbound topic.url}}" {{{bind-attr class=":age topic.ageCold"}}} title='{{i18n first_post}}: {{{rawDate topic.created_at}}}' >{{unboundAge topic.created_at}}</a> <a href="{{unbound topic.url}}" class='{{coldAgeClass created_at}}' title='{{i18n first_post}}: {{{rawDate topic.created_at}}}' >{{unboundAge topic.created_at}}</a>
</td> </td>
<td class='num activity last'> <td class='num activity last'>
<a href="{{unbound topic.lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{rawDate topic.bumped_at}}}'>{{unboundAge topic.bumped_at}}</a> <a href="{{unbound topic.lastPostUrl}}" class='{{coldAgeClass bumped_at}}' title='{{i18n last_post}}: {{{rawDate topic.bumped_at}}}'>{{unboundAge topic.bumped_at}}</a>
</td> </td>
{{else}} {{else}}
<td class='num activity'> <td class='num activity'>

View File

@ -7,7 +7,7 @@
<section {{bind-attr class=":map mapCollapsed"}}> <section {{bind-attr class=":map mapCollapsed"}}>
<ul class="clearfix"> <ul class="clearfix">
<li> <li>
<a href='{{unbound topic.url}}' {{bind-attr class=topic.ageCold}}> <a href='{{unbound topic.url}}' class='{{coldAgeClass topic.created_at}}'>
<h4>{{i18n created}}</h4> <h4>{{i18n created}}</h4>
{{avatar details.created_by imageSize="tiny"}} {{avatar details.created_by imageSize="tiny"}}
{{unboundDate topic.created_at}} {{unboundDate topic.created_at}}

View File

@ -52,7 +52,7 @@
</div> </div>
</td> </td>
<td class='num posts'><span class='badge-posts'>{{number posts_count}}</span></td> <td class='num posts'><span class='badge-posts'>{{number posts_count}}</span></td>
<td class='num age'><span {{bind-attr class=":age ageCold"}} title='{{rawDate created_at}}'>{{{unboundAge created_at}}}</span></td> <td class='num age'><span class="{{coldAgeClass created_at}}" title='{{rawDate created_at}}'>{{{unboundAge created_at}}}</span></td>
</tr> </tr>
{{/each}} {{/each}}

View File

@ -58,14 +58,14 @@
{{#if bumped}} {{#if bumped}}
<td class='num activity'> <td class='num activity'>
<a href="{{url}}" {{{bind-attr class=":age ageCold"}}} title='{{i18n first_post}}: {{{rawDate created_at}}}' >{{unboundAge created_at}}</a> <a href="{{url}}" class="{{coldAgeClass created_at}}" title='{{i18n first_post}}: {{{rawDate created_at}}}' >{{unboundAge created_at}}</a>
</td> </td>
<td class='num activity last'> <td class='num activity last'>
<a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{rawDate bumped_at}}}'>{{unboundAge bumped_at}}</a> <a href="{{lastPostUrl}}" class="{{coldAgeClass bumped_at}}" title='{{i18n last_post}}: {{{rawDate bumped_at}}}'>{{unboundAge bumped_at}}</a>
</td> </td>
{{else}} {{else}}
<td class='num activity'> <td class='num activity'>
<a href="{{url}}" {{{bind-attr class=":age ageCold"}}} title='{{i18n first_post}}: {{{rawDate created_at}}}'>{{unboundAge created_at}}</a> <a href="{{url}}" class="{{coldAgeClass created_at}}" title='{{i18n first_post}}: {{{rawDate created_at}}}'>{{unboundAge created_at}}</a>
</td> </td>
<td class='activity'></td> <td class='activity'></td>
{{/if}} {{/if}}