Admin Dashboard: click numbers in Users per Trust Level table to see a list of the users

This commit is contained in:
Neil Lalonde 2013-04-23 10:29:18 -04:00
parent e8172e66d2
commit fe1b979c65
9 changed files with 180 additions and 63 deletions

View File

@ -11,6 +11,7 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
query: null, query: null,
selectAll: false, selectAll: false,
content: null, content: null,
loading: false,
/** /**
Triggered when the selectAll property is changed Triggered when the selectAll property is changed
@ -42,6 +43,15 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
this.refreshUsers(); this.refreshUsers();
}).observes('query'), }).observes('query'),
/**
The title of the user list, based on which query was performed.
@property title
**/
title: function() {
return Em.String.i18n('admin.users.titles.' + this.get('query'));
}.property('query'),
/** /**
Do we want to show the approval controls? Do we want to show the approval controls?
@ -78,7 +88,9 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
@method refreshUsers @method refreshUsers
**/ **/
refreshUsers: function() { refreshUsers: function() {
this.set('content', Discourse.AdminUser.findAll(this.get('query'), this.get('username'))); this.set('loading', true);
var _this = this;
this.set('content', Discourse.AdminUser.findAll(this.get('query'), this.get('username'), function() { _this.set('loading', false); }));
}, },

View File

@ -196,7 +196,7 @@ Discourse.AdminUser.reopenClass({
}); });
}, },
findAll: function(query, filter) { findAll: function(query, filter, doneCallback) {
var result = Em.A(); var result = Em.A();
Discourse.ajax({ Discourse.ajax({
url: Discourse.getURL("/admin/users/list/") + query + ".json", url: Discourse.getURL("/admin/users/list/") + query + ".json",
@ -205,6 +205,7 @@ Discourse.AdminUser.reopenClass({
users.each(function(u) { users.each(function(u) {
result.pushObject(Discourse.AdminUser.create(u)); result.pushObject(Discourse.AdminUser.create(u));
}); });
if( doneCallback ) { doneCallback(); }
}); });
return result; return result;
} }

View File

@ -33,6 +33,12 @@ Discourse.Route.buildRoutes(function() {
this.route('active', { path: '/active' }); this.route('active', { path: '/active' });
this.route('new', { path: '/new' }); this.route('new', { path: '/new' });
this.route('pending', { path: '/pending' }); this.route('pending', { path: '/pending' });
// Trust Levels:
this.route('newuser', { path: '/newuser' });
this.route('basic', { path: '/basic' });
this.route('regular', { path: '/regular' });
this.route('leaders', { path: '/leaders' });
this.route('elders', { path: '/elders' });
}); });
}); });

View File

@ -0,0 +1,69 @@
/**
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 AdminUsersListBasicRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.AdminUsersListBasicRoute = 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');
}
});

View File

@ -1,8 +1,8 @@
<tr> <tr>
<td class="title">{{title}}</td> <td class="title">{{title}}</td>
<td class="value">{{valueAtTrustLevel data 0}}</td> <td class="value">{{#linkTo 'adminUsersList.newuser'}}{{valueAtTrustLevel data 0}}{{/linkTo}}</td>
<td class="value">{{valueAtTrustLevel data 1}}</td> <td class="value">{{#linkTo 'adminUsersList.basic'}}{{valueAtTrustLevel data 1}}{{/linkTo}}</td>
<td class="value">{{valueAtTrustLevel data 2}}</td> <td class="value">{{#linkTo 'adminUsersList.regular'}}{{valueAtTrustLevel data 2}}{{/linkTo}}</td>
<td class="value">{{valueAtTrustLevel data 3}}</td> <td class="value">{{#linkTo 'adminUsersList.leaders'}}{{valueAtTrustLevel data 3}}{{/linkTo}}</td>
<td class="value">{{valueAtTrustLevel data 4}}</td> <td class="value">{{#linkTo 'adminUsersList.elders'}}{{valueAtTrustLevel data 4}}{{/linkTo}}</td>
</tr> </tr>

View File

@ -19,67 +19,74 @@
</div> </div>
{{/if}} {{/if}}
{{#if content.length}} <h2>{{title}}</h2>
<table class='table'> <br/>
<tr>
{{#if showApproval}}
<th>{{view Ember.Checkbox checkedBinding="selectAll"}}</th>
{{/if}}
<th>&nbsp;</th>
<th>{{i18n username}}</th>
<th>{{i18n email}}</th>
<th>{{i18n admin.users.last_emailed}}</th>
<th>{{i18n last_seen}}</th>
<th>{{i18n admin.user.topics_entered}}</th>
<th>{{i18n admin.user.posts_read_count}}</th>
<th>{{i18n admin.user.time_read}}</th>
<th>{{i18n created}}</th>
{{#if showApproval}}
<th>{{i18n admin.users.approved}}</th>
{{/if}}
<th>&nbsp;</th>
</tr> {{#if loading}}
<div class='admin-loading'>{{i18n loading}}</div>
{{else}}
{{#if content.length}}
<table class='table'>
<tr>
{{#if showApproval}}
<th>{{view Ember.Checkbox checkedBinding="selectAll"}}</th>
{{/if}}
<th>&nbsp;</th>
<th>{{i18n username}}</th>
<th>{{i18n email}}</th>
<th>{{i18n admin.users.last_emailed}}</th>
<th>{{i18n last_seen}}</th>
<th>{{i18n admin.user.topics_entered}}</th>
<th>{{i18n admin.user.posts_read_count}}</th>
<th>{{i18n admin.user.time_read}}</th>
<th>{{i18n created}}</th>
{{#if showApproval}}
<th>{{i18n admin.users.approved}}</th>
{{/if}}
<th>&nbsp;</th>
{{#each content}} </tr>
<tr {{bindAttr class="selected"}}>
{{#if controller.showApproval}} {{#each content}}
<tr {{bindAttr class="selected"}}>
{{#if controller.showApproval}}
<td>
{{#if can_approve}}
{{view Ember.Checkbox checkedBinding="selected"}}
{{/if}}
</td>
{{/if}}
<td> <td>
{{#if can_approve}} <a href="{{unbound adminPath}}">{{avatar this imageSize="small"}}</a>
{{view Ember.Checkbox checkedBinding="selected"}} </td>
<td><a href="{{unbound adminPath}}">{{unbound username}}</a></td>
<td>{{shorten email}}</td>
<td>{{{unbound last_emailed_age}}}</td>
<td>{{{unbound last_seen_age}}}</td>
<td>{{{unbound topics_entered}}}</td>
<td>{{{unbound posts_read_count}}}</td>
<td>{{{unbound time_read}}}</td>
<td>{{{unbound created_at_age}}}</td>
{{#if controller.showApproval}}
<td>
{{#if approved}}
{{i18n yes_value}}
{{else}}
{{i18n no_value}}
{{/if}} {{/if}}
</td> </td>
{{/if}}
<td>
<a href="{{unbound adminPath}}">{{avatar this imageSize="small"}}</a>
</td>
<td><a href="{{unbound adminPath}}">{{unbound username}}</a></td>
<td>{{shorten email}}</td>
<td>{{{unbound last_emailed_age}}}</td>
<td>{{{unbound last_seen_age}}}</td>
<td>{{{unbound topics_entered}}}</td>
<td>{{{unbound posts_read_count}}}</td>
<td>{{{unbound time_read}}}</td>
<td>{{{unbound created_at_age}}}</td>
{{#if controller.showApproval}}
<td>
{{#if approved}}
{{i18n yes_value}}
{{else}}
{{i18n no_value}}
{{/if}} {{/if}}
</td> <td>
{{/if}} {{#if admin}}<i class="icon-trophy" title="{{i18n admin.title}}"></i>{{/if}}
<td> {{#if moderator}}<i class="icon-magic" title="{{i18n admin.moderator}}"></i>{{/if}}
{{#if admin}}<i class="icon-trophy" title="{{i18n admin.title}}"></i>{{/if}} <td>
{{#if moderator}}<i class="icon-magic" title="{{i18n admin.moderator}}"></i>{{/if}} </tr>
<td> {{/each}}
</tr>
{{/each}}
</table> </table>
{{else}} {{else}}
<div class='admin-loading'>{{i18n loading}}</div> <p>{{i18n search.no_results}}</p>
{{/if}}
{{/if}} {{/if}}

View File

@ -1,3 +1,12 @@
/**
The view that displays the number of users at each trust level
on the admin dashboard.
@class AdminReportTrustLevelsView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.AdminReportTrustLevelsView = Discourse.View.extend({ Discourse.AdminReportTrustLevelsView = Discourse.View.extend({
templateName: 'admin/templates/reports/trust_levels_report', templateName: 'admin/templates/reports/trust_levels_report',
tagName: 'tbody' tagName: 'tbody'

View File

@ -10,6 +10,10 @@ class Admin::UsersController < Admin::AdminController
@users = User.order("created_at DESC, username") @users = User.order("created_at DESC, username")
end end
if ['newuser', 'basic', 'regular', 'leader', 'elder'].include?(params[:query])
@users = @users.where('trust_level = ?', TrustLevel.levels[params[:query].to_sym])
end
@users = @users.where('approved = false') if params[:query] == 'pending' @users = @users.where('approved = false') if params[:query] == 'pending'
@users = @users.where('username_lower like :filter or email like :filter', filter: "%#{params[:filter]}%") if params[:filter].present? @users = @users.where('username_lower like :filter or email like :filter', filter: "%#{params[:filter]}%") if params[:filter].present?
@users = @users.take(100) @users = @users.take(100)

View File

@ -913,6 +913,15 @@ en:
approved_selected: approved_selected:
one: "approve user" one: "approve user"
other: "approve users ({{count}})" other: "approve users ({{count}})"
titles:
active: 'Active Users'
new: 'New Users'
pending: 'Users Pending Review'
newuser: 'Users at Trust Level 0 (New User)'
basic: 'Users at Trust Level 1 (Basic User)'
regular: 'Users at Trust Level 2 (Regular User)'
leader: 'Users at Trust Level 3 (Leader)'
elder: 'Users at Trust Level 4 (Elder)'
user: user:
ban_failed: "Something went wrong banning this user {{error}}" ban_failed: "Something went wrong banning this user {{error}}"