enable group filtering

This commit is contained in:
Arthur Schiwon 2014-04-15 00:13:23 +02:00
parent dbc854d8b8
commit 249e42c4cd
7 changed files with 143 additions and 15 deletions

View File

@ -0,0 +1,75 @@
<?php
/**
* ownCloud
*
* @author Arthur Schiwon
* @copyright 2014 Arthur Schiwon <blizzz@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
OC_JSON::callCheck();
OC_JSON::checkSubAdminUser();
if (isset($_GET['pattern']) && !empty($_GET['pattern'])) {
$pattern = $_GET['pattern'];
} else {
$pattern = '';
}
$groups = array();
$adminGroups = array();
$groupManager = \OC_Group::getManager();
$accessiblegroups = $groupManager->search($pattern);
if (!OC_User::isAdminUser(OC_User::getUser())) {
$subadminGroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
$accessiblegroups = array_intersect($accessiblegroups, $subadminGroups);
}
$sortGroupsIndex = 0;
$sortGroupsKeys = array();
$sortAdminGroupsIndex = 0;
$sortAdminGroupsKeys = array();
foreach($accessiblegroups as $group) {
$gid = $group->getGID();
$usersInGroup = OC_Group::usersInGroup($gid, '');
if (!OC_User::isAdminUser($gid)) {
$groups[] = array(
'id' => str_replace(' ','', $gid ),
'name' => $gid,
'usercount' => count($usersInGroup),
);
$sortGroupsKeys[$sortGroupsIndex] = count($usersInGroup);
$sortGroupsIndex++;
} else {
$adminGroup[] = array(
'id' => str_replace(' ','', $gid ),
'name' => $gid,
'usercount' => count($usersInGroup)
);
$sortAdminGroupsKeys[$sortAdminGroupsIndex] = count($usersInGroup);
$sortAdminGroupsIndex++;
}
}
if(!empty($groups)) {
array_multisort($sortGroupsKeys, SORT_DESC, $groups);
}
if(!empty($adminGroup)) {
array_multisort($sortAdminGroupsKeys, SORT_DESC, $adminGroup);
}
OC_JSON::success(
array('data' => array('adminGroups' => $adminGroups, 'groups' => $groups)));

View File

@ -10,9 +10,10 @@
* @param jQuery input element that works as the user text input field
* @param object the UserList object
*/
function UserManagementFilter(filterInput, userList) {
function UserManagementFilter(filterInput, userList, groupList) {
this.filterInput = filterInput;
this.userList = userList;
this.groupList = groupList;
this.thread = undefined;
this.oldval = this.filterInput.val();
@ -25,8 +26,6 @@ function UserManagementFilter(filterInput, userList) {
UserManagementFilter.prototype.init = function() {
umf = this;
this.filterInput.keyup(function(e) {
console.log(e.keyCode);
//we want to react on any printable letter, plus on modyfing stuff like
//Backspace and Delete. extended https://stackoverflow.com/a/12467610
var valid =
@ -61,6 +60,8 @@ UserManagementFilter.prototype.init = function() {
UserManagementFilter.prototype.run = function() {
this.userList.empty();
this.userList.update();
this.groupList.empty();
this.groupList.update();
}
/**

View File

@ -6,17 +6,22 @@
*/
var GroupList = {
addGroup: function(gid) {
addGroup: function(gid, usercount) {
if(usercount === undefined || usercount === 0) {
usercount = '';
}
var li = $('li[data-gid]').last().clone();
var ul = $('li[data-gid]').first().parent();
li.attr('data-gid', gid);
li.attr('data-usercount', 0);
li.attr('data-usercount', usercount);
li.find('a span').first().text(gid);
li.find('span[class=usercount]').first().text('');
li.find('span[class=usercount]').first().text(usercount);
$(li).appendTo(ul);
GroupList.sortGroups(0);
return li;
},
sortGroups: function(usercount) {
@ -75,6 +80,41 @@
)
},
update: function() {
if (GroupList.updating) {
return;
}
GroupList.updating = true;
pattern = filter.getPattern();
var query = $.param({ pattern: pattern });
$.get(OC.generateUrl('/settings/ajax/grouplist') + '?' + query, function (result) {
var lis = [];
if (result.status === 'success') {
$.each(result.data, function (i, subset) {
$.each(subset, function (index, group) {
if($('li[data-gid="' + group.name + '"]').length > 0) {
return true;
}
var li = GroupList.addGroup(group.name, group.usercount);
li.addClass('appear transparent');
lis.push(li);
});
});
if (result.data.length > 0) {
GroupList.doSort();
} else {
GroupList.noMoreEntries = true;
}
setTimeout(function() {
for (var i = 0; i < lis.length; i++) {
lis[i].removeClass('transparent');
}
}, 0);
}
GroupList.updating = false;
});
},
elementBelongsToAddGroup: function(el) {
return !(el !== $('#newgroup-form').get(0)
&& $('#newgroup-form').find($(el)).length === 0);
@ -134,6 +174,9 @@
remove: function(gid) {
$('li').filterAttr('data-gid', gid).remove();
},
empty: function() {
$('li:not([data-gid=""])').remove();
},
initDeleteHandling: function() {
//set up handler
GroupDeleteHandler = new DeleteHandler('removegroup.php', 'groupname',

View File

@ -403,8 +403,6 @@ $(document).ready(function () {
UserList.applyMultiplySelect($(element));
});
$('table').on('click', 'td.password>img', function (event) {
event.stopPropagation();
var img = $(this);
@ -549,5 +547,6 @@ $(document).ready(function () {
);
});
// Implements User Search
filter = new UserManagementFilter($('#usersearchform input'), UserList);
filter = new UserManagementFilter(
$('#usersearchform input'), UserList, GroupList);
});

View File

@ -25,6 +25,8 @@ $this->create('settings_admin', '/settings/admin')
// users
$this->create('settings_ajax_userlist', '/settings/ajax/userlist')
->actionInclude('settings/ajax/userlist.php');
$this->create('settings_ajax_grouplist', '/settings/ajax/grouplist')
->actionInclude('settings/ajax/grouplist.php');
$this->create('settings_ajax_createuser', '/settings/ajax/createuser.php')
->actionInclude('settings/ajax/createuser.php');
$this->create('settings_ajax_removeuser', '/settings/ajax/removeuser.php')

View File

@ -18,6 +18,9 @@
<?php p($l->t('Everyone')); ?>
</span>
</a>
<span class="utils">
<span class="usercount"></span>
</span>
</li>
<!-- The Admin Group -->
@ -25,21 +28,21 @@
<li data-gid="admin">
<a href="#"><?php p($l->t('Admins')); ?></a>
<span class="utils">
<span class="usercount"><?php if(count($adminGroup['useringroup']) > 0) { p(count($adminGroup['useringroup'])); } ?></span>
<span class="usercount"><?php if($adminGroup['useringroup'] > 0) { p($adminGroup['useringroup']); } ?></span>
</span>
</li>
<?php endforeach; ?>
<!--List of Groups-->
<?php foreach($_["groups"] as $group): ?>
<li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p(count($group['useringroup'])) ?>">
<li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p($group['useringroup']) ?>">
<a href="#">
<span><?php p($group['name']); ?></span>
<img class="svg action rename" src="<?php p(image_path('core', 'actions/rename.svg'))?>"
original-title="<?php p($l->t('Edit'))?>" alt="<?php p($l->t("change group name"))?>" title="<?php p($l->t("change group name"))?>" />
</a>
<span class="utils">
<span class="usercount"><?php if(count($group['useringroup']) > 0) { p(count($group['useringroup'])); } ?></span>
<span class="usercount"><?php if($group['useringroup'] > 0) { p($group['useringroup']); } ?></span>
<a href="#" class="action delete" original-title="<?php p($l->t('Delete'))?>">
<img src="<?php print_unescaped(image_path('core', 'actions/delete.svg')) ?>" class="svg" />
</a>

View File

@ -22,6 +22,7 @@ $users = array();
$groups = array();
$adminGroup = array();
$userManager = \OC_User::getManager();
$groupManager = \OC_Group::getManager();
if (isset($_GET['offset'])) {
$offset = $_GET['offset'];
@ -89,14 +90,18 @@ $sortGroupsKeys = array();
$sortAdminGroupsIndex = 0;
$sortAdminGroupsKeys = array();
foreach( $accessiblegroups as $gid ) {
$usersInGroup = OC_Group::usersInGroup($gid, '', $limit, $offset);
$group = $groupManager->get($gid);
if(!$group) {
continue;
}
$usersInGroup = $group->count();
if (!OC_User::isAdminUser($gid)) {
$groups[] = array(
'id' => str_replace(' ','', $gid ),
'name' => $gid,
'useringroup' => $usersInGroup,
);
$sortGroupsKeys[$sortGroupsIndex] = count($usersInGroup);
$sortGroupsKeys[$sortGroupsIndex] = $usersInGroup;
$sortGroupsIndex++;
} else {
$adminGroup[] = array(
@ -104,7 +109,7 @@ foreach( $accessiblegroups as $gid ) {
'name' => $gid,
'useringroup' => $usersInGroup
);
$sortAdminGroupsKeys[$sortAdminGroupsIndex] = count($usersInGroup);
$sortAdminGroupsKeys[$sortAdminGroupsIndex] = $usersInGroup;
$sortAdminGroupsIndex++;
}
}