mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 16:48:29 +08:00
Migrate more helpers to ES6 format.
This commit is contained in:
parent
6f149edecc
commit
1de9c3b04a
|
@ -19,7 +19,7 @@
|
|||
|
||||
{{#each model}}
|
||||
<tr>
|
||||
<td>{{date created_at}}</td>
|
||||
<td>{{format-date created_at}}</td>
|
||||
<td>
|
||||
{{#if user}}
|
||||
{{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
{{#each model}}
|
||||
<tr>
|
||||
<td>{{date created_at}}</td>
|
||||
<td>{{format-date created_at}}</td>
|
||||
<td>
|
||||
{{#if user}}
|
||||
{{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
{{#each model}}
|
||||
<tr>
|
||||
<td>{{date created_at}}</td>
|
||||
<td>{{format-date created_at}}</td>
|
||||
<td>
|
||||
{{#if user}}
|
||||
{{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}}
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
{{#link-to 'adminUser' user}}
|
||||
{{user.username}}
|
||||
{{/link-to}}
|
||||
{{age flaggedAt}}
|
||||
{{format-age flaggedAt}}
|
||||
<br />
|
||||
{{flagType}}
|
||||
</td>
|
||||
|
@ -88,7 +88,7 @@
|
|||
{{/link-to}}
|
||||
</td>
|
||||
<td>
|
||||
{{age disposedAt}}
|
||||
{{format-age disposedAt}}
|
||||
{{{dispositionIcon}}}
|
||||
{{#if tookAction}}
|
||||
<i class='fa fa-gavel' title='{{i18n admin.flags.took_action}}'></i>
|
||||
|
|
|
@ -45,17 +45,6 @@ Handlebars.registerHelper('raw-date', function(property, options) {
|
|||
return Discourse.Formatter.longDate(dt);
|
||||
});
|
||||
|
||||
/**
|
||||
Live refreshing age helper
|
||||
|
||||
@method age
|
||||
@for Handlebars
|
||||
**/
|
||||
Handlebars.registerHelper('age', function(property, options) {
|
||||
var dt = new Date(Ember.Handlebars.get(this, property, options));
|
||||
return new safe(Discourse.Formatter.autoUpdatingRelativeAge(dt));
|
||||
});
|
||||
|
||||
/**
|
||||
Live refreshing age helper, with a tooltip showing the date and time
|
||||
|
||||
|
@ -98,33 +87,3 @@ Handlebars.registerHelper('number', function(property, options) {
|
|||
|
||||
return new safe(result);
|
||||
});
|
||||
|
||||
/**
|
||||
Display logic for dates. It is unbound in Ember but will use jQuery to
|
||||
update the dates on a regular interval.
|
||||
|
||||
@method date
|
||||
@for Handlebars
|
||||
**/
|
||||
Handlebars.registerHelper('date', function(property, options) {
|
||||
var leaveAgo;
|
||||
if (property.hash) {
|
||||
if (property.hash.leaveAgo) {
|
||||
leaveAgo = property.hash.leaveAgo === "true";
|
||||
}
|
||||
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 safe(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', title: true, leaveAgo: leaveAgo}));
|
||||
}
|
||||
});
|
||||
|
||||
Em.Handlebars.helper('bound-date', function(dt) {
|
||||
return new safe(Discourse.Formatter.autoUpdatingRelativeAge(new Date(dt), {format: 'medium', title: true }));
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export default Ember.Handlebars.makeBoundHelper(function(dt) {
|
||||
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(new Date(dt), {format: 'medium', title: true }));
|
||||
});
|
|
@ -0,0 +1,4 @@
|
|||
Handlebars.registerHelper('format-age', function(property, options) {
|
||||
var dt = new Date(Ember.Handlebars.get(this, property, options));
|
||||
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(dt));
|
||||
});
|
21
app/assets/javascripts/discourse/helpers/format-date.js.es6
Normal file
21
app/assets/javascripts/discourse/helpers/format-date.js.es6
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
Display logic for dates. It is unbound in Ember but will use jQuery to
|
||||
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";
|
||||
}
|
||||
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: 'medium', title: true, leaveAgo: leaveAgo}));
|
||||
}
|
||||
});
|
|
@ -10,7 +10,9 @@ var deprecatedViewHelpers = {
|
|||
};
|
||||
|
||||
var renamedHelpers = {
|
||||
icon: "fa-icon"
|
||||
icon: "fa-icon",
|
||||
date: "format-date",
|
||||
age: "format-age"
|
||||
};
|
||||
|
||||
export default {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
{{avatar user imageSize="large"}}
|
||||
<div class="details">
|
||||
<span class="username">{{user.username}}</span>
|
||||
{{date granted_at}}
|
||||
{{format-date granted_at}}
|
||||
</div>
|
||||
{{/link-to}}
|
||||
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
<a href='{{unbound topic.url}}'>
|
||||
<h4>{{i18n created_lowercase}}</h4>
|
||||
{{avatar details.created_by imageSize="tiny"}}
|
||||
{{date topic.created_at}}
|
||||
{{format-date topic.created_at}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a {{bind-attr href="topic.lastPostUrl"}}>
|
||||
<h4>{{i18n last_post_lowercase}}</h4>
|
||||
{{avatar details.last_poster imageSize="tiny"}}
|
||||
{{date topic.last_posted_at}}
|
||||
{{format-date topic.last_posted_at}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
|
|
|
@ -53,11 +53,11 @@
|
|||
{{#if controller.latestTopicOnly}}
|
||||
<div class='last-user-info'>
|
||||
{{i18n categories.latest_by}} <a href="{{{unbound lastPosterUrl}}}">{{unbound last_poster.username}}</a>
|
||||
<a href="{{unbound lastPostUrl}}">{{age last_posted_at}}</a>
|
||||
<a href="{{unbound lastPostUrl}}">{{format-age last_posted_at}}</a>
|
||||
</div>
|
||||
{{else}}
|
||||
|
||||
<a href="{{unbound lastPostUrl}}" class="last-posted-at">{{age last_posted_at}}</a>
|
||||
<a href="{{unbound lastPostUrl}}" class="last-posted-at">{{format-age last_posted_at}}</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/each}}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<div class='item'>
|
||||
<div class='clearfix info'>
|
||||
{{#link-to 'user' user class="avatar-link"}}<div class='avatar-wrapper'>{{avatar user imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div>{{/link-to}}
|
||||
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span>
|
||||
<span class='time'>{{format-date path="created_at" leaveAgo="true"}}</span>
|
||||
<span class="title">
|
||||
<a href="{{unbound url}}">{{unbound title}}</a>
|
||||
</span>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
</div>
|
||||
</td>
|
||||
<td class='num posts'>{{number posts_count}}</td>
|
||||
<td class='num age'><span class="{{cold-age-class created_at}}" title='{{raw-date created_at}}'>{{{age created_at}}}</span></td>
|
||||
<td class='num age'><span class="{{cold-age-class created_at}}" title='{{raw-date created_at}}'>{{{format-age created_at}}}</span></td>
|
||||
</tr>
|
||||
|
||||
{{/each}}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
</span>
|
||||
{{#unless controller.site.mobileView}}
|
||||
<span class='blurb'>
|
||||
{{age created_at}} - {{{unbound blurb}}}
|
||||
{{format-age created_at}} - {{{unbound blurb}}}
|
||||
</span>
|
||||
{{/unless}}
|
||||
</a>
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
{{#if user}}
|
||||
<div class="metadata">
|
||||
{{#if user.location}}<h3>{{fa-icon "map-marker"}} {{user.location}}</h3>{{/if}}
|
||||
<h3>{{i18n last_post}} {{date path="user.last_posted_at" leaveAgo="true"}}</h3>
|
||||
<h3>{{i18n joined}} {{date path="user.created_at" leaveAgo="true"}}</h3>
|
||||
<h3>{{i18n last_post}} {{format-date path="user.last_posted_at" leaveAgo="true"}}</h3>
|
||||
<h3>{{i18n joined}} {{format-date path="user.created_at" leaveAgo="true"}}</h3>
|
||||
{{groups-list groups=user.custom_groups}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
{{#link-to 'user' invite.user}}{{avatar invite.user imageSize="tiny"}}{{/link-to}}
|
||||
{{#link-to 'user' invite.user}}{{invite.user.username}}{{/link-to}}
|
||||
</td>
|
||||
<td>{{date invite.redeemed_at}}</td>
|
||||
<td>{{format-date invite.redeemed_at}}</td>
|
||||
{{#if can_see_invite_details}}
|
||||
<td>{{date invite.user.last_seen_at}}</td>
|
||||
<td>{{format-date invite.user.last_seen_at}}</td>
|
||||
<td>{{number invite.user.topics_entered}}</td>
|
||||
<td>{{number invite.user.posts_read_count}}</td>
|
||||
<td>{{{unbound invite.user.time_read}}}</td>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<div {{bind-attr class=":item :notification read::unread"}}>
|
||||
{{notification-item notification=this scope=scope}}
|
||||
<span class="time">
|
||||
{{date path="created_at" leaveAgo="true"}}
|
||||
{{format-date path="created_at" leaveAgo="true"}}
|
||||
</span>
|
||||
</div>
|
||||
{{/each}}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</div>
|
||||
</a>
|
||||
<span class="time">
|
||||
{{date path="created_at" leaveAgo="true"}}
|
||||
{{format-date path="created_at" leaveAgo="true"}}
|
||||
</span>
|
||||
<span class="title">
|
||||
<a href="{{unbound url}}">{{unbound topic_title}}</a>
|
||||
|
@ -17,7 +17,7 @@
|
|||
</span>
|
||||
{{#if deleted}}
|
||||
<span class="delete-info">
|
||||
<i class="fa fa-trash-o"></i> {{avatar deleted_by imageSize="tiny" extraClasses="actor" ignoreTitle="true"}} {{date path="deleted_at" leaveAgo="true"}}
|
||||
<i class="fa fa-trash-o"></i> {{avatar deleted_by imageSize="tiny" extraClasses="actor" ignoreTitle="true"}} {{format-date path="deleted_at" leaveAgo="true"}}
|
||||
</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div {{bind-attr class=":item hidden deleted moderator_action"}}>
|
||||
<div class='clearfix info'>
|
||||
<a href="{{unbound userUrl}}" data-user-expand="{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
|
||||
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span>
|
||||
<span class='time'>{{format-date path="created_at" leaveAgo="true"}}</span>
|
||||
<span class="title">
|
||||
<a href="{{unbound postUrl}}">{{unbound title}}</a>
|
||||
</span>
|
||||
|
|
Loading…
Reference in New Issue
Block a user