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}}
{{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}} |
{{input type="checkbox" checked=selectAll}} | + {{/if}} ++ | {{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}} | + {{#if showApproval}} +{{i18n admin.users.approved}} | + {{/if}} ++ | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
+ {{#if can_approve}} + {{input type="checkbox" checked=selected}} + {{/if}} + | + {{/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 showApproval}} ++ {{#if approved}} + {{i18n yes_value}} + {{else}} + {{i18n no_value}} + {{/if}} + | + {{/if}} ++ {{#if admin}}{{/if}} + {{#if moderator}}{{/if}} + | + |
{{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 @@{{view Ember.Checkbox checkedBinding="selectAll"}} | - {{/if}} -- | {{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}} | - {{#if showApproval}} -{{i18n admin.users.approved}} | - {{/if}} -- | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
- {{#if can_approve}} - {{view Ember.Checkbox checkedBinding="selected"}} - {{/if}} - | - {{/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 showApproval}} -- {{#if approved}} - {{i18n yes_value}} - {{else}} - {{i18n no_value}} - {{/if}} - | - {{/if}} -- {{#if admin}}{{/if}} - {{#if moderator}}{{/if}} - | - |
{{i18n search.no_results}}
- {{/if}} - {{/loading-spinner}} + {{outlet}}