UX: Allow groups page to be searchable.

This commit is contained in:
Guo Xiang Tan 2018-03-19 17:16:51 +08:00
parent 0522aabaab
commit 05ea034490
7 changed files with 93 additions and 57 deletions

View File

@ -1,10 +1,18 @@
import { observes } from 'ember-addons/ember-computed-decorators'; import { observes } from 'ember-addons/ember-computed-decorators';
import debounce from 'discourse/lib/debounce';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
application: Ember.inject.controller(), application: Ember.inject.controller(),
queryParams: ["order", "asc"], queryParams: ["order", "asc", "filter"],
order: null, order: null,
asc: null, asc: null,
filter: "",
filterInput: "",
@observes("filterInput")
_setFilter: debounce(function() {
this.set("filter", this.get("filterInput"));
}, 500),
@observes("model.canLoadMore") @observes("model.canLoadMore")
_showFooter() { _showFooter() {

View File

@ -2,6 +2,7 @@ export default Discourse.Route.extend({
queryParams: { queryParams: {
order: { refreshModel: true, replace: true }, order: { refreshModel: true, replace: true },
asc: { refreshModel: true, replace: true }, asc: { refreshModel: true, replace: true },
filter: { refreshModel: true }
}, },
refreshQueryWithoutTransition: true, refreshQueryWithoutTransition: true,

View File

@ -1,7 +1,12 @@
{{#d-section pageClass="groups"}} {{#d-section pageClass="groups"}}
<h1>{{i18n "groups.index.title"}}</h1> <h1>{{i18n "groups.index.title"}}</h1>
{{text-field value=filterInput
placeholderKey="groups.filter_name"
class="group-filter-name no-blur"}}
{{#if model}} {{#if model}}
{{#conditional-loading-spinner condition=model.loading}}
{{#load-more selector=".groups-table .groups-table-row" action="loadMore"}} {{#load-more selector=".groups-table .groups-table-row" action="loadMore"}}
<div class='container'> <div class='container'>
<table class="groups-table"> <table class="groups-table">
@ -63,6 +68,7 @@
{{/load-more}} {{/load-more}}
{{conditional-loading-spinner condition=model.loadingMore}} {{conditional-loading-spinner condition=model.loadingMore}}
{{/conditional-loading-spinner}}
{{else}} {{else}}
<p>{{i18n "groups.index.empty"}}</p> <p>{{i18n "groups.index.empty"}}</p>
{{/if}} {{/if}}

View File

@ -1,9 +1,15 @@
.groups-page { .groups-page {
h1 { h1 {
margin: 20px 0; margin-bottom: 20px;
display: inline-block;
} }
} }
.group-filter-name {
display: inline-block;
float: right;
}
.groups-table { .groups-table {
width: 100%; width: 100%;

View File

@ -24,6 +24,10 @@ class GroupsController < ApplicationController
dir = params[:asc] ? 'ASC' : 'DESC' dir = params[:asc] ? 'ASC' : 'DESC'
groups = Group.visible_groups(current_user, order ? "#{order} #{dir}" : nil) groups = Group.visible_groups(current_user, order ? "#{order} #{dir}" : nil)
if (filter = params[:filter]).present?
groups = Group.search_groups(filter, groups: groups)
end
unless guardian.is_staff? unless guardian.is_staff?
# hide automatic groups from all non stuff to de-clutter page # hide automatic groups from all non stuff to de-clutter page
groups = groups.where(automatic: false) groups = groups.where(automatic: false)

View File

@ -432,6 +432,7 @@ en:
join: "Join Group" join: "Join Group"
leave: "Leave Group" leave: "Leave Group"
request: "Request to Join Group" request: "Request to Join Group"
filter_name: "filter by group name"
message: "Message" message: "Message"
automatic_group: Automatic Group automatic_group: Automatic Group
closed_group: Closed Group closed_group: Closed Group

View File

@ -18,6 +18,16 @@ describe GroupsController do
end end
end end
context 'searchable' do
it 'should return the right response' do
other_group = Fabricate(:group, name: 'testing')
get "/groups.json", params: { filter: 'test' }
expect(response.status).to eq(200)
expect(JSON.parse(response.body)["groups"].first["id"]).to eq(other_group.id)
end
end
context 'sortable' do context 'sortable' do
let!(:other_group) { Fabricate(:group, name: "zzzzzz", users: [user]) } let!(:other_group) { Fabricate(:group, name: "zzzzzz", users: [user]) }