Move deleted at into actions history, where it should be.

This commit is contained in:
Robin Ward 2013-07-29 14:46:25 -04:00
parent 323aea78e2
commit 08ebaf926b
3 changed files with 55 additions and 45 deletions

View File

@ -25,6 +25,7 @@ Discourse.Post = Discourse.Model.extend({
// Posts can show up as deleted if the topic is deleted // Posts can show up as deleted if the topic is deleted
deletedViaTopic: Em.computed.and('firstPost', 'topic.deleted_at'), deletedViaTopic: Em.computed.and('firstPost', 'topic.deleted_at'),
deleted: Em.computed.or('deleted_at', 'deletedViaTopic'), deleted: Em.computed.or('deleted_at', 'deletedViaTopic'),
notDeleted: Em.computed.not('deleted'),
postDeletedBy: function() { postDeletedBy: function() {
if (this.get('firstPost')) { return this.get('topic.deleted_by'); } if (this.get('firstPost')) { return this.get('topic.deleted_by'); }

View File

@ -53,14 +53,7 @@
{{view Discourse.PostMenuView postBinding="this" postViewBinding="view"}} {{view Discourse.PostMenuView postBinding="this" postViewBinding="view"}}
</div> </div>
{{view Discourse.RepliesView contentBinding="replies" postViewBinding="view"}} {{view Discourse.RepliesView contentBinding="replies" postViewBinding="view"}}
{{view Discourse.ActionsHistoryView contentBinding="actionsHistory"}} {{view Discourse.ActionsHistoryView postBinding="this"}}
{{#if deleted}}
<div class='post-actions'>
{{i18n post.deleted_by}} {{avatar postDeletedBy imageSize="tiny"}} {{unboundAge postDeletedAt}}
</div>
{{/if}}
{{view Discourse.TopicSummaryView postBinding="this"}} {{view Discourse.TopicSummaryView postBinding="this"}}
</div> </div>

View File

@ -10,51 +10,67 @@
Discourse.ActionsHistoryView = Discourse.View.extend({ Discourse.ActionsHistoryView = Discourse.View.extend({
tagName: 'section', tagName: 'section',
classNameBindings: [':post-actions', 'hidden'], classNameBindings: [':post-actions', 'hidden'],
hidden: Em.computed.empty('content'), content: Em.computed.alias('post.actionsHistory'),
shouldRerender: Discourse.View.renderIfChanged('content.@each', 'content.users.length'), noContent: Em.computed.empty('content'),
hidden: Em.computed.and('noContent', 'post.notDeleted'),
shouldRerender: Discourse.View.renderIfChanged('content.@each', 'content.users.length', 'post.deleted'),
// This was creating way too many bound ifs and subviews in the handlebars version. // This was creating way too many bound ifs and subviews in the handlebars version.
render: function(buffer) { render: function(buffer) {
if (!this.present('content')) return;
this.get('content').forEach(function(c) { var renderAvatar = function() {
buffer.push("<div class='post-action'>");
var renderActionIf = function(property, dataAttribute, text) { }
if (!c.get(property)) { return; }
buffer.push(" <a href='#' data-" + dataAttribute + "='" + c.get('id') + "'>" + text + "</a>.");
};
// TODO multi line expansion for flags if (this.present('content')) {
var iconsHtml = ""; this.get('content').forEach(function(c) {
if (c.get('usersExpanded')) { buffer.push("<div class='post-action'>");
var postUrl;
c.get('users').forEach(function(u) { var renderActionIf = function(property, dataAttribute, text) {
iconsHtml += "<a href=\"" + Discourse.getURL("/users/") + (u.get('username_lower')) + "\">"; if (!c.get(property)) { return; }
if (u.post_url) { buffer.push(" <a href='#' data-" + dataAttribute + "='" + c.get('id') + "'>" + text + "</a>.");
postUrl = postUrl || u.post_url; };
}
iconsHtml += Discourse.Utilities.avatarImg({ // TODO multi line expansion for flags
size: 'small', var iconsHtml = "";
username: u.get('username'), if (c.get('usersExpanded')) {
avatarTemplate: u.get('avatar_template'), var postUrl;
title: u.get('username') c.get('users').forEach(function(u) {
iconsHtml += "<a href=\"" + Discourse.getURL("/users/") + (u.get('username_lower')) + "\">";
if (u.post_url) {
postUrl = postUrl || u.post_url;
}
iconsHtml += Discourse.Utilities.avatarImg({
size: 'small',
username: u.get('username'),
avatarTemplate: u.get('avatar_template'),
title: u.get('username')
});
iconsHtml += "</a>";
}); });
iconsHtml += "</a>";
});
var key = 'post.actions.people.' + c.get('actionType.name_key'); var key = 'post.actions.people.' + c.get('actionType.name_key');
if (postUrl) { key = key + "_with_url"; } if (postUrl) { key = key + "_with_url"; }
buffer.push(" " + I18n.t(key, { icons: iconsHtml, postUrl: postUrl}) + "."); buffer.push(" " + I18n.t(key, { icons: iconsHtml, postUrl: postUrl}) + ".");
} }
renderActionIf('usersCollapsed', 'who-acted', c.get('description')); renderActionIf('usersCollapsed', 'who-acted', c.get('description'));
renderActionIf('canAlsoAction', 'act', I18n.t("post.actions.it_too." + c.get('actionType.name_key'))); renderActionIf('canAlsoAction', 'act', I18n.t("post.actions.it_too." + c.get('actionType.name_key')));
renderActionIf('can_undo', 'undo', I18n.t("post.actions.undo." + c.get('actionType.name_key'))); renderActionIf('can_undo', 'undo', I18n.t("post.actions.undo." + c.get('actionType.name_key')));
renderActionIf('can_clear_flags', 'clear-flags', I18n.t("post.actions.clear_flags", { count: c.count })); renderActionIf('can_clear_flags', 'clear-flags', I18n.t("post.actions.clear_flags", { count: c.count }));
buffer.push("</div>"); buffer.push("</div>");
}); });
}
var post = this.get('post');
if (post.get('deleted')) {
buffer.push("<div class='post-action'>" +
I18n.t("post.deleted_by") + " " +
Discourse.Utilities.tinyAvatar(post.get('postDeletedBy.username')) +
Discourse.Formatter.autoUpdatingRelativeAge(new Date(post.get('postDeletedAt'))) +
"</div>");
}
}, },
actionTypeById: function(actionTypeId) { actionTypeById: function(actionTypeId) {
@ -77,12 +93,12 @@ Discourse.ActionsHistoryView = Discourse.View.extend({
} }
if (actionTypeId = $target.data('act')) { if (actionTypeId = $target.data('act')) {
this.content.findProperty('id', actionTypeId).act(); this.get('content').findProperty('id', actionTypeId).act();
return false; return false;
} }
if (actionTypeId = $target.data('undo')) { if (actionTypeId = $target.data('undo')) {
this.content.findProperty('id', actionTypeId).undo(); this.get('content').findProperty('id', actionTypeId).undo();
return false; return false;
} }