mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: Can sort reviewable queue
Choices are Priority / Created At (and desc versions.)
This commit is contained in:
parent
de013262a7
commit
d902c4eb9f
7 changed files with 67 additions and 8 deletions
|
@ -7,7 +7,8 @@ export default Ember.Controller.extend({
|
||||||
"status",
|
"status",
|
||||||
"category_id",
|
"category_id",
|
||||||
"topic_id",
|
"topic_id",
|
||||||
"username"
|
"username",
|
||||||
|
"sort_order"
|
||||||
],
|
],
|
||||||
type: null,
|
type: null,
|
||||||
status: "pending",
|
status: "pending",
|
||||||
|
@ -17,6 +18,7 @@ export default Ember.Controller.extend({
|
||||||
topic_id: null,
|
topic_id: null,
|
||||||
filtersExpanded: false,
|
filtersExpanded: false,
|
||||||
username: "",
|
username: "",
|
||||||
|
sort_order: "priority",
|
||||||
|
|
||||||
init(...args) {
|
init(...args) {
|
||||||
this._super(...args);
|
this._super(...args);
|
||||||
|
@ -44,6 +46,18 @@ export default Ember.Controller.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed
|
||||||
|
sortOrders() {
|
||||||
|
return ["priority", "priority_asc", "created_at", "created_at_asc"].map(
|
||||||
|
order => {
|
||||||
|
return {
|
||||||
|
id: order,
|
||||||
|
name: I18n.t(`review.filters.orders.${order}`)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
statuses() {
|
statuses() {
|
||||||
return [
|
return [
|
||||||
|
@ -86,7 +100,8 @@ export default Ember.Controller.extend({
|
||||||
priority: this.filterPriority,
|
priority: this.filterPriority,
|
||||||
status: this.filterStatus,
|
status: this.filterStatus,
|
||||||
category_id: this.filterCategoryId,
|
category_id: this.filterCategoryId,
|
||||||
username: this.filterUsername
|
username: this.filterUsername,
|
||||||
|
sort_order: this.filterSortOrder
|
||||||
});
|
});
|
||||||
this.send("refreshRoute");
|
this.send("refreshRoute");
|
||||||
},
|
},
|
||||||
|
|
|
@ -20,7 +20,8 @@ export default Discourse.Route.extend({
|
||||||
filterCategoryId: meta.category_id,
|
filterCategoryId: meta.category_id,
|
||||||
filterPriority: meta.priority,
|
filterPriority: meta.priority,
|
||||||
reviewableTypes: meta.reviewable_types,
|
reviewableTypes: meta.reviewable_types,
|
||||||
filterUsername: meta.username
|
filterUsername: meta.username,
|
||||||
|
filterSortOrder: meta.sort_order
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,11 @@
|
||||||
{{d-button label="review.show_all_topics" icon="times" action=(action "resetTopic")}}
|
{{d-button label="review.show_all_topics" icon="times" action=(action "resetTopic")}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
<div class='reviewable-filter sort-order'>
|
||||||
|
{{i18n "review.order_by"}}
|
||||||
|
{{combo-box value=filterSortOrder content=sortOrders}}
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class='reviewable-filters-actions'>
|
<div class='reviewable-filters-actions'>
|
||||||
|
|
|
@ -26,7 +26,8 @@ class ReviewablesController < ApplicationController
|
||||||
topic_id: topic_id,
|
topic_id: topic_id,
|
||||||
priority: params[:priority],
|
priority: params[:priority],
|
||||||
username: params[:username],
|
username: params[:username],
|
||||||
type: params[:type]
|
type: params[:type],
|
||||||
|
sort_order: params[:sort_order]
|
||||||
}
|
}
|
||||||
|
|
||||||
total_rows = Reviewable.list_for(current_user, filters).count
|
total_rows = Reviewable.list_for(current_user, filters).count
|
||||||
|
|
|
@ -383,10 +383,21 @@ class Reviewable < ActiveRecord::Base
|
||||||
limit: nil,
|
limit: nil,
|
||||||
offset: nil,
|
offset: nil,
|
||||||
priority: nil,
|
priority: nil,
|
||||||
username: nil
|
username: nil,
|
||||||
|
sort_order: nil
|
||||||
)
|
)
|
||||||
min_score = Reviewable.min_score_for_priority(priority)
|
min_score = Reviewable.min_score_for_priority(priority)
|
||||||
order = (status == :pending) ? 'score DESC, created_at DESC' : 'created_at DESC'
|
|
||||||
|
order = case sort_order
|
||||||
|
when 'priority_asc'
|
||||||
|
'score ASC, created_at DESC'
|
||||||
|
when 'created_at'
|
||||||
|
'created_at DESC, score DESC'
|
||||||
|
when 'created_at_asc'
|
||||||
|
'created_at ASC, score DESC'
|
||||||
|
else
|
||||||
|
'score DESC, created_at DESC'
|
||||||
|
end
|
||||||
|
|
||||||
if username.present?
|
if username.present?
|
||||||
user_id = User.find_by_username(username)&.id
|
user_id = User.find_by_username(username)&.id
|
||||||
|
|
|
@ -363,6 +363,7 @@ en:
|
||||||
placeholder: "type the message title here"
|
placeholder: "type the message title here"
|
||||||
|
|
||||||
review:
|
review:
|
||||||
|
order_by: "Order by"
|
||||||
in_reply_to: "in reply to"
|
in_reply_to: "in reply to"
|
||||||
claim_help:
|
claim_help:
|
||||||
optional: "You can claim this item to prevent others from reviewing it."
|
optional: "You can claim this item to prevent others from reviewing it."
|
||||||
|
@ -442,6 +443,12 @@ en:
|
||||||
refresh: "Refresh"
|
refresh: "Refresh"
|
||||||
status: "Status"
|
status: "Status"
|
||||||
category: "Category"
|
category: "Category"
|
||||||
|
orders:
|
||||||
|
priority: "Priority"
|
||||||
|
priority_asc: "Priority (reverse)"
|
||||||
|
created_at: "Created At"
|
||||||
|
created_at_asc: "Created At (reverse)"
|
||||||
|
|
||||||
priority:
|
priority:
|
||||||
title: "Minimum Priority"
|
title: "Minimum Priority"
|
||||||
low: "Low"
|
low: "Low"
|
||||||
|
|
|
@ -151,11 +151,30 @@ RSpec.describe Reviewable, type: :model do
|
||||||
|
|
||||||
it 'Does not filter by status when status parameter is set to all' do
|
it 'Does not filter by status when status parameter is set to all' do
|
||||||
rejected_reviewable = Fabricate(:reviewable, target: post, status: Reviewable.statuses[:rejected])
|
rejected_reviewable = Fabricate(:reviewable, target: post, status: Reviewable.statuses[:rejected])
|
||||||
|
|
||||||
reviewables = Reviewable.list_for(user, status: :all)
|
reviewables = Reviewable.list_for(user, status: :all)
|
||||||
|
|
||||||
expect(reviewables).to match_array [reviewable, rejected_reviewable]
|
expect(reviewables).to match_array [reviewable, rejected_reviewable]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "supports sorting" do
|
||||||
|
r0 = Fabricate(:reviewable, score: 100, created_at: 3.months.ago)
|
||||||
|
r1 = Fabricate(:reviewable, score: 999, created_at: 1.month.ago)
|
||||||
|
|
||||||
|
list = Reviewable.list_for(user, sort_order: 'priority')
|
||||||
|
expect(list[0].id).to eq(r1.id)
|
||||||
|
expect(list[1].id).to eq(r0.id)
|
||||||
|
|
||||||
|
list = Reviewable.list_for(user, sort_order: 'priority_asc')
|
||||||
|
expect(list[0].id).to eq(r0.id)
|
||||||
|
expect(list[1].id).to eq(r1.id)
|
||||||
|
|
||||||
|
list = Reviewable.list_for(user, sort_order: 'created_at')
|
||||||
|
expect(list[0].id).to eq(r1.id)
|
||||||
|
expect(list[1].id).to eq(r0.id)
|
||||||
|
|
||||||
|
list = Reviewable.list_for(user, sort_order: 'created_at_asc')
|
||||||
|
expect(list[0].id).to eq(r0.id)
|
||||||
|
expect(list[1].id).to eq(r1.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue