diff --git a/1.5 b/1.5 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/app/assets/javascripts/discourse/app/templates/users.hbs b/app/assets/javascripts/discourse/app/templates/users.hbs index 0766928a143..b406e63a751 100644 --- a/app/assets/javascripts/discourse/app/templates/users.hbs +++ b/app/assets/javascripts/discourse/app/templates/users.hbs @@ -13,7 +13,14 @@ {{/if}} - {{text-field value=nameInput placeholderKey="directory.filter_name" class="filter-name no-blur"}} +
{{i18n "directory.total_rows" count=model.totalRows}} | + {{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}} diff --git a/app/assets/stylesheets/common/base/directory.scss b/app/assets/stylesheets/common/base/directory.scss index c68f47e3759..bbe8757af6f 100644 --- a/app/assets/stylesheets/common/base/directory.scss +++ b/app/assets/stylesheets/common/base/directory.scss @@ -23,6 +23,9 @@ .directory-controls { display: flex; justify-content: space-between; + .total-rows { + color: var(--primary-medium); + } .filter-name { height: 1em; } diff --git a/app/controllers/directory_items_controller.rb b/app/controllers/directory_items_controller.rb index a0af52a6e15..d174571e67d 100644 --- a/app/controllers/directory_items_controller.rb +++ b/app/controllers/directory_items_controller.rb @@ -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] diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f82f5d8b182..4e9e6ba2154 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -578,6 +578,7 @@ en: sent_by_you: "Sent by you" directory: + username: "Username" filter_name: "filter by username" title: "Users" likes_given: "Given" diff --git a/spec/requests/directory_items_controller_spec.rb b/spec/requests/directory_items_controller_spec.rb index 80817ef744e..df7042c9fbc 100644 --- a/spec/requests/directory_items_controller_spec.rb +++ b/spec/requests/directory_items_controller_spec.rb @@ -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)
---|