From 0137b882c5eb47431cc98135ec174cb659cdab5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 12 Jun 2018 17:14:54 +0200 Subject: [PATCH] Add attachment indicator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- css/style.scss | 8 ++++++-- js/controller/BoardController.js | 7 +++++++ js/service/CardService.js | 2 +- lib/Db/AttachmentMapper.php | 19 ++++++++++++++----- lib/Service/AttachmentService.php | 30 ++++++++++++++++++++++++++++-- lib/Service/CardService.php | 2 +- lib/Service/StackService.php | 8 +++++++- 7 files changed, 64 insertions(+), 12 deletions(-) diff --git a/css/style.scss b/css/style.scss index 1eeaa5974..64ca7f7ac 100644 --- a/css/style.scss +++ b/css/style.scss @@ -461,7 +461,7 @@ input.input-inline { } } - .card-tasks { + .card-tasks, .card-files { border-radius: 3px; margin: 4px 4px 4px 0px; padding: 0 2px; @@ -472,6 +472,7 @@ input.input-inline { .icon { background-size: contain; + margin-right: 2px; } } @@ -819,9 +820,12 @@ input.input-inline { position: relative; button { height: 32px; - width: 40px; + width: 42px; } } + button.icon-history { + width: 44px; + } } } diff --git a/js/controller/BoardController.js b/js/controller/BoardController.js index 6d4d7e615..4d0b0c95b 100644 --- a/js/controller/BoardController.js +++ b/js/controller/BoardController.js @@ -353,4 +353,11 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St }; }; + $scope.attachmentCount = function(attachments) { + if (Array.isArray(attachments)) { + return attachments.filter((obj) => obj.deletedAt === 0).length; + } + return attachments; + }; + }); diff --git a/js/service/CardService.js b/js/service/CardService.js index 324e8ed45..1e62d1bdd 100644 --- a/js/service/CardService.js +++ b/js/service/CardService.js @@ -137,7 +137,7 @@ app.factory('CardService', function (ApiService, $http, $q) { var deferred = $q.defer(); var self = this; $http.delete(this.baseUrl + '/' + this.getCurrent().id + '/attachment/' + attachment.id, {}).then(function (response) { - if (response.data.de#letedAt > 0) { + if (response.data.deletedAt > 0) { let currentAttachment = self.getCurrent().attachments.find(function (obj) { if (obj.id === attachment.id) { obj.deletedAt = response.data.deletedAt; diff --git a/lib/Db/AttachmentMapper.php b/lib/Db/AttachmentMapper.php index 7bb125723..cfbc75a0a 100644 --- a/lib/Db/AttachmentMapper.php +++ b/lib/Db/AttachmentMapper.php @@ -53,7 +53,7 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from('deck_attachment') - ->where($qb->expr()->eq('id', $id)); + ->where($qb->expr()->eq('id', (string)$id)); $cursor = $qb->execute(); $row = $cursor->fetch(PDO::FETCH_ASSOC); @@ -71,7 +71,9 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from('deck_attachment') - ->where($qb->expr()->eq('card_id', $cardId, IQueryBuilder::PARAM_INT)); + ->where($qb->expr()->eq('card_id', (string)$cardId, IQueryBuilder::PARAM_INT)) + ->andWhere($qb->expr()->eq('deleted_at', (string)0, IQueryBuilder::PARAM_INT)); + $entities = []; $cursor = $qb->execute(); @@ -82,14 +84,21 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper { return $entities; } - public function findToDelete() { + public function findToDelete($cardId = null, $withOffset = true) { // add buffer of 5 min $timeLimit = time() - (60 * 5); $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from('deck_attachment') - ->where($qb->expr()->gt('deleted_at', '0', IQueryBuilder::PARAM_INT)) - ->andWhere($qb->expr()->lt('deleted_at', (string)$timeLimit, IQueryBuilder::PARAM_INT)); + ->where($qb->expr()->gt('deleted_at', '0', IQueryBuilder::PARAM_INT)); + if ($withOffset) { + $qb + ->andWhere($qb->expr()->lt('deleted_at', (string)$timeLimit, IQueryBuilder::PARAM_INT)); + } + if ($cardId !== null) { + $qb + ->andWhere($qb->expr()->eq('card_id', (string)$cardId, IQueryBuilder::PARAM_INT)); + } $entities = []; $cursor = $qb->execute(); diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index 3155d650d..aa49be651 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -33,6 +33,8 @@ use OCA\Deck\InvalidAttachmentType; use OCA\Deck\NoPermissionException; use OCA\Deck\NotFoundException; use OCP\AppFramework\Http\Response; +use OCP\ICache; +use OCP\ICacheFactory; class AttachmentService { @@ -44,6 +46,8 @@ class AttachmentService { /** @var IAttachmentService[] */ private $services = []; private $application; + /** @var ICache */ + private $cache; /** * AttachmentService constructor. @@ -54,12 +58,14 @@ class AttachmentService { * @param $userId * @throws \OCP\AppFramework\QueryException */ - public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, PermissionService $permissionService, Application $application, $userId) { + public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, PermissionService $permissionService, Application $application, ICacheFactory $cacheFactory, $userId) { $this->attachmentMapper = $attachmentMapper; $this->cardMapper = $cardMapper; $this->permissionService = $permissionService; $this->userId = $userId; $this->application = $application; + $this->cache = $cacheFactory->createDistributed('deck-card-attachments-'); + // Register shipped attachment services // TODO: move this to a plugin based approach once we have different types of attachments @@ -92,10 +98,13 @@ class AttachmentService { * @return array * @throws \OCA\Deck\NoPermissionException */ - public function findAll($cardId) { + public function findAll($cardId, $withDeleted = false) { $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ); $attachments = $this->attachmentMapper->findAll($cardId); + if ($withDeleted) { + $attachments = array_merge($attachments, $this->attachmentMapper->findToDelete($cardId, false)); + } foreach ($attachments as &$attachment) { try { $service = $this->getService($attachment->getType()); @@ -107,9 +116,19 @@ class AttachmentService { return $attachments; } + public function count($cardId) { + $count = $this->cache->get('card-' . $cardId); + if (!$count) { + $count = count($this->attachmentMapper->findAll($cardId)); + $this->cache->set('card-' . $cardId, $count); + } + return $count; + } + public function create($cardId, $type, $data) { $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); + $this->cache->clear('card-' . $cardId); $attachment = new Attachment(); $attachment->setCardId($cardId); $attachment->setType($type); @@ -171,6 +190,9 @@ class AttachmentService { */ public function update($cardId, $attachmentId, $data) { $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); + + $this->cache->clear('card-' . $cardId); + $attachment = $this->attachmentMapper->find($attachmentId); $attachment->setData($data); try { @@ -196,6 +218,8 @@ class AttachmentService { public function delete($cardId, $attachmentId) { $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); + $this->cache->clear('card-' . $cardId); + $attachment = $this->attachmentMapper->find($attachmentId); try { $service = $this->getService($attachment->getType()); @@ -213,6 +237,8 @@ class AttachmentService { public function restore($cardId, $attachmentId) { $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); + $this->cache->clear('card-' . $cardId); + $attachment = $this->attachmentMapper->find($attachmentId); try { $service = $this->getService($attachment->getType()); diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index c9adcebe5..540913f72 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -54,7 +54,7 @@ class CardService { $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ); $card = $this->cardMapper->find($cardId); $assignedUsers = $this->assignedUsersMapper->find($card->getId()); - $attachments = $this->attachmentService->findAll($cardId); + $attachments = $this->attachmentService->findAll($cardId, true); $card->setAssignedUsers($assignedUsers); $card->setAttachments($attachments); return $card; diff --git a/lib/Service/StackService.php b/lib/Service/StackService.php index 598a5731c..12d988d24 100644 --- a/lib/Service/StackService.php +++ b/lib/Service/StackService.php @@ -30,6 +30,8 @@ use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\Stack; use OCA\Deck\Db\StackMapper; use OCA\Deck\StatusException; +use OCP\ICache; +use OCP\ICacheFactory; class StackService { @@ -40,6 +42,7 @@ class StackService { private $permissionService; private $boardService; private $assignedUsersMapper; + private $attachmentService; public function __construct( StackMapper $stackMapper, @@ -47,7 +50,8 @@ class StackService { LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService, - AssignedUsersMapper $assignedUsersMapper + AssignedUsersMapper $assignedUsersMapper, + AttachmentService $attachmentService ) { $this->stackMapper = $stackMapper; $this->cardMapper = $cardMapper; @@ -55,6 +59,7 @@ class StackService { $this->permissionService = $permissionService; $this->boardService = $boardService; $this->assignedUsersMapper = $assignedUsersMapper; + $this->attachmentService = $attachmentService; } public function findAll($boardId) { @@ -69,6 +74,7 @@ class StackService { if (array_key_exists($card->id, $labels)) { $cards[$cardIndex]->setLabels($labels[$card->id]); } + $card->setAttachments($this->attachmentService->count($card->getId())); } $stacks[$stackIndex]->setCards($cards); }