FEATURE: Can sort reviewable queue
Choices are Priority / Created At (and desc versions.)
This commit is contained in:
parent
de013262a7
commit
d902c4eb9f
|
@ -7,7 +7,8 @@ export default Ember.Controller.extend({
|
|||
"status",
|
||||
"category_id",
|
||||
"topic_id",
|
||||
"username"
|
||||
"username",
|
||||
"sort_order"
|
||||
],
|
||||
type: null,
|
||||
status: "pending",
|
||||
|
@ -17,6 +18,7 @@ export default Ember.Controller.extend({
|
|||
topic_id: null,
|
||||
filtersExpanded: false,
|
||||
username: "",
|
||||
sort_order: "priority",
|
||||
|
||||
init(...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
|
||||
statuses() {
|
||||
return [
|
||||
|
@ -86,7 +100,8 @@ export default Ember.Controller.extend({
|
|||
priority: this.filterPriority,
|
||||
status: this.filterStatus,
|
||||
category_id: this.filterCategoryId,
|
||||
username: this.filterUsername
|
||||
username: this.filterUsername,
|
||||
sort_order: this.filterSortOrder
|
||||
});
|
||||
this.send("refreshRoute");
|
||||
},
|
||||
|
|
|
@ -20,7 +20,8 @@ export default Discourse.Route.extend({
|
|||
filterCategoryId: meta.category_id,
|
||||
filterPriority: meta.priority,
|
||||
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")}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<div class='reviewable-filter sort-order'>
|
||||
{{i18n "review.order_by"}}
|
||||
{{combo-box value=filterSortOrder content=sortOrders}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<div class='reviewable-filters-actions'>
|
||||
|
|
|
@ -26,7 +26,8 @@ class ReviewablesController < ApplicationController
|
|||
topic_id: topic_id,
|
||||
priority: params[:priority],
|
||||
username: params[:username],
|
||||
type: params[:type]
|
||||
type: params[:type],
|
||||
sort_order: params[:sort_order]
|
||||
}
|
||||
|
||||
total_rows = Reviewable.list_for(current_user, filters).count
|
||||
|
|
|
@ -383,10 +383,21 @@ class Reviewable < ActiveRecord::Base
|
|||
limit: nil,
|
||||
offset: nil,
|
||||
priority: nil,
|
||||
username: nil
|
||||
username: nil,
|
||||
sort_order: nil
|
||||
)
|
||||
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?
|
||||
user_id = User.find_by_username(username)&.id
|
||||
|
|
|
@ -363,6 +363,7 @@ en:
|
|||
placeholder: "type the message title here"
|
||||
|
||||
review:
|
||||
order_by: "Order by"
|
||||
in_reply_to: "in reply to"
|
||||
claim_help:
|
||||
optional: "You can claim this item to prevent others from reviewing it."
|
||||
|
@ -442,6 +443,12 @@ en:
|
|||
refresh: "Refresh"
|
||||
status: "Status"
|
||||
category: "Category"
|
||||
orders:
|
||||
priority: "Priority"
|
||||
priority_asc: "Priority (reverse)"
|
||||
created_at: "Created At"
|
||||
created_at_asc: "Created At (reverse)"
|
||||
|
||||
priority:
|
||||
title: "Minimum Priority"
|
||||
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
|
||||
rejected_reviewable = Fabricate(:reviewable, target: post, status: Reviewable.statuses[:rejected])
|
||||
|
||||
reviewables = Reviewable.list_for(user, status: :all)
|
||||
|
||||
expect(reviewables).to match_array [reviewable, rejected_reviewable]
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue