зеркало из https://github.com/nextcloud/deck.git
Add attachment indicator
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
ee5a54a575
Коммит
0137b882c5
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче