Remove existing shares from ui-select field

This commit is contained in:
Julius Haertl
2016-10-14 23:55:08 +02:00
parent 382b4175a6
commit c37f9384c3
6 changed files with 92 additions and 14 deletions

View File

@@ -126,7 +126,14 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
BoardService.searchUsers(); BoardService.searchUsers('%25');
$scope.searchForUser = function(search) {
if(search=="") {
search = "%25";
}
BoardService.searchUsers(search);
}
$scope.newStack = { 'boardId': $scope.id}; $scope.newStack = { 'boardId': $scope.id};
$scope.newCard = {}; $scope.newCard = {};

View File

@@ -223,7 +223,14 @@ app.controller('BoardController', ["$rootScope", "$scope", "$stateParams", "Stat
BoardService.searchUsers(); BoardService.searchUsers('%25');
$scope.searchForUser = function(search) {
if(search=="") {
search = "%25";
}
BoardService.searchUsers(search);
}
$scope.newStack = { 'boardId': $scope.id}; $scope.newStack = { 'boardId': $scope.id};
$scope.newCard = {}; $scope.newCard = {};
@@ -859,13 +866,26 @@ app.factory('BoardService', ["ApiService", "$http", "$q", function(ApiService, $
}; };
BoardService.prototype = angular.copy(ApiService.prototype); BoardService.prototype = angular.copy(ApiService.prototype);
BoardService.prototype.searchUsers = function() { BoardService.prototype.searchUsers = function(search) {
var url = OC.generateUrl('/apps/deck/share/search/%'); var url = OC.generateUrl('/apps/deck/share/search/'+search);
var deferred = $q.defer(); var deferred = $q.defer();
var self = this; var self = this;
this.sharees = [];
$http.get(url).then(function (response) { $http.get(url).then(function (response) {
self.sharees = response.data;
self.sharees = [];
// filter out everyone who is already in the share list
angular.forEach(response.data, function(item) {
var exists = false;
angular.forEach(self.getCurrent().acl, function(acl) {
if (acl.participant === item.participant) {
exists = true;
}
});
if(!exists) {
self.sharees.push(item);
}
});
deferred.resolve(response.data); deferred.resolve(response.data);
}, function (error) { }, function (error) {
deferred.reject('Error while update ' + self.endpoint); deferred.reject('Error while update ' + self.endpoint);

View File

@@ -26,13 +26,26 @@ app.factory('BoardService', function(ApiService, $http, $q){
}; };
BoardService.prototype = angular.copy(ApiService.prototype); BoardService.prototype = angular.copy(ApiService.prototype);
BoardService.prototype.searchUsers = function() { BoardService.prototype.searchUsers = function(search) {
var url = OC.generateUrl('/apps/deck/share/search/%'); var url = OC.generateUrl('/apps/deck/share/search/'+search);
var deferred = $q.defer(); var deferred = $q.defer();
var self = this; var self = this;
this.sharees = [];
$http.get(url).then(function (response) { $http.get(url).then(function (response) {
self.sharees = response.data;
self.sharees = [];
// filter out everyone who is already in the share list
angular.forEach(response.data, function(item) {
var exists = false;
angular.forEach(self.getCurrent().acl, function(acl) {
if (acl.participant === item.participant) {
exists = true;
}
});
if(!exists) {
self.sharees.push(item);
}
});
deferred.resolve(response.data); deferred.resolve(response.data);
}, function (error) { }, function (error) {
deferred.reject('Error while update ' + self.endpoint); deferred.reject('Error while update ' + self.endpoint);

View File

@@ -26,14 +26,15 @@ namespace OCA\Deck\Controller;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IRequest; use OCP\IRequest;
use OCP\AppFramework\ApiController as BaseApiController;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\IUserManager; use OCP\IUserManager;
class ShareController extends Controller { class ShareController extends Controller {
protected $userManager; protected $userManager;
protected $groupManager; protected $groupManager;
private $userId; private $userId;
public function __construct($appName, public function __construct($appName,
IRequest $request, IRequest $request,
IUserManager $userManager, IUserManager $userManager,
@@ -48,9 +49,10 @@ class ShareController extends Controller {
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
* @RequireNoPermission
*/ */
public function searchUser($search) { public function searchUser($search) {
$limit = null; $limit = 3;
$offset = null; $offset = null;
$result = []; $result = [];
foreach ($this->groupManager->search($search, $limit, $offset) as $idx => $group) { foreach ($this->groupManager->search($search, $limit, $offset) as $idx => $group) {
@@ -62,6 +64,7 @@ class ShareController extends Controller {
$acl->setPermissionManage(true); $acl->setPermissionManage(true);
$result[] = $acl; $result[] = $acl;
} }
$limit = 10;
foreach ($this->userManager->searchDisplayName($search, $limit, $offset) as $idx => $user) { foreach ($this->userManager->searchDisplayName($search, $limit, $offset) as $idx => $user) {
if($user->getUID() === $this->userId) if($user->getUID() === $this->userId)
continue; continue;

35
lib/NotFoundException.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck;
class NoPermissionException extends \Exception {
public function __construct($message, $controller=null, $method=null) {
parent::__construct($message);
if($controller && $method) {
$this->message = get_class($controller) . "#" . $method . ": " . $message;
}
}
}

View File

@@ -21,8 +21,8 @@
<ui-select-match placeholder="<?php p($l->t('Select users...')); ?>"> <ui-select-match placeholder="<?php p($l->t('Select users...')); ?>">
<span><i class="icon icon-{{$item.type}}"></i> {{ $item.participant }}</span> <span><i class="icon icon-{{$item.type}}"></i> {{ $item.participant }}</span>
</ui-select-match> </ui-select-match>
<!-- FIXME: filter by selected or add multiple //--> <ui-select-choices refresh="searchForUser($select.search)"
<ui-select-choices repeat="sharee in boardservice.sharees | filter: board.sharees | filter: $select.search track by $index"> refresh-delay="0" repeat="sharee in boardservice.sharees">
<span><i class="icon icon-{{sharee.type}}"></i> {{ sharee.participant }}</span> <span><i class="icon icon-{{sharee.type}}"></i> {{ sharee.participant }}</span>
</ui-select-choices> </ui-select-choices>
<ui-select-no-choice> <ui-select-no-choice>