mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
FEATURE: Show edit indicator on review queue
If a flagged post has edits, show the pencil icon and pop up the history window when clicked.
This commit is contained in:
parent
5f78bbebe9
commit
15c9b00307
@ -0,0 +1,33 @@
|
|||||||
|
import computed from "ember-addons/ember-computed-decorators";
|
||||||
|
import { longDate } from "discourse/lib/formatter";
|
||||||
|
import { historyHeat } from "discourse/widgets/post-edits-indicator";
|
||||||
|
import showModal from "discourse/lib/show-modal";
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
hasEdits: Ember.computed.gt("reviewable.version", 1),
|
||||||
|
|
||||||
|
@computed("reviewable.post_updated_at")
|
||||||
|
historyClass(updatedAt) {
|
||||||
|
return historyHeat(this.siteSettings, new Date(updatedAt));
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed("reviewable.post_updated_at")
|
||||||
|
editedDate(updatedAt) {
|
||||||
|
return longDate(updatedAt);
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
showEditHistory() {
|
||||||
|
let postId = this.get("reviewable.post_id");
|
||||||
|
this.store.find("post", postId).then(post => {
|
||||||
|
let historyController = showModal("history", {
|
||||||
|
model: post,
|
||||||
|
modalClass: "history-modal"
|
||||||
|
});
|
||||||
|
historyController.refresh(postId, "latest");
|
||||||
|
historyController.set("post", post);
|
||||||
|
historyController.set("topicController", null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@ -152,9 +152,14 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
return !prevHidden && this.currentUser && this.currentUser.get("staff");
|
return !prevHidden && this.currentUser && this.currentUser.get("staff");
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("model.last_revision", "model.current_revision", "model.can_edit")
|
@computed(
|
||||||
displayEdit(lastRevision, currentRevision, canEdit) {
|
"model.last_revision",
|
||||||
return canEdit && lastRevision === currentRevision;
|
"model.current_revision",
|
||||||
|
"model.can_edit",
|
||||||
|
"topicController"
|
||||||
|
)
|
||||||
|
displayEdit(lastRevision, currentRevision, canEdit, topicController) {
|
||||||
|
return !!(canEdit && topicController && lastRevision === currentRevision);
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("model.wiki")
|
@computed("model.wiki")
|
||||||
|
@ -118,14 +118,13 @@ const TopicRoute = Discourse.Route.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
showHistory(model, revision) {
|
showHistory(model, revision) {
|
||||||
showModal("history", { model });
|
let historyController = showModal("history", {
|
||||||
const historyController = this.controllerFor("history");
|
model,
|
||||||
|
modalClass: "history-modal"
|
||||||
|
});
|
||||||
historyController.refresh(model.get("id"), revision || "latest");
|
historyController.refresh(model.get("id"), revision || "latest");
|
||||||
historyController.set("post", model);
|
historyController.set("post", model);
|
||||||
historyController.set("topicController", this.controllerFor("topic"));
|
historyController.set("topicController", this.controllerFor("topic"));
|
||||||
|
|
||||||
this.controllerFor("modal").set("modalClass", "history-modal");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
showGrantBadgeModal() {
|
showGrantBadgeModal() {
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
{{reviewable-topic-link reviewable=reviewable tagName=''}}
|
<div class='flagged-post-header'>
|
||||||
|
{{reviewable-topic-link reviewable=reviewable tagName=''}}
|
||||||
|
{{#if hasEdits}}
|
||||||
|
<a {{action "showEditHistory"}}
|
||||||
|
class="has-edits {{historyClass}}"
|
||||||
|
title="{{i18n "post.last_edited_on"}} {{editedDate}}">
|
||||||
|
{{d-icon "pencil-alt"}}
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class='post-contents-wrapper'>
|
<div class='post-contents-wrapper'>
|
||||||
{{reviewable-created-by user=reviewable.target_created_by tagName=''}}
|
{{reviewable-created-by user=reviewable.target_created_by tagName=''}}
|
||||||
<div class='post-contents'>
|
<div class='post-contents'>
|
||||||
{{reviewable-created-by-name user=reviewable.target_created_by tagName=''}}
|
{{reviewable-created-by-name user=reviewable.target_created_by tagName=''}}
|
||||||
<div class='post-body'>
|
<div class='post-body'>
|
||||||
|
|
||||||
{{#if reviewable.blank_post}}
|
{{#if reviewable.blank_post}}
|
||||||
<p>{{i18n "review.deleted_post"}}</p>
|
<p>{{i18n "review.deleted_post"}}</p>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
@ -122,23 +122,25 @@
|
|||||||
{{/links-redirect}}
|
{{/links-redirect}}
|
||||||
</div>
|
</div>
|
||||||
{{/d-modal-body}}
|
{{/d-modal-body}}
|
||||||
<div class="modal-footer">
|
{{#if topicController}}
|
||||||
{{#if displayRevert}}
|
<div class="modal-footer">
|
||||||
{{d-button action=(action "revertToVersion") icon="undo" label="post.revisions.controls.revert" class="btn-danger" disabled=loading}}
|
{{#if displayRevert}}
|
||||||
{{/if}}
|
{{d-button action=(action "revertToVersion") icon="undo" label="post.revisions.controls.revert" class="btn-danger" disabled=loading}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#if displayHide}}
|
{{#if displayHide}}
|
||||||
{{d-button action=(action "hideVersion") icon="far-eye-slash" label="post.revisions.controls.hide" class="btn-danger" disabled=loading}}
|
{{d-button action=(action "hideVersion") icon="far-eye-slash" label="post.revisions.controls.hide" class="btn-danger" disabled=loading}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if displayShow}}
|
{{#if displayShow}}
|
||||||
{{d-button action=(action "showVersion") icon="far-eye" label="post.revisions.controls.show" class="btn-default" disabled=loading}}
|
{{d-button action=(action "showVersion") icon="far-eye" label="post.revisions.controls.show" class="btn-default" disabled=loading}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if displayEdit}}
|
{{#if displayEdit}}
|
||||||
{{d-button action=(action "editPost")
|
{{d-button action=(action "editPost")
|
||||||
icon="pencil-alt"
|
icon="pencil-alt"
|
||||||
class="btn-default"
|
class="btn-default"
|
||||||
label=editButtonLabel}}
|
label=editButtonLabel}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
@ -3,39 +3,39 @@ import { iconNode } from "discourse-common/lib/icon-library";
|
|||||||
import { longDate } from "discourse/lib/formatter";
|
import { longDate } from "discourse/lib/formatter";
|
||||||
import { h } from "virtual-dom";
|
import { h } from "virtual-dom";
|
||||||
|
|
||||||
const FIFTY_HOURS = 60 * 50 * 1000;
|
function mult(val) {
|
||||||
|
return 60 * 50 * 1000 * val;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function historyHeat(siteSettings, updatedAt) {
|
||||||
|
if (!updatedAt) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show heat on age
|
||||||
|
const rightNow = new Date().getTime();
|
||||||
|
const updatedAtTime = updatedAt.getTime();
|
||||||
|
|
||||||
|
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_low)) {
|
||||||
|
return "heatmap-high";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_medium)) {
|
||||||
|
return "heatmap-med";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_high)) {
|
||||||
|
return "heatmap-low";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default createWidget("post-edits-indicator", {
|
export default createWidget("post-edits-indicator", {
|
||||||
tagName: "div.post-info.edits",
|
tagName: "div.post-info.edits",
|
||||||
|
|
||||||
historyHeat(updatedAt) {
|
|
||||||
if (!updatedAt) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show heat on age
|
|
||||||
const rightNow = new Date().getTime();
|
|
||||||
const updatedAtTime = updatedAt.getTime();
|
|
||||||
|
|
||||||
const siteSettings = this.siteSettings;
|
|
||||||
if (updatedAtTime > rightNow - FIFTY_HOURS * siteSettings.history_hours_low)
|
|
||||||
return "heatmap-high";
|
|
||||||
if (
|
|
||||||
updatedAtTime >
|
|
||||||
rightNow - FIFTY_HOURS * siteSettings.history_hours_medium
|
|
||||||
)
|
|
||||||
return "heatmap-med";
|
|
||||||
if (
|
|
||||||
updatedAtTime >
|
|
||||||
rightNow - FIFTY_HOURS * siteSettings.history_hours_high
|
|
||||||
)
|
|
||||||
return "heatmap-low";
|
|
||||||
},
|
|
||||||
|
|
||||||
html(attrs) {
|
html(attrs) {
|
||||||
let icon = "pencil-alt";
|
let icon = "pencil-alt";
|
||||||
const updatedAt = new Date(attrs.updated_at);
|
const updatedAt = new Date(attrs.updated_at);
|
||||||
let className = this.historyHeat(updatedAt);
|
let className = historyHeat(this.siteSettings, updatedAt);
|
||||||
const date = longDate(updatedAt);
|
const date = longDate(updatedAt);
|
||||||
let title;
|
let title;
|
||||||
|
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
.reviewable {
|
.reviewable {
|
||||||
|
.flagged-post-header {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
.status {
|
.status {
|
||||||
color: $primary-medium;
|
color: $primary-medium;
|
||||||
span.approved {
|
span.approved {
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
class ReviewableFlaggedPostSerializer < ReviewableSerializer
|
class ReviewableFlaggedPostSerializer < ReviewableSerializer
|
||||||
target_attributes :cooked, :raw, :reply_count
|
target_attributes :cooked, :raw, :reply_count, :version
|
||||||
attributes :blank_post
|
attributes :blank_post, :post_updated_at
|
||||||
|
|
||||||
|
def post_updated_at
|
||||||
|
object.target&.updated_at
|
||||||
|
end
|
||||||
|
|
||||||
def blank_post
|
def blank_post
|
||||||
true
|
true
|
||||||
|
@ -4,7 +4,8 @@ QUnit.test("displayEdit", function(assert) {
|
|||||||
const HistoryController = this.subject();
|
const HistoryController = this.subject();
|
||||||
|
|
||||||
HistoryController.setProperties({
|
HistoryController.setProperties({
|
||||||
model: { last_revision: 3, current_revision: 3, can_edit: false }
|
model: { last_revision: 3, current_revision: 3, can_edit: false },
|
||||||
|
topicController: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@ -21,6 +22,14 @@ QUnit.test("displayEdit", function(assert) {
|
|||||||
"it should display edit button when user can edit the post"
|
"it should display edit button when user can edit the post"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
HistoryController.set("topicController", null);
|
||||||
|
assert.equal(
|
||||||
|
HistoryController.get("displayEdit"),
|
||||||
|
false,
|
||||||
|
"it should not display edit button when there is not topic controller"
|
||||||
|
);
|
||||||
|
HistoryController.set("topicController", {});
|
||||||
|
|
||||||
HistoryController.set("model.current_revision", 2);
|
HistoryController.set("model.current_revision", 2);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
HistoryController.get("displayEdit"),
|
HistoryController.get("displayEdit"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user