2014-08-13 07:04:36 +08:00
|
|
|
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
|
|
|
|
|
|
|
import ObjectController from 'discourse/controllers/object';
|
|
|
|
|
2013-05-31 02:12:33 +08:00
|
|
|
/**
|
|
|
|
This controller handles displaying of history
|
|
|
|
|
|
|
|
@class HistoryController
|
2014-08-13 07:04:36 +08:00
|
|
|
@extends ObjectController
|
2013-05-31 02:12:33 +08:00
|
|
|
@namespace Discourse
|
2014-08-13 07:04:36 +08:00
|
|
|
@uses ModalFunctionality
|
2013-05-31 02:12:33 +08:00
|
|
|
@module Discourse
|
|
|
|
**/
|
2014-08-13 07:04:36 +08:00
|
|
|
export default ObjectController.extend(ModalFunctionality, {
|
2014-10-28 05:06:43 +08:00
|
|
|
loading: true,
|
2014-10-28 05:18:10 +08:00
|
|
|
viewMode: "side_by_side",
|
2014-03-15 00:25:02 +08:00
|
|
|
revisionsTextKey: "post.revisions.controls.comparing_previous_to_current_out_of_total",
|
2013-05-31 02:12:33 +08:00
|
|
|
|
2014-10-28 05:18:10 +08:00
|
|
|
_changeViewModeOnMobile: function() {
|
|
|
|
if (Discourse.Mobile.mobileView) { this.set("viewMode", "inline"); }
|
|
|
|
}.on("init"),
|
|
|
|
|
2013-12-12 10:41:34 +08:00
|
|
|
refresh: function(postId, postVersion) {
|
2014-03-12 01:51:26 +08:00
|
|
|
this.set("loading", true);
|
2013-05-31 02:12:33 +08:00
|
|
|
|
2013-12-12 10:41:34 +08:00
|
|
|
var self = this;
|
|
|
|
Discourse.Post.loadRevision(postId, postVersion).then(function (result) {
|
2014-03-12 01:51:26 +08:00
|
|
|
self.setProperties({ loading: false, model: result });
|
2013-12-12 10:41:34 +08:00
|
|
|
});
|
2013-05-31 02:12:33 +08:00
|
|
|
},
|
|
|
|
|
2014-10-13 16:18:49 +08:00
|
|
|
hide: function(postId, postVersion) {
|
|
|
|
var self = this;
|
|
|
|
Discourse.Post.hideRevision(postId, postVersion).then(function (result) {
|
|
|
|
self.refresh(postId, postVersion);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function(postId, postVersion) {
|
|
|
|
var self = this;
|
|
|
|
Discourse.Post.showRevision(postId, postVersion).then(function (result) {
|
|
|
|
self.refresh(postId, postVersion);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-12-12 10:41:34 +08:00
|
|
|
createdAtDate: function() { return moment(this.get("created_at")).format("LLLL"); }.property("created_at"),
|
2013-05-31 02:12:33 +08:00
|
|
|
|
2014-10-28 05:06:43 +08:00
|
|
|
previousVersion: function() { return this.get("current_version") - 1; }.property("current_version"),
|
2013-05-31 02:12:33 +08:00
|
|
|
|
2014-10-28 05:06:43 +08:00
|
|
|
displayGoToFirst: function() { return this.get("current_revision") > this.get("first_revision"); }.property("current_revision", "first_revision"),
|
|
|
|
displayGoToPrevious: function() { return this.get("previous_revision") && this.get("current_revision") > this.get("previous_revision"); }.property("current_revision", "previous_revision"),
|
|
|
|
displayRevisions: Em.computed.gt("version_count", 2),
|
|
|
|
displayGoToNext: function() { return this.get("next_revision") && this.get("current_revision") < this.get("next_revision"); }.property("current_revision", "next_revision"),
|
|
|
|
displayGoToLast: function() { return this.get("current_revision") < this.get("last_revision"); }.property("current_revision", "last_revision"),
|
2013-05-31 02:12:33 +08:00
|
|
|
|
2014-10-28 22:56:24 +08:00
|
|
|
displayShow: function() { return this.get("previous_hidden") && Discourse.User.currentProp('staff') && !this.get("loading"); }.property("previous_hidden", "loading"),
|
|
|
|
displayHide: function() { return !this.get("previous_hidden") && Discourse.User.currentProp('staff') && !this.get("loading"); }.property("previous_hidden", "loading"),
|
2014-10-28 05:06:43 +08:00
|
|
|
|
|
|
|
isEitherRevisionHidden: Em.computed.or("previous_hidden", "current_hidden"),
|
|
|
|
|
|
|
|
hiddenClasses: function() {
|
|
|
|
if (this.get("displayingInline")) {
|
|
|
|
return this.get("isEitherRevisionHidden") ? "hidden-revision-either" : null;
|
|
|
|
} else {
|
|
|
|
var result = [];
|
|
|
|
if (this.get("previous_hidden")) { result.push("hidden-revision-previous"); }
|
|
|
|
if (this.get("current_hidden")) { result.push("hidden-revision-current"); }
|
|
|
|
return result.join(" ");
|
|
|
|
}
|
|
|
|
}.property("previous_hidden", "current_hidden", "displayingInline"),
|
2014-10-13 16:18:49 +08:00
|
|
|
|
2013-12-12 10:41:34 +08:00
|
|
|
displayingInline: Em.computed.equal("viewMode", "inline"),
|
|
|
|
displayingSideBySide: Em.computed.equal("viewMode", "side_by_side"),
|
|
|
|
displayingSideBySideMarkdown: Em.computed.equal("viewMode", "side_by_side_markdown"),
|
2013-05-31 02:12:33 +08:00
|
|
|
|
2014-10-28 05:06:43 +08:00
|
|
|
previousCategory: function() {
|
2014-03-07 15:59:47 +08:00
|
|
|
var changes = this.get("category_changes");
|
2014-10-28 05:06:43 +08:00
|
|
|
if (changes) {
|
|
|
|
var category = Discourse.Category.findById(changes["previous"]);
|
|
|
|
return Discourse.HTML.categoryBadge(category, { allowUncategorized: true });
|
2014-03-07 15:59:47 +08:00
|
|
|
}
|
2014-10-28 05:06:43 +08:00
|
|
|
}.property("category_changes"),
|
2014-03-07 15:59:47 +08:00
|
|
|
|
2014-10-28 05:06:43 +08:00
|
|
|
currentCategory: function() {
|
|
|
|
var changes = this.get("category_changes");
|
|
|
|
if (changes) {
|
|
|
|
var category = Discourse.Category.findById(changes["current"]);
|
|
|
|
return Discourse.HTML.categoryBadge(category, { allowUncategorized: true });
|
|
|
|
}
|
|
|
|
}.property("category_changes"),
|
2014-05-13 20:53:11 +08:00
|
|
|
|
|
|
|
wiki_diff: function() {
|
2014-10-28 05:06:43 +08:00
|
|
|
var changes = this.get("wiki_changes")
|
|
|
|
if (changes) {
|
|
|
|
return changes["current"] ?
|
|
|
|
'<span class="fa-stack"><i class="fa fa-pencil-square-o fa-stack-2x"></i></span>' :
|
|
|
|
'<span class="fa-stack"><i class="fa fa-pencil-square-o fa-stack-2x"></i><i class="fa fa-ban fa-stack-2x"></i></span>';
|
2014-05-13 20:53:11 +08:00
|
|
|
}
|
2014-10-28 05:06:43 +08:00
|
|
|
}.property("wiki_changes"),
|
2014-09-11 05:08:33 +08:00
|
|
|
|
|
|
|
post_type_diff: function () {
|
|
|
|
var moderator = Discourse.Site.currentProp('post_types.moderator_action');
|
2014-10-28 05:06:43 +08:00
|
|
|
var changes = this.get("post_type_changes");
|
|
|
|
if (changes) {
|
|
|
|
return changes["current"] == moderator ?
|
|
|
|
'<span class="fa-stack"><i class="fa fa-shield fa-stack-2x"></i></span>' :
|
|
|
|
'<span class="fa-stack"><i class="fa fa-shield fa-stack-2x"></i><i class="fa fa-ban fa-stack-2x"></i></span>';
|
2014-09-11 05:08:33 +08:00
|
|
|
}
|
2014-10-28 05:06:43 +08:00
|
|
|
}.property("post_type_changes"),
|
2014-03-07 15:59:47 +08:00
|
|
|
|
|
|
|
title_diff: function() {
|
|
|
|
var viewMode = this.get("viewMode");
|
2014-10-28 05:06:43 +08:00
|
|
|
if (viewMode === "side_by_side_markdown") { viewMode = "side_by_side"; }
|
2014-03-07 15:59:47 +08:00
|
|
|
return this.get("title_changes." + viewMode);
|
2014-03-12 01:51:26 +08:00
|
|
|
}.property("viewMode", "title_changes"),
|
2014-03-07 15:59:47 +08:00
|
|
|
|
|
|
|
body_diff: function() {
|
|
|
|
return this.get("body_changes." + this.get("viewMode"));
|
2014-03-12 01:51:26 +08:00
|
|
|
}.property("viewMode", "body_changes"),
|
2013-06-17 23:56:50 +08:00
|
|
|
|
2013-12-12 10:41:34 +08:00
|
|
|
actions: {
|
2014-10-28 05:06:43 +08:00
|
|
|
loadFirstVersion: function() { this.refresh(this.get("post_id"), this.get("first_revision")); },
|
|
|
|
loadPreviousVersion: function() { this.refresh(this.get("post_id"), this.get("previous_revision")); },
|
|
|
|
loadNextVersion: function() { this.refresh(this.get("post_id"), this.get("next_revision")); },
|
|
|
|
loadLastVersion: function() { this.refresh(this.get("post_id"), this.get("last_revision")); },
|
2013-06-17 23:56:50 +08:00
|
|
|
|
2014-10-28 05:06:43 +08:00
|
|
|
hideVersion: function() { this.hide(this.get("post_id"), this.get("current_revision")); },
|
|
|
|
showVersion: function() { this.show(this.get("post_id"), this.get("current_revision")); },
|
2014-10-13 16:18:49 +08:00
|
|
|
|
2013-12-12 10:41:34 +08:00
|
|
|
displayInline: function() { this.set("viewMode", "inline"); },
|
|
|
|
displaySideBySide: function() { this.set("viewMode", "side_by_side"); },
|
|
|
|
displaySideBySideMarkdown: function() { this.set("viewMode", "side_by_side_markdown"); }
|
2013-05-31 02:12:33 +08:00
|
|
|
}
|
|
|
|
});
|