From a3e53e0d2845967ce38c8a7a97e0e491cf3c1ac5 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 26 Nov 2014 13:05:49 -0500 Subject: [PATCH] Use far fewer admin user list routes, instead pass the query as a parameter. --- .../controllers/admin-users-list-show.js.es6 | 74 +++++++++ .../admin/controllers/admin-users-list.js.es6 | 140 ------------------ .../admin/routes/admin-users-list-show.js.es6 | 15 ++ .../javascripts/admin/routes/admin_routes.js | 6 +- .../admin/routes/admin_users_list_routes.js | 137 ----------------- .../admin_users_list_trust_level_routes.js | 69 --------- .../javascripts/admin/templates/admin.hbs | 2 +- .../javascripts/admin/templates/dashboard.hbs | 8 +- .../templates/reports/trust_levels_report.hbs | 10 +- .../admin/templates/user_tl3_requirements.hbs | 2 +- .../admin/templates/users-list-show.hbs | 84 +++++++++++ .../admin/templates/users_list.hbs | 99 ++----------- .../discourse/ember/resolver.js.es6 | 2 +- 13 files changed, 196 insertions(+), 452 deletions(-) create mode 100644 app/assets/javascripts/admin/controllers/admin-users-list-show.js.es6 delete mode 100644 app/assets/javascripts/admin/controllers/admin-users-list.js.es6 create mode 100644 app/assets/javascripts/admin/routes/admin-users-list-show.js.es6 delete mode 100644 app/assets/javascripts/admin/routes/admin_users_list_routes.js delete mode 100644 app/assets/javascripts/admin/routes/admin_users_list_trust_level_routes.js create mode 100644 app/assets/javascripts/admin/templates/users-list-show.hbs diff --git a/app/assets/javascripts/admin/controllers/admin-users-list-show.js.es6 b/app/assets/javascripts/admin/controllers/admin-users-list-show.js.es6 new file mode 100644 index 00000000000..20a48ea5d32 --- /dev/null +++ b/app/assets/javascripts/admin/controllers/admin-users-list-show.js.es6 @@ -0,0 +1,74 @@ +export default Ember.ArrayController.extend({ + query: null, + showEmails: false, + refreshing: false, + listFilter: null, + selectAll: false, + + queryNew: Em.computed.equal('query', 'new'), + queryPending: Em.computed.equal('query', 'pending'), + queryHasApproval: Em.computed.or('queryNew', 'queryPending'), + showApproval: Em.computed.and('siteSettings.must_approve_users', 'queryHasApproval'), + searchHint: Discourse.computed.i18n('search_hint'), + hasSelection: Em.computed.gt('selectedCount', 0), + + selectedCount: function() { + var model = this.get('model'); + if (!model || !model.length) return 0; + return model.filterProperty('selected').length; + }.property('model.@each.selected'), + + selectAllChanged: function() { + var val = this.get('selectAll'); + this.get('model').forEach(function(user) { + if (user.get('can_approve')) { + user.set('selected', val); + } + }); + }.observes('selectAll'), + + title: function() { + return I18n.t('admin.users.titles.' + this.get('query')); + }.property('query'), + + _filterUsers: Discourse.debounce(function() { + this._refreshUsers(); + }, 250).observes('listFilter'), + + _refreshUsers: function() { + var self = this; + this.set('refreshing', true); + + Discourse.AdminUser.findAll(this.get('query'), { filter: this.get('listFilter'), show_emails: this.get('showEmails') }).then(function (result) { + self.set('model', result); + }).finally(function() { + self.set('refreshing', false); + }); + }, + + actions: { + approveUsers: function() { + Discourse.AdminUser.bulkApprove(this.get('model').filterProperty('selected')); + this._refreshUsers(); + }, + + rejectUsers: function() { + var controller = this; + Discourse.AdminUser.bulkReject(this.get('model').filterProperty('selected')).then(function(result){ + var message = I18n.t("admin.users.reject_successful", {count: result.success}); + if (result.failed > 0) { + message += ' ' + I18n.t("admin.users.reject_failures", {count: result.failed}); + message += ' ' + I18n.t("admin.user.delete_forbidden", {count: Discourse.SiteSettings.delete_user_max_post_age}); + } + bootbox.alert(message); + controller._refreshUsers(); + }); + }, + + showEmails: function() { + this.set('showEmails', true); + this._refreshUsers(true); + } + } + +}); diff --git a/app/assets/javascripts/admin/controllers/admin-users-list.js.es6 b/app/assets/javascripts/admin/controllers/admin-users-list.js.es6 deleted file mode 100644 index e3c237d9d27..00000000000 --- a/app/assets/javascripts/admin/controllers/admin-users-list.js.es6 +++ /dev/null @@ -1,140 +0,0 @@ -/** - This controller supports the interface for listing users in the admin section. - - @class AdminUsersListController - @extends Ember.ArrayController - @namespace Discourse - @module Discourse -**/ -export default Ember.ArrayController.extend(Discourse.Presence, { - username: null, - query: null, - selectAll: false, - loading: false, - - mustApproveUsers: Discourse.computed.setting('must_approve_users'), - queryNew: Em.computed.equal('query', 'new'), - queryPending: Em.computed.equal('query', 'pending'), - queryHasApproval: Em.computed.or('queryNew', 'queryPending'), - - searchHint: function() { return I18n.t("search_hint"); }.property(), - - /** - Triggered when the selectAll property is changed - - @event selectAll - **/ - selectAllChanged: function() { - var _this = this; - _.each(this.get('model'),function(user) { - user.set('selected', _this.get('selectAll')); - }); - }.observes('selectAll'), - - /** - Triggered when the username filter is changed - - @event filterUsers - **/ - filterUsers: Discourse.debounce(function() { - this.refreshUsers(); - }, 250).observes('username'), - - /** - Triggered when the order of the users list is changed - - @event orderChanged - **/ - orderChanged: function() { - this.refreshUsers(); - }.observes('query'), - - /** - The title of the user list, based on which query was performed. - - @property title - **/ - title: function() { - return I18n.t('admin.users.titles.' + this.get('query')); - }.property('query'), - - /** - Do we want to show the approval controls? - - @property showApproval - **/ - showApproval: function() { - return Discourse.SiteSettings.must_approve_users && this.get('queryHasApproval'); - }.property('queryPending'), - - /** - How many users are currently selected - - @property selectedCount - **/ - selectedCount: function() { - if (this.blank('model')) return 0; - return this.get('model').filterProperty('selected').length; - }.property('model.@each.selected'), - - /** - Do we have any selected users? - - @property hasSelection - **/ - hasSelection: Em.computed.gt('selectedCount', 0), - - /** - Refresh the current list of users. - - @method refreshUsers - **/ - refreshUsers: function(showEmails) { - var adminUsersListController = this; - adminUsersListController.set('loading', true); - - Discourse.AdminUser.findAll(this.get('query'), { filter: this.get('username'), show_emails: showEmails }).then(function (result) { - adminUsersListController.set('model', result); - adminUsersListController.set('loading', false); - }); - }, - - - /** - Show the list of users. - - @method show - **/ - show: function(term) { - if (this.get('query') === term) { - this.refreshUsers(); - return; - } - this.set('query', term); - }, - - actions: { - approveUsers: function() { - Discourse.AdminUser.bulkApprove(this.get('model').filterProperty('selected')); - this.refreshUsers(); - }, - - rejectUsers: function() { - var controller = this; - Discourse.AdminUser.bulkReject(this.get('model').filterProperty('selected')).then(function(result){ - var message = I18n.t("admin.users.reject_successful", {count: result.success}); - if (result.failed > 0) { - message += ' ' + I18n.t("admin.users.reject_failures", {count: result.failed}); - message += ' ' + I18n.t("admin.user.delete_forbidden", {count: Discourse.SiteSettings.delete_user_max_post_age}); - } - bootbox.alert(message); - controller.refreshUsers(); - }); - }, - - showEmails: function() { - this.refreshUsers(true); - } - } - -}); diff --git a/app/assets/javascripts/admin/routes/admin-users-list-show.js.es6 b/app/assets/javascripts/admin/routes/admin-users-list-show.js.es6 new file mode 100644 index 00000000000..87d5fce68c9 --- /dev/null +++ b/app/assets/javascripts/admin/routes/admin-users-list-show.js.es6 @@ -0,0 +1,15 @@ +export default Discourse.Route.extend({ + model: function(params) { + this.userFilter = params.filter; + return Discourse.AdminUser.findAll(params.filter); + }, + + setupController: function(controller, model) { + controller.setProperties({ + model: model, + query: this.userFilter, + showEmails: false, + refreshing: false, + }); + } +}); diff --git a/app/assets/javascripts/admin/routes/admin_routes.js b/app/assets/javascripts/admin/routes/admin_routes.js index 6640df91982..737e6e9eec6 100644 --- a/app/assets/javascripts/admin/routes/admin_routes.js +++ b/app/assets/javascripts/admin/routes/admin_routes.js @@ -49,11 +49,9 @@ Discourse.Route.buildRoutes(function() { this.route('badges'); this.route('tl3Requirements', { path: '/tl3_requirements' }); }); + this.resource('adminUsersList', { path: '/list' }, function() { - _.each(['active', 'new', 'pending', 'admins', 'moderators', 'blocked', 'suspended', - 'newuser', 'basicuser', 'regular', 'leaders', 'elders'], function(x) { - this.route(x, { path: '/' + x }); - }, this); + this.route('show', {path: '/:filter'}); }); }); diff --git a/app/assets/javascripts/admin/routes/admin_users_list_routes.js b/app/assets/javascripts/admin/routes/admin_users_list_routes.js deleted file mode 100644 index a6b2b330b7d..00000000000 --- a/app/assets/javascripts/admin/routes/admin_users_list_routes.js +++ /dev/null @@ -1,137 +0,0 @@ -/** - Handles the route that deals with listing users - - @class AdminUsersListRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListRoute = Discourse.Route.extend({ - renderTemplate: function() { - this.render('admin/templates/users_list', {into: 'admin/templates/admin'}); - }, - - actions: { - exportUsers: function() { - Discourse.ExportCsv.exportUserList().then(function(result) { - if (result.success) { - bootbox.alert(I18n.t("admin.export_csv.success")); - } else { - bootbox.alert(I18n.t("admin.export_csv.failed")); - } - }); - } - } -}); - -/** - Index should just redirect to active - - @class AdminUsersIndexRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListIndexRoute = Discourse.Route.extend({ - redirect: function() { - this.transitionTo('adminUsersList.active'); - } -}); - -/** - Handles the route that lists active users. - - @class AdminUsersListActiveRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListActiveRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('active'); - } -}); - -/** - Handles the route that lists new users. - - @class AdminUsersListNewRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListNewRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('new'); - } -}); - -/** - Handles the route that lists pending users. - - @class AdminUsersListPendingRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListPendingRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('pending'); - } -}); - -/** - Handles the route that lists admin users. - - @class AdminUsersListAdminsRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListAdminsRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('admins'); - } -}); - -/** - Handles the route that lists moderators. - - @class AdminUsersListModeratorsRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListModeratorsRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('moderators'); - } -}); - -/** - Handles the route that lists blocked users. - - @class AdminUsersListBlockedRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListBlockedRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('blocked'); - } -}); - -/** - Handles the route that lists suspended users. - - @class AdminUsersListSuspendedRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListSuspendedRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('suspended'); - } -}); diff --git a/app/assets/javascripts/admin/routes/admin_users_list_trust_level_routes.js b/app/assets/javascripts/admin/routes/admin_users_list_trust_level_routes.js deleted file mode 100644 index 4575299b2eb..00000000000 --- a/app/assets/javascripts/admin/routes/admin_users_list_trust_level_routes.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - Handles the route that lists users at trust level 0. - - @class AdminUsersListNewuserRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListNewuserRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('newuser'); - } -}); - -/** - Handles the route that lists users at trust level 1. - - @class AdminUsersListBasicuserRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListBasicuserRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('basic'); - } -}); - -/** - Handles the route that lists users at trust level 2. - - @class AdminUsersListRegularRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListRegularRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('regular'); - } -}); - -/** - Handles the route that lists users at trust level 3. - - @class AdminUsersListLeadersRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListLeadersRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('leader'); - } -}); - -/** - Handles the route that lists users at trust level 4. - - @class AdminUsersListEldersRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.AdminUsersListEldersRoute = Discourse.Route.extend({ - setupController: function() { - return this.controllerFor('adminUsersList').show('elder'); - } -}); diff --git a/app/assets/javascripts/admin/templates/admin.hbs b/app/assets/javascripts/admin/templates/admin.hbs index d67291e9ada..09eadbdb7d2 100644 --- a/app/assets/javascripts/admin/templates/admin.hbs +++ b/app/assets/javascripts/admin/templates/admin.hbs @@ -8,7 +8,7 @@ {{#if currentUser.admin}}
  • {{#link-to 'adminSiteSettings'}}{{i18n admin.site_settings.title}}{{/link-to}}
  • {{/if}} -
  • {{#link-to 'adminUsersList'}}{{i18n admin.users.title}}{{/link-to}}
  • +
  • {{#link-to 'adminUsersList.show' 'active'}}{{i18n admin.users.title}}{{/link-to}}
  • {{#if showBadges}}
  • {{#link-to 'adminBadges.index'}}{{i18n admin.badges.title}}{{/link-to}}
  • {{/if}} diff --git a/app/assets/javascripts/admin/templates/dashboard.hbs b/app/assets/javascripts/admin/templates/dashboard.hbs index cb597d1cdca..97d0390dede 100644 --- a/app/assets/javascripts/admin/templates/dashboard.hbs +++ b/app/assets/javascripts/admin/templates/dashboard.hbs @@ -25,15 +25,15 @@ - + - + - + - +
    {{i18n admin.dashboard.admins}}{{#link-to 'adminUsersList.admins'}}{{admins}}{{/link-to}}{{#link-to 'adminUsersList.show' 'admins'}}{{admins}}{{/link-to}} {{i18n admin.dashboard.suspended}}{{#link-to 'adminUsersList.suspended'}}{{suspended}}{{/link-to}}{{#link-to 'adminUsersList.show' 'suspended'}}{{suspended}}{{/link-to}}
    {{i18n admin.dashboard.moderators}}{{#link-to 'adminUsersList.moderators'}}{{moderators}}{{/link-to}}{{#link-to 'adminUsersList.show' 'moderators'}}{{moderators}}{{/link-to}} {{i18n admin.dashboard.blocked}}{{#link-to 'adminUsersList.blocked'}}{{blocked}}{{/link-to}}{{#link-to 'adminUsersList.show' 'blocked'}}{{blocked}}{{/link-to}}
    diff --git a/app/assets/javascripts/admin/templates/reports/trust_levels_report.hbs b/app/assets/javascripts/admin/templates/reports/trust_levels_report.hbs index b483755fe1d..b2ab0c92ef3 100644 --- a/app/assets/javascripts/admin/templates/reports/trust_levels_report.hbs +++ b/app/assets/javascripts/admin/templates/reports/trust_levels_report.hbs @@ -1,8 +1,8 @@ {{title}} - {{#link-to 'adminUsersList.newuser'}}{{valueAtTrustLevel data 0}}{{/link-to}} - {{#link-to 'adminUsersList.basicuser'}}{{valueAtTrustLevel data 1}}{{/link-to}} - {{#link-to 'adminUsersList.regular'}}{{valueAtTrustLevel data 2}}{{/link-to}} - {{#link-to 'adminUsersList.leaders'}}{{valueAtTrustLevel data 3}}{{/link-to}} - {{#link-to 'adminUsersList.elders'}}{{valueAtTrustLevel data 4}}{{/link-to}} + {{#link-to 'adminUsersList.show' 'newuser'}}{{valueAtTrustLevel data 0}}{{/link-to}} + {{#link-to 'adminUsersList.show' 'basic'}}{{valueAtTrustLevel data 1}}{{/link-to}} + {{#link-to 'adminUsersList.show' 'regular'}}{{valueAtTrustLevel data 2}}{{/link-to}} + {{#link-to 'adminUsersList.show' 'leader'}}{{valueAtTrustLevel data 3}}{{/link-to}} + {{#link-to 'adminUsersList.show' 'elder'}}{{valueAtTrustLevel data 4}}{{/link-to}} diff --git a/app/assets/javascripts/admin/templates/user_tl3_requirements.hbs b/app/assets/javascripts/admin/templates/user_tl3_requirements.hbs index 7bb228867be..cb57aa4875e 100644 --- a/app/assets/javascripts/admin/templates/user_tl3_requirements.hbs +++ b/app/assets/javascripts/admin/templates/user_tl3_requirements.hbs @@ -2,7 +2,7 @@
    diff --git a/app/assets/javascripts/admin/templates/users-list-show.hbs b/app/assets/javascripts/admin/templates/users-list-show.hbs new file mode 100644 index 00000000000..3f2dd2ceab3 --- /dev/null +++ b/app/assets/javascripts/admin/templates/users-list-show.hbs @@ -0,0 +1,84 @@ +{{#if hasSelection}} +
    + + +
    +{{/if}} + +
    +
    +

    {{title}}

    +
    +
    +
    + {{text-field value=listFilter placeholder=searchHint}} + {{#unless showEmails}} +
    + +
    + {{/unless}} +
    + +{{#loading-spinner condition=refreshing}} + {{#if model}} + + + {{#if showApproval}} + + {{/if}} + + + + + + + + + + {{#if showApproval}} + + {{/if}} + + + + {{#each model}} + + {{#if controller.showApproval}} + + {{/if}} + + + + + + + + + + + + {{#if showApproval}} + + {{/if}} + + {{/each}} + +
    {{input type="checkbox" checked=selectAll}} {{i18n username}}{{i18n email}}{{i18n admin.users.last_emailed}}{{i18n last_seen}}{{i18n admin.user.topics_entered}}{{i18n admin.user.posts_read_count}}{{i18n admin.user.time_read}}{{i18n created}}{{i18n admin.users.approved}} 
    + {{#if can_approve}} + {{input type="checkbox" checked=selected}} + {{/if}} + {{#link-to 'adminUser' this}}{{avatar this imageSize="small"}}{{/link-to}}{{#link-to 'adminUser' this}}{{unbound username}}{{/link-to}}{{{unbound email}}}{{{unbound last_emailed_age}}}{{{unbound last_seen_age}}}{{{unbound topics_entered}}}{{{unbound posts_read_count}}}{{{unbound time_read}}}{{{unbound created_at_age}}} + {{#if approved}} + {{i18n yes_value}} + {{else}} + {{i18n no_value}} + {{/if}} + + {{#if admin}}{{/if}} + {{#if moderator}}{{/if}} + +
    + {{else}} +

    {{i18n search.no_results}}

    + {{/if}} +{{/loading-spinner}} diff --git a/app/assets/javascripts/admin/templates/users_list.hbs b/app/assets/javascripts/admin/templates/users_list.hbs index c4ab6dac64d..78500233600 100644 --- a/app/assets/javascripts/admin/templates/users_list.hbs +++ b/app/assets/javascripts/admin/templates/users_list.hbs @@ -1,103 +1,22 @@
    -
    - {{text-field value=username placeholder=searchHint}} -
    - {{#if hasSelection}} -
    - - -
    - {{/if}} - -
    -
    -

    {{title}}

    -
    -
    - -
    -
    - - {{#loading-spinner condition=loading}} - {{#if model.length}} - - - {{#if showApproval}} - - {{/if}} - - - - - - - - - - {{#if showApproval}} - - {{/if}} - - - - {{#each model}} - - {{#if controller.showApproval}} - - {{/if}} - - - - - - - - - - - - {{#if showApproval}} - - {{/if}} - - {{/each}} - -
    {{view Ember.Checkbox checkedBinding="selectAll"}} {{i18n username}}{{i18n email}}{{i18n admin.users.last_emailed}}{{i18n last_seen}}{{i18n admin.user.topics_entered}}{{i18n admin.user.posts_read_count}}{{i18n admin.user.time_read}}{{i18n created}}{{i18n admin.users.approved}} 
    - {{#if can_approve}} - {{view Ember.Checkbox checkedBinding="selected"}} - {{/if}} - {{#link-to 'adminUser' this}}{{avatar this imageSize="small"}}{{/link-to}}{{#link-to 'adminUser' this}}{{unbound username}}{{/link-to}}{{{unbound email}}}{{{unbound last_emailed_age}}}{{{unbound last_seen_age}}}{{{unbound topics_entered}}}{{{unbound posts_read_count}}}{{{unbound time_read}}}{{{unbound created_at_age}}} - {{#if approved}} - {{i18n yes_value}} - {{else}} - {{i18n no_value}} - {{/if}} - - {{#if admin}}{{/if}} - {{#if moderator}}{{/if}} - -
    - {{else}} -

    {{i18n search.no_results}}

    - {{/if}} - {{/loading-spinner}} + {{outlet}}
    diff --git a/app/assets/javascripts/discourse/ember/resolver.js.es6 b/app/assets/javascripts/discourse/ember/resolver.js.es6 index a11aa487882..b4cb4bd0d9b 100644 --- a/app/assets/javascripts/discourse/ember/resolver.js.es6 +++ b/app/assets/javascripts/discourse/ember/resolver.js.es6 @@ -4,7 +4,7 @@ var classify = Ember.String.classify; var get = Ember.get; var LOADING_WHITELIST = ['badges', 'userActivity', 'userPrivateMessages', 'admin', 'adminFlags', - 'user', 'preferences', 'adminEmail'], + 'user', 'preferences', 'adminEmail', 'adminUsersList'], _dummyRoute, _loadingView;