##// END OF EJS Templates
admin users and admin users group: add number of inactive users/users_group, resolves #5454
Bartłomiej Wołyńczyk -
r2727:15796c8e default
parent child Browse files
Show More
@@ -41,6 +41,7 b' from rhodecode.model.db import ('
41 41 or_, count, User, UserGroup, UserGroupMember)
42 42 from rhodecode.model.meta import Session
43 43 from rhodecode.model.user_group import UserGroupModel
44 from rhodecode.model.db import true
44 45
45 46 log = logging.getLogger(__name__)
46 47
@@ -108,6 +109,10 b' class AdminUserGroupsView(BaseAppView, D'
108 109 .filter(UserGroup.users_group_id.in_(allowed_ids))\
109 110 .count()
110 111
112 user_groups_data_total_inactive_count = UserGroup.query()\
113 .filter(UserGroup.users_group_id.in_(allowed_ids))\
114 .filter(UserGroup.users_group_active != true()).count()
115
111 116 member_count = count(UserGroupMember.user_id)
112 117 base_q = Session.query(
113 118 UserGroup.users_group_name,
@@ -123,13 +128,17 b' class AdminUserGroupsView(BaseAppView, D'
123 128 .join(User, User.user_id == UserGroup.user_id) \
124 129 .group_by(UserGroup, User)
125 130
131 base_q_inactive = base_q.filter(UserGroup.users_group_active != true())
132
126 133 if search_q:
127 134 like_expression = u'%{}%'.format(safe_unicode(search_q))
128 135 base_q = base_q.filter(or_(
129 136 UserGroup.users_group_name.ilike(like_expression),
130 137 ))
138 base_q_inactive = base_q.filter(UserGroup.users_group_active != true())
131 139
132 140 user_groups_data_total_filtered_count = base_q.count()
141 user_groups_data_total_filtered_inactive_count = base_q_inactive.count()
133 142
134 143 if order_by == 'members_total':
135 144 sort_col = member_count
@@ -171,7 +180,9 b' class AdminUserGroupsView(BaseAppView, D'
171 180 'draw': draw,
172 181 'data': user_groups_data,
173 182 'recordsTotal': user_groups_data_total_count,
183 'recordsTotalInactive': user_groups_data_total_inactive_count,
174 184 'recordsFiltered': user_groups_data_total_filtered_count,
185 'recordsFilteredInactive': user_groups_data_total_filtered_inactive_count,
175 186 })
176 187
177 188 return data
@@ -32,6 +32,7 b' from rhodecode.apps._base import BaseApp'
32 32 from rhodecode.apps.ssh_support import SshKeyFileChangeEvent
33 33 from rhodecode.authentication.plugins import auth_rhodecode
34 34 from rhodecode.events import trigger
35 from rhodecode.model.db import true
35 36
36 37 from rhodecode.lib import audit_logger
37 38 from rhodecode.lib.exceptions import (
@@ -89,7 +90,6 b' class AdminUsersView(BaseAppView, DataGr'
89 90 draw, start, limit = self._extract_chunk(self.request)
90 91 search_q, order_by, order_dir = self._extract_ordering(
91 92 self.request, column_map=column_map)
92
93 93 _render = self.request.get_partial_renderer(
94 94 'rhodecode:templates/data_table/_dt_elements.mako')
95 95
@@ -100,8 +100,14 b' class AdminUsersView(BaseAppView, DataGr'
100 100 .filter(User.username != User.DEFAULT_USER) \
101 101 .count()
102 102
103 users_data_total_inactive_count = User.query()\
104 .filter(User.username != User.DEFAULT_USER) \
105 .filter(User.active != true())\
106 .count()
107
103 108 # json generate
104 109 base_q = User.query().filter(User.username != User.DEFAULT_USER)
110 base_inactive_q = base_q.filter(User.active != true())
105 111
106 112 if search_q:
107 113 like_expression = u'%{}%'.format(safe_unicode(search_q))
@@ -111,8 +117,10 b' class AdminUsersView(BaseAppView, DataGr'
111 117 User.name.ilike(like_expression),
112 118 User.lastname.ilike(like_expression),
113 119 ))
120 base_inactive_q = base_q.filter(User.active != true())
114 121
115 122 users_data_total_filtered_count = base_q.count()
123 users_data_total_filtered_inactive_count = base_inactive_q.count()
116 124
117 125 sort_col = getattr(User, order_by, None)
118 126 if sort_col:
@@ -148,12 +156,13 b' class AdminUsersView(BaseAppView, DataGr'
148 156 "extern_name": user.extern_name,
149 157 "action": user_actions(user.user_id, user.username),
150 158 })
151
152 159 data = ({
153 160 'draw': draw,
154 161 'data': users_data,
155 162 'recordsTotal': users_data_total_count,
156 163 'recordsFiltered': users_data_total_filtered_count,
164 'recordsTotalInactive': users_data_total_inactive_count,
165 'recordsFilteredInactive': users_data_total_filtered_inactive_count
157 166 })
158 167
159 168 return data
@@ -10,7 +10,7 b''
10 10
11 11 <%def name="breadcrumbs_links()">
12 12 <input class="q_filter_box" id="q_filter" size="15" type="text" name="filter" placeholder="${_('quick filter...')}" value=""/>
13 ${h.link_to(_('Admin'),h.route_path('admin_home'))} &raquo; <span id="user_group_count">0</span> ${_('user groups')}
13 ${h.link_to(_('Admin'),h.route_path('admin_home'))} &raquo; <span id="user_group_count">0</span>
14 14 </%def>
15 15
16 16 <%def name="menu_bar_nav()">
@@ -38,21 +38,33 b''
38 38 </div>
39 39 <script>
40 40 $(document).ready(function() {
41 var getDatatableCount = function(){
42 var table = $('#user_group_list_table').dataTable();
43 var page = table.api().page.info();
44 var active = page.recordsDisplay;
45 var total = page.recordsTotal;
46
47 var _text = _gettext("{0} out of {1} users").format(active, total);
48 $('#user_group_count').text(_text);
49 };
41 var $userGroupsListTable = $('#user_group_list_table');
50 42
51 43 // user list
52 $('#user_group_list_table').DataTable({
44 $userGroupsListTable.DataTable({
53 45 processing: true,
54 46 serverSide: true,
55 ajax: "${h.route_path('user_groups_data')}",
47 ajax: {
48 "url": "${h.route_path('user_groups_data')}",
49 "dataSrc": function (json) {
50 var filteredCount = json.recordsFiltered;
51 var filteredInactiveCount = json.recordsFilteredInactive;
52 var totalInactive = json.recordsTotalInactive;
53 var total = json.recordsTotal;
54
55 var _text = _gettext(
56 "{0} ({1} inactive) of {2} user groups ({3} inactive)").format(
57 filteredCount, filteredInactiveCount, total, totalInactive);
58
59 if (total === filteredCount) {
60 _text = _gettext(
61 "{0} user groups ({1} inactive)").format(total, totalInactive);
62 }
63 $('#user_group_count').text(_text);
64 return json.data;
65 },
66 },
67
56 68 dom: 'rtp',
57 69 pageLength: ${c.visual.admin_grid_items},
58 70 order: [[ 0, "asc" ]],
@@ -79,17 +91,12 b''
79 91 }
80 92 });
81 93
82 $('#user_group_list_table').on('xhr.dt', function(e, settings, json, xhr){
83 $('#user_group_list_table').css('opacity', 1);
94 $userGroupsListTable.on('xhr.dt', function(e, settings, json, xhr){
95 $userGroupsListTable.css('opacity', 1);
84 96 });
85 97
86 $('#user_group_list_table').on('preXhr.dt', function(e, settings, data){
87 $('#user_group_list_table').css('opacity', 0.3);
88 });
89
90 // refresh counters on draw
91 $('#user_group_list_table').on('draw.dt', function(){
92 getDatatableCount();
98 $userGroupsListTable.on('preXhr.dt', function(e, settings, data){
99 $userGroupsListTable.css('opacity', 0.3);
93 100 });
94 101
95 102 // filter
@@ -39,22 +39,30 b''
39 39
40 40 $(document).ready(function() {
41 41 var $userListTable = $('#user_list_table');
42
43 var getDatatableCount = function(){
44 var table = $userListTable.dataTable();
45 var page = table.api().page.info();
46 var active = page.recordsDisplay;
47 var total = page.recordsTotal;
48
49 var _text = _gettext("{0} out of {1} users").format(active, total);
50 $('#user_count').text(_text);
51 };
52
53 42 // user list
54 43 $userListTable.DataTable({
55 44 processing: true,
56 45 serverSide: true,
57 ajax: "${h.route_path('users_data')}",
46 ajax: {
47 "url": "${h.route_path('users_data')}",
48 "dataSrc": function ( json ) {
49 var filteredCount = json.recordsFiltered;
50 var filteredInactiveCount = json.recordsFilteredInactive;
51 var totalInactive = json.recordsTotalInactive;
52 var total = json.recordsTotal;
53
54 var _text = _gettext(
55 "{0} ({1} inactive) of {2} users ({3} inactive)").format(
56 filteredCount, filteredInactiveCount, total, totalInactive);
57
58 if(total === filteredCount){
59 _text = _gettext(
60 "{0} users ({1} inactive)").format(total, totalInactive);
61 }
62 $('#user_count').text(_text);
63 return json.data;
64 }
65 },
58 66 dom: 'rtp',
59 67 pageLength: ${c.visual.admin_grid_items},
60 68 order: [[ 0, "asc" ]],
@@ -100,11 +108,6 b''
100 108 $userListTable.css('opacity', 0.3);
101 109 });
102 110
103 // refresh counters on draw
104 $userListTable.on('draw.dt', function(){
105 getDatatableCount();
106 });
107
108 111 // filter
109 112 $('#q_filter').on('keyup',
110 113 $.debounce(250, function() {
General Comments 0
You need to be logged in to leave comments. Login now