From 7ef306cd3bbffc1fe8e19d223c1024dd3caf2004 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 19 Mar 2015 11:48:16 -0400 Subject: [PATCH] A bunch of tweaks to the Users directory - Move user directory from `/directory` to `/users/` - Defaults to 'weekly' time period - Don't include deleted topics/posts in the results - Move heart icon to header instead of on each row - "Users" instead of "Users found" --- .../components/directory-toggle.js.es6 | 6 +++ .../{directory-show.js.es6 => users.js.es6} | 3 +- .../discourse/routes/app-route-map.js.es6 | 5 +- .../discourse/routes/directory-index.js.es6 | 6 --- .../{directory-show.js.es6 => users.js.es6} | 15 ++---- .../discourse/templates/directory.hbs | 5 -- .../discourse/templates/directory/show.hbs | 50 ------------------- .../discourse/templates/site-map.hbs | 2 +- .../javascripts/discourse/templates/users.hbs | 50 +++++++++++++++++++ .../{directory-show.js.es6 => users.js.es6} | 0 .../stylesheets/common/base/directory.scss | 13 +++-- app/controllers/directory_controller.rb | 8 --- app/controllers/directory_items_controller.rb | 6 +-- app/controllers/users_controller.rb | 3 ++ app/models/directory_item.rb | 4 ++ config/locales/client.en.yml | 4 +- config/routes.rb | 1 - .../directory_items_controller_spec.rb | 8 +-- ...irectory-test.js.es6 => users-test.js.es6} | 4 +- 19 files changed, 87 insertions(+), 106 deletions(-) rename app/assets/javascripts/discourse/controllers/{directory-show.js.es6 => users.js.es6} (77%) delete mode 100644 app/assets/javascripts/discourse/routes/directory-index.js.es6 rename app/assets/javascripts/discourse/routes/{directory-show.js.es6 => users.js.es6} (60%) delete mode 100644 app/assets/javascripts/discourse/templates/directory.hbs delete mode 100644 app/assets/javascripts/discourse/templates/directory/show.hbs create mode 100644 app/assets/javascripts/discourse/templates/users.hbs rename app/assets/javascripts/discourse/views/{directory-show.js.es6 => users.js.es6} (100%) delete mode 100644 app/controllers/directory_controller.rb rename test/javascripts/integration/{directory-test.js.es6 => users-test.js.es6} (69%) diff --git a/app/assets/javascripts/discourse/components/directory-toggle.js.es6 b/app/assets/javascripts/discourse/components/directory-toggle.js.es6 index 8c4b4761b..3b6b35c96 100644 --- a/app/assets/javascripts/discourse/components/directory-toggle.js.es6 +++ b/app/assets/javascripts/discourse/components/directory-toggle.js.es6 @@ -7,6 +7,12 @@ export default Ember.Component.extend(StringBuffer, { rerenderTriggers: ['order', 'asc'], renderString(buffer) { + + const icon = this.get('icon'); + if (icon) { + buffer.push(iconHTML(icon)); + } + const field = this.get('field'); buffer.push(I18n.t('directory.' + field)); diff --git a/app/assets/javascripts/discourse/controllers/directory-show.js.es6 b/app/assets/javascripts/discourse/controllers/users.js.es6 similarity index 77% rename from app/assets/javascripts/discourse/controllers/directory-show.js.es6 rename to app/assets/javascripts/discourse/controllers/users.js.es6 index 2ea363076..631be71d7 100644 --- a/app/assets/javascripts/discourse/controllers/directory-show.js.es6 +++ b/app/assets/javascripts/discourse/controllers/users.js.es6 @@ -1,5 +1,6 @@ export default Ember.Controller.extend({ - queryParams: ['order', 'asc'], + queryParams: ['period', 'order', 'asc'], + period: 'weekly', order: 'likes_received', asc: null, diff --git a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 index e6adf8630..15d469230 100644 --- a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 +++ b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 @@ -11,10 +11,6 @@ export default function() { }); this.resource('topicBySlug', { path: '/t/:slug' }); - this.resource('directory', function() { - this.route('show', {path: '/:period'}); - }); - this.resource('discovery', { path: '/' }, function() { // top this.route('top'); @@ -56,6 +52,7 @@ export default function() { }); // User routes + this.resource('users'); this.resource('user', { path: '/users/:username' }, function() { this.resource('userActivity', { path: '/activity' }, function() { var self = this; diff --git a/app/assets/javascripts/discourse/routes/directory-index.js.es6 b/app/assets/javascripts/discourse/routes/directory-index.js.es6 deleted file mode 100644 index cc8c80730..000000000 --- a/app/assets/javascripts/discourse/routes/directory-index.js.es6 +++ /dev/null @@ -1,6 +0,0 @@ -export default Discourse.Route.extend({ - beforeModel: function() { - this.controllerFor('directory-show').setProperties({ sort: null, asc: null }); - this.replaceWith('directory.show', 'all'); - } -}); diff --git a/app/assets/javascripts/discourse/routes/directory-show.js.es6 b/app/assets/javascripts/discourse/routes/users.js.es6 similarity index 60% rename from app/assets/javascripts/discourse/routes/directory-show.js.es6 rename to app/assets/javascripts/discourse/routes/users.js.es6 index fc319f689..22fc3575b 100644 --- a/app/assets/javascripts/discourse/routes/directory-show.js.es6 +++ b/app/assets/javascripts/discourse/routes/users.js.es6 @@ -1,31 +1,22 @@ export default Discourse.Route.extend({ queryParams: { + period: { refreshModel: true }, order: { refreshModel: true }, asc: { refreshModel: true }, }, model(params) { // If we refresh via `refreshModel` set the old model to loading - const existing = this.modelFor('directory-show'); + const existing = this.modelFor('users'); if (existing) { existing.set('loading', true); } this._period = params.period; - return this.store.find('directoryItem', { - id: params.period, - asc: params.asc, - order: params.order - }); + return this.store.find('directoryItem', params); }, setupController(controller, model) { controller.setProperties({ model, period: this._period }); - }, - - actions: { - changePeriod(period) { - this.transitionTo('directory.show', period); - } } }); diff --git a/app/assets/javascripts/discourse/templates/directory.hbs b/app/assets/javascripts/discourse/templates/directory.hbs deleted file mode 100644 index 68207c460..000000000 --- a/app/assets/javascripts/discourse/templates/directory.hbs +++ /dev/null @@ -1,5 +0,0 @@ -
-
- {{outlet}} -
-
diff --git a/app/assets/javascripts/discourse/templates/directory/show.hbs b/app/assets/javascripts/discourse/templates/directory/show.hbs deleted file mode 100644 index e06356f61..000000000 --- a/app/assets/javascripts/discourse/templates/directory/show.hbs +++ /dev/null @@ -1,50 +0,0 @@ -{{period-chooser period=period action="changePeriod"}} - -{{#loading-spinner condition=model.loading}} - {{#if model.length}} - {{i18n "directory.total_rows" count=model.totalRows}} - - - - - {{directory-toggle field="likes_received" order=order asc=asc}} - {{directory-toggle field="likes_given" order=order asc=asc}} - {{directory-toggle field="topic_count" order=order asc=asc}} - {{directory-toggle field="post_count" order=order asc=asc}} - {{directory-toggle field="topics_entered" order=order asc=asc}} - {{#if showTimeRead}} - - {{/if}} - - - {{#each item in model}} - - - - - - - - {{#if showTimeRead}} - - {{/if}} - - {{/each}} - -
 {{i18n "directory.time_read"}}
- {{avatar item imageSize="tiny"}} - {{#link-to 'user' item.username}}{{unbound item.username}}{{/link-to}} - {{number item.topic_count}}{{number item.post_count}}{{number item.topics_entered}}{{unbound item.time_read}}
- - {{loading-spinner condition=model.loadingMore}} - {{else}} -
-

{{i18n "directory.no_results"}}

- {{/if}} -{{/loading-spinner}} diff --git a/app/assets/javascripts/discourse/templates/site-map.hbs b/app/assets/javascripts/discourse/templates/site-map.hbs index d4be2d7bd..c7995ef22 100644 --- a/app/assets/javascripts/discourse/templates/site-map.hbs +++ b/app/assets/javascripts/discourse/templates/site-map.hbs @@ -22,7 +22,7 @@ {{/if}} -
  • {{#link-to 'directory'}}{{i18n "directory.title"}}{{/link-to}}
  • +
  • {{#link-to 'users'}}{{i18n "directory.title"}}{{/link-to}}
  • {{plugin-outlet "site-map-links"}} diff --git a/app/assets/javascripts/discourse/templates/users.hbs b/app/assets/javascripts/discourse/templates/users.hbs new file mode 100644 index 000000000..7285ea21e --- /dev/null +++ b/app/assets/javascripts/discourse/templates/users.hbs @@ -0,0 +1,50 @@ +
    +
    + + {{period-chooser period=period}} + + {{#loading-spinner condition=model.loading}} + {{#if model.length}} + {{i18n "directory.total_rows" count=model.totalRows}} + + + + + {{directory-toggle field="likes_received" order=order asc=asc icon="heart"}} + {{directory-toggle field="likes_given" order=order asc=asc icon="heart"}} + {{directory-toggle field="topic_count" order=order asc=asc}} + {{directory-toggle field="post_count" order=order asc=asc}} + {{directory-toggle field="topics_entered" order=order asc=asc}} + {{#if showTimeRead}} + + {{/if}} + + + {{#each item in model}} + + + + + + + + {{#if showTimeRead}} + + {{/if}} + + {{/each}} + +
     {{i18n "directory.time_read"}}
    + {{avatar item imageSize="tiny"}} + {{#link-to 'user' item.username}}{{unbound item.username}}{{/link-to}} + {{number item.likes_received}}{{number item.likes_given}}{{number item.topic_count}}{{number item.post_count}}{{number item.topics_entered}}{{unbound item.time_read}}
    + + {{loading-spinner condition=model.loadingMore}} + {{else}} +
    +

    {{i18n "directory.no_results"}}

    + {{/if}} + {{/loading-spinner}} + +
    +
    diff --git a/app/assets/javascripts/discourse/views/directory-show.js.es6 b/app/assets/javascripts/discourse/views/users.js.es6 similarity index 100% rename from app/assets/javascripts/discourse/views/directory-show.js.es6 rename to app/assets/javascripts/discourse/views/users.js.es6 diff --git a/app/assets/stylesheets/common/base/directory.scss b/app/assets/stylesheets/common/base/directory.scss index d11141fbe..16aad83c3 100644 --- a/app/assets/stylesheets/common/base/directory.scss +++ b/app/assets/stylesheets/common/base/directory.scss @@ -26,9 +26,14 @@ th.sortable { cursor: pointer; + white-space: nowrap; width: 13%; - i.fa { + i.fa-heart { + color: $love; + margin-right: 0.5em; + } + i.fa-chevron-down, i.fa-chevron-up { margin-left: 1em; } @@ -36,11 +41,5 @@ background-color: scale-color-diff(); } } - - td.likes { - i { - color: $love; - } - } } } diff --git a/app/controllers/directory_controller.rb b/app/controllers/directory_controller.rb deleted file mode 100644 index aea4bbc20..000000000 --- a/app/controllers/directory_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class DirectoryController < ApplicationController - # This controller just exists to avoid 404s and to have the ember app load up - def index - end - - def show - end -end diff --git a/app/controllers/directory_items_controller.rb b/app/controllers/directory_items_controller.rb index 221149d22..a70a872aa 100644 --- a/app/controllers/directory_items_controller.rb +++ b/app/controllers/directory_items_controller.rb @@ -2,8 +2,8 @@ class DirectoryItemsController < ApplicationController PAGE_SIZE = 50 def index - id = params.require(:id) - period_type = DirectoryItem.period_types[id.to_sym] + period = params.require(:period) + period_type = DirectoryItem.period_types[period.to_sym] raise Discourse::InvalidAccess.new(:period_type) unless period_type result = DirectoryItem.where(period_type: period_type).includes(:user) @@ -24,7 +24,7 @@ class DirectoryItemsController < ApplicationController serialized = serialize_data(result, DirectoryItemSerializer) - more_params = params.slice(:id, :order, :asc) + more_params = params.slice(:period, :order, :asc) more_params[:page] = page + 1 render_json_dump directory_items: serialized, diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d257cb7e2..4642bef89 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -25,6 +25,9 @@ class UsersController < ApplicationController :authorize_email, :password_reset] + def index + end + def show @user = fetch_user_from_params user_serializer = UserSerializer.new(@user, scope: guardian, root: 'user') diff --git a/app/models/directory_item.rb b/app/models/directory_item.rb index d2b8c02a5..facd8d487 100644 --- a/app/models/directory_item.rb +++ b/app/models/directory_item.rb @@ -42,9 +42,13 @@ class DirectoryItem < ActiveRecord::Base SUM(CASE WHEN ua.action_type = :reply_type THEN 1 ELSE 0 END) FROM users AS u LEFT OUTER JOIN user_actions AS ua ON ua.user_id = u.id + LEFT OUTER JOIN topics AS t ON ua.target_topic_id = t.id + LEFT OUTER JOIN posts AS p ON ua.target_post_id = p.id WHERE u.active AND NOT u.blocked AND COALESCE(ua.created_at, :since) >= :since + AND t.deleted_at IS NULL + AND p.deleted_at IS NULL AND u.id > 0 GROUP BY u.id", period_type: period_types[period_type], diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 60d311b7b..8a40413ba 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -247,8 +247,8 @@ en: post_count: "Replies" no_results: "No results were found for this time period." total_rows: - one: "1 user found" - other: "%{count} users found" + one: "1 user" + other: "%{count} users" groups: visible: "Group is visible to all users" diff --git a/config/routes.rb b/config/routes.rb index a3cfd922b..5e8d9ef72 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -25,7 +25,6 @@ Discourse::Application.routes.draw do resources :about - resources :directory resources :directory_items get "site" => "site#site" diff --git a/spec/controllers/directory_items_controller_spec.rb b/spec/controllers/directory_items_controller_spec.rb index bc36d9b86..8f46747d8 100644 --- a/spec/controllers/directory_items_controller_spec.rb +++ b/spec/controllers/directory_items_controller_spec.rb @@ -2,12 +2,12 @@ require 'spec_helper' describe DirectoryItemsController do - it "requires an `id` param" do + it "requires a `period` param" do ->{ xhr :get, :index }.should raise_error end - it "requires a proper `id` param" do - xhr :get, :index, id: 'eviltrout' + it "requires a proper `period` param" do + xhr :get, :index, period: 'eviltrout' response.should_not be_success end @@ -18,7 +18,7 @@ describe DirectoryItemsController do end it "succeeds with a valid value" do - xhr :get, :index, id: 'all' + xhr :get, :index, period: 'all' response.should be_success json = ::JSON.parse(response.body) diff --git a/test/javascripts/integration/directory-test.js.es6 b/test/javascripts/integration/users-test.js.es6 similarity index 69% rename from test/javascripts/integration/directory-test.js.es6 rename to test/javascripts/integration/users-test.js.es6 index 460cf4915..96f27623d 100644 --- a/test/javascripts/integration/directory-test.js.es6 +++ b/test/javascripts/integration/users-test.js.es6 @@ -1,7 +1,7 @@ integration("User Directory"); -test("Visit Page", () => { - visit("/directory/all"); +test("Visit Page", function() { + visit("/users"); andThen(() => { ok(exists('.directory table tr'), "has a list of users"); });