From f01cd506f7bc89f7c168fcf07a9b068dd61e9f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20R=C3=B6hrl?= Date: Thu, 24 Jan 2019 10:19:05 +0100 Subject: [PATCH] new try MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakob Röhrl --- js/controller/BoardController.js | 10 ++++++++-- lib/Service/LabelService.php | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/js/controller/BoardController.js b/js/controller/BoardController.js index e6599f2f8..6273875cb 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,17 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St BoardService.getCurrent().labels.push(data); $scope.status.createLabel = false; $scope.newLabel = {}; + }).catch(err => { + OC.Notification.showTemporary('Duplicate label name is not allowed'); }); }; + $scope.labelUpdate = function (label) { label.edit = false; - LabelService.update(label); + LabelService.update(label).catch(err => { + label.title('XXX'); + OC.Notification.showTemporary('Duplicate label name is not allowed'); + }); // update labels in UI var cards = CardService.data; diff --git a/lib/Service/LabelService.php b/lib/Service/LabelService.php index 44d2c255d..8bc041ca5 100644 --- a/lib/Service/LabelService.php +++ b/lib/Service/LabelService.php @@ -92,7 +92,14 @@ class LabelService { $this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE); - $this->checkDuplicateTitle($boardId, $title); + //$this->checkDuplicateTitle($boardId, $title); + $boardLabels = $this->labelMapper->findAll($boardId); + 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.'); @@ -157,7 +164,18 @@ class LabelService { $this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE); $label = $this->find($id); - $this->checkDuplicateTitle($label->getBoardId(), $title); + //$this->checkDuplicateTitle($label->getBoardId(), $title); + + $boardLabels = $this->labelMapper->findAll($label->getBoardId()); + 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.');