FEATURE: Added sort by username for directory items (#10482)

* done-sorting-usernames-on-users-page

* sorted-usernames-on-users-page

* spec written

* specs added
This commit is contained in:
jahan-ggn 2020-08-26 19:44:20 +05:30 committed by GitHub
parent 6c3b1eb9b9
commit ae7ff5eb73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 3 deletions

0
1.5 Normal file
View File

View File

@ -13,7 +13,14 @@
</div>
{{/if}}
</div>
{{text-field value=nameInput placeholderKey="directory.filter_name" class="filter-name no-blur"}}
<div>
<span class="total-rows">
{{#if model.totalRows}}
{{i18n "directory.total_rows" count=model.totalRows}}
{{/if}}
</span>
{{text-field value=nameInput placeholderKey="directory.filter_name" class="filter-name no-blur"}}
</div>
</div>
{{#conditional-loading-spinner condition=isLoading}}
@ -21,7 +28,7 @@
<table>
<thead>
<th>{{i18n "directory.total_rows" count=model.totalRows}}</th>
{{table-header-toggle field="username" order=order asc=asc}}
{{table-header-toggle field="likes_received" order=order asc=asc icon="heart"}}
{{table-header-toggle field="likes_given" order=order asc=asc icon="heart"}}
{{table-header-toggle field="topic_count" order=order asc=asc}}

View File

@ -23,6 +23,9 @@
.directory-controls {
display: flex;
justify-content: space-between;
.total-rows {
color: var(--primary-medium);
}
.filter-name {
height: 1em;
}

View File

@ -27,9 +27,11 @@ class DirectoryItemsController < ApplicationController
end
order = params[:order] || DirectoryItem.headings.first
dir = params[:asc] ? 'ASC' : 'DESC'
if DirectoryItem.headings.include?(order.to_sym)
dir = params[:asc] ? 'ASC' : 'DESC'
result = result.order("directory_items.#{order} #{dir}")
elsif params[:order] === 'username'
result = result.order("users.#{order} #{dir}")
end
if period_type == DirectoryItem.period_types[:all]

View File

@ -578,6 +578,7 @@ en:
sent_by_you: "Sent by <a href='%{userUrl}'>you</a>"
directory:
username: "Username"
filter_name: "filter by username"
title: "Users"
likes_given: "Given"

View File

@ -60,6 +60,25 @@ describe DirectoryItemsController do
expect(response).not_to be_successful
end
it "sort username with asc as a parameter" do
get '/directory_items.json', params: { asc: true, order: 'username', period: 'all' }
expect(response.status).to eq(200)
json = response.parsed_body
names = json['directory_items'].map { |item| item['user']['username'] }
expect(names).to eq(names.sort)
end
it "sort username without asc as a parameter" do
get '/directory_items.json', params: { order: 'username', period: 'all' }
expect(response.status).to eq(200)
json = response.parsed_body
names = json['directory_items'].map { |item| item['user']['username'] }
expect(names).to eq(names.sort.reverse)
end
it "finds user by name" do
get '/directory_items.json', params: { period: 'all', name: 'eviltrout' }
expect(response.status).to eq(200)