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

This reverts commit a4363e033d.
This commit is contained in:
Sam 2014-10-29 13:05:19 +11:00
parent 189ae2e6e3
commit e3b88d3688
12 changed files with 82 additions and 66 deletions

View file

@ -1,43 +0,0 @@
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,18 +8,25 @@ 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 '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);
}
// Show heat on age
var nowDays = daysSinceEpoch(new Date()),
var nowDays = daysSinceEpoch(startDate),
epochDays = daysSinceEpoch(new Date(dt));
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';
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';
return 'age';
return className;
}
Handlebars.registerHelper('cold-age-class', coldAgeClass);

View file

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

View file

@ -0,0 +1,19 @@
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,5 +1,24 @@
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(),

View file

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

View file

@ -0,0 +1 @@
<{{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

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

View file

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

View file

@ -27,7 +27,7 @@
<div class="topic-item-stats clearfix">
<div class="pull-right">
{{posts-count-column topic=topic tagName="div" class="num posts" action="clickedPosts"}}
{{activity-column topic=topic tagName="div" class="num activity last"}}
{{handlebars "list/activity_column" topic=topic tagName="div" class="num activity last"}}
</div>
{{#unless controller.hideCategory}}
<div class='category'>

View file

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