diff --git a/js/controller/BoardController.js b/js/controller/BoardController.js index e6599f2f8..41729c8aa 100644 --- a/js/controller/BoardController.js +++ b/js/controller/BoardController.js @@ -323,7 +323,7 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St // remove from board data var i = BoardService.getCurrent().labels.indexOf(label); BoardService.getCurrent().labels.splice(i, 1); - + // remove from cards var cards = CardService.data; for (var card in cards) { @@ -346,11 +346,21 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St BoardService.getCurrent().labels.push(data); $scope.status.createLabel = false; $scope.newLabel = {}; + }).catch((err) => { + OC.Notification.showTemporary(err); }); }; + + $scope.labelUpdateBefore = function (label) { + label.renameTitle = label.title; + }; + $scope.labelUpdate = function (label) { label.edit = false; - LabelService.update(label); + LabelService.update(label).catch((err) => { + label.title = label.renameTitle; + OC.Notification.showTemporary(err); + }); // update labels in UI var cards = CardService.data; diff --git a/js/service/ApiService.js b/js/service/ApiService.js index 077ed4dd7..d5599e69a 100644 --- a/js/service/ApiService.js +++ b/js/service/ApiService.js @@ -119,7 +119,7 @@ app.factory('ApiService', function ($http, $q) { self.add(response.data); deferred.resolve(response.data); }, function (error) { - deferred.reject('Fetching' + self.endpoint + ' failed'); + deferred.reject(error.data.message); }); return deferred.promise; }; @@ -131,7 +131,7 @@ app.factory('ApiService', function ($http, $q) { self.add(response.data); deferred.resolve(response.data); }, function (error) { - deferred.reject('Updating ' + self.endpoint + ' failed'); + deferred.reject(error.data.message); }); return deferred.promise; diff --git a/lib/Service/LabelService.php b/lib/Service/LabelService.php index e46ee39ab..f596b19a2 100644 --- a/lib/Service/LabelService.php +++ b/lib/Service/LabelService.php @@ -91,6 +91,17 @@ class LabelService { } $this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE); + + $boardLabels = $this->labelMapper->findAll($boardId); + if (\is_array($boardLabels)) { + foreach($boardLabels as $boardLabel) { + if ($boardLabel->getTitle() === $title) { + throw new BadRequestException('title must be unique'); + break; + } + } + } + if ($this->boardService->isArchived(null, $boardId)) { throw new StatusException('Operation not allowed. This board is archived.'); } @@ -143,7 +154,7 @@ class LabelService { throw new BadRequestException('label id must be a number'); } - if ($title === false || $title === null) { + if ($title === false || $title === null || $title === "") { throw new BadRequestException('title must be provided'); } @@ -152,10 +163,26 @@ class LabelService { } $this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE); + + $label = $this->find($id); + + $boardLabels = $this->labelMapper->findAll($label->getBoardId()); + if (\is_array($boardLabels)) { + foreach($boardLabels as $boardLabel) { + if ($boardLabel->getId() === $label->getId()) { + continue; + } + if ($boardLabel->getTitle() === $title) { + throw new BadRequestException('title must be unique'); + break; + } + } + } + if ($this->boardService->isArchived($this->labelMapper, $id)) { throw new StatusException('Operation not allowed. This board is archived.'); } - $label = $this->find($id); + $label->setTitle($title); $label->setColor($color); $this->changeHelper->boardChanged($label->getBoardId()); diff --git a/templates/part.board.sidebarView.php b/templates/part.board.sidebarView.php index db35568be..928510b01 100644 --- a/templates/part.board.sidebarView.php +++ b/templates/part.board.sidebarView.php @@ -105,7 +105,7 @@ t('Update tag')); ?> - t('Edit tag')); ?> + t('Edit tag')); ?> t('Delete tag')); ?>