REVERT commits for raw handlebars rendering. We need to create a

separate branch and discuss issues of this approach.
This commit is contained in:
Robin Ward 2014-10-28 10:56:04 -04:00
parent 2143348dea
commit a4363e033d
12 changed files with 66 additions and 82 deletions

View File

@ -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("<a href='" + this.get('topic.lastPostUrl') +"'>" + Discourse.Formatter.autoUpdatingRelativeAge(this.get('bumpedAt')) + "</a>");
}
});

View File

@ -8,25 +8,18 @@ export function daysSinceEpoch(dt) {
**/ **/
function coldAgeClass(property, options) { function coldAgeClass(property, options) {
var dt = Em.Handlebars.get(this, 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; } if (!dt) { return 'age'; }
var startDate = (options && options.hash && options.hash.startDate) || new Date();
if (typeof startDate === "string") {
startDate = Em.Handlebars.get(this, startDate, options);
}
// Show heat on age // Show heat on age
var nowDays = daysSinceEpoch(startDate), var nowDays = daysSinceEpoch(new Date()),
epochDays = daysSinceEpoch(new Date(dt)); 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_high) return 'age coldmap-high';
if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_medium) return className + ' coldmap-med'; if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_medium) return 'age coldmap-med';
if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_low) return className + ' coldmap-low'; if (nowDays - epochDays > Discourse.SiteSettings.cold_age_days_low) return 'age coldmap-low';
return className; return 'age';
} }
Handlebars.registerHelper('cold-age-class', coldAgeClass); Handlebars.registerHelper('cold-age-class', coldAgeClass);

View File

@ -3,27 +3,19 @@
update the dates on a regular interval. update the dates on a regular interval.
**/ **/
Handlebars.registerHelper('format-date', function(property, options) { Handlebars.registerHelper('format-date', function(property, options) {
var leaveAgo, format = 'medium', title = true; var leaveAgo;
var hash = property.hash || (options && options.hash); if (property.hash) {
if (property.hash.leaveAgo) {
if (hash) { leaveAgo = property.hash.leaveAgo === "true";
if (hash.leaveAgo) {
leaveAgo = hash.leaveAgo === "true";
} }
if (hash.path) { if (property.hash.path) {
property = hash.path; property = property.hash.path;
}
if (hash.format) {
format = hash.format;
}
if (hash.noTitle) {
title = false;
} }
} }
var val = Ember.Handlebars.get(this, property, options); var val = Ember.Handlebars.get(this, property, options);
if (val) { if (val) {
var date = new Date(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}));
} }
}); });

View File

@ -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);
});

View File

@ -1,24 +1,5 @@
Discourse.Topic = Discourse.Model.extend({ 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() { postStream: function() {
return Discourse.PostStream.create({topic: this}); return Discourse.PostStream.create({topic: this});
}.property(), }.property(),

View File

@ -48,7 +48,7 @@
{{number topic.views numberKey="views_long"}} {{number topic.views numberKey="views_long"}}
</td> </td>
{{handlebars "list/activity_column" topic=topic class="num" tagName="td"}} {{activity-column topic=topic class="num"}}
</tr> </tr>
{{/grouped-each}} {{/grouped-each}}
</tbody> </tbody>

View File

@ -1 +0,0 @@
<{{this.tagName}} class="{{cold-age-class "topic.createdAt" startDate="topic.bumpedAt" class=this.class}} activity" title="{{get "topic.bumpedAtTitle"}}"><a href="{{get "topic.lastPostUrl"}}">{{format-date "topic.bumpedAt" format="tiny" noTitle=true}}</a></{{this.tagName}}>

View File

@ -1,3 +0,0 @@
{{#unless hideCategory}}
<td class='category'>{{category-link "category" showParent=true}}</td>
{{/unless}}

View File

@ -1,5 +0,0 @@
<td class='posters'>
{{#each posters}}
<a href="{{get "user.path"}}" data-user-card="{{this.user.username}}" class="{{get "extras"}}">{{avatar this usernamePath="user.username" imageSize="small"}}</a>
{{/each}}
</td>

View File

@ -27,10 +27,13 @@
{{/if}} {{/if}}
</td> </td>
{{handlebars "list/category_column" hideCategory=hideCategory category=category}} {{#unless hideCategory}}
{{handlebars "list/posters_column" posters=posters}} <td class='category'>{{bound-category-link category showParent=true}}</td>
{{/unless}}
{{view 'posters-column' posters=posters}}
{{posts-count-column topic=model class="num" action="showTopicEntrance"}} {{posts-count-column topic=model class="num" action="showTopicEntrance"}}
<td class="num views {{unbound viewsHeat}}">{{number views numberKey="views_long"}}</td> <td {{bind-attr class=":num :views viewsHeat"}}>{{number views numberKey="views_long"}}</td>
{{handlebars "list/activity_column" topic=model class="num" tagName="td"}} {{activity-column topic=model class="num"}}

View File

@ -27,7 +27,7 @@
<div class="topic-item-stats clearfix"> <div class="topic-item-stats clearfix">
<div class="pull-right"> <div class="pull-right">
{{posts-count-column topic=topic tagName="div" class="num posts" action="clickedPosts"}} {{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"}}
</div> </div>
{{#unless controller.hideCategory}} {{#unless controller.hideCategory}}
<div class='category'> <div class='category'>

View File

@ -31,7 +31,7 @@
{{posts-count-column topic=this tagName="div" class="num posts" action="showTopicEntrance"}} {{posts-count-column topic=this tagName="div" class="num posts" action="showTopicEntrance"}}
<div class='num activity last'> <div class='num activity last'>
<a href="{{lastPostUrl}}" title='{{i18n last_post}}: {{{raw-date bumped_at}}}'>{{last_poster_username}}</a> <a href="{{lastPostUrl}}" title='{{i18n last_post}}: {{{raw-date bumped_at}}}'>{{last_poster_username}}</a>
{{handlebars "list/activity_column" topic=this tagName="span" class="age"}} {{activity-column topic=this tagName="span" class="age"}}
</div> </div>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>