Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-06-12 17:14:54 +02:00
Родитель ee5a54a575
Коммит 0137b882c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
7 изменённых файлов: 64 добавлений и 12 удалений

Просмотреть файл

@ -461,7 +461,7 @@ input.input-inline {
} }
} }
.card-tasks { .card-tasks, .card-files {
border-radius: 3px; border-radius: 3px;
margin: 4px 4px 4px 0px; margin: 4px 4px 4px 0px;
padding: 0 2px; padding: 0 2px;
@ -472,6 +472,7 @@ input.input-inline {
.icon { .icon {
background-size: contain; background-size: contain;
margin-right: 2px;
} }
} }
@ -819,9 +820,12 @@ input.input-inline {
position: relative; position: relative;
button { button {
height: 32px; 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 deferred = $q.defer();
var self = this; var self = this;
$http.delete(this.baseUrl + '/' + this.getCurrent().id + '/attachment/' + attachment.id, {}).then(function (response) { $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) { let currentAttachment = self.getCurrent().attachments.find(function (obj) {
if (obj.id === attachment.id) { if (obj.id === attachment.id) {
obj.deletedAt = response.data.deletedAt; obj.deletedAt = response.data.deletedAt;

Просмотреть файл

@ -53,7 +53,7 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
->from('deck_attachment') ->from('deck_attachment')
->where($qb->expr()->eq('id', $id)); ->where($qb->expr()->eq('id', (string)$id));
$cursor = $qb->execute(); $cursor = $qb->execute();
$row = $cursor->fetch(PDO::FETCH_ASSOC); $row = $cursor->fetch(PDO::FETCH_ASSOC);
@ -71,7 +71,9 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
->from('deck_attachment') ->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 = []; $entities = [];
$cursor = $qb->execute(); $cursor = $qb->execute();
@ -82,14 +84,21 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
return $entities; return $entities;
} }
public function findToDelete() { public function findToDelete($cardId = null, $withOffset = true) {
// add buffer of 5 min // add buffer of 5 min
$timeLimit = time() - (60 * 5); $timeLimit = time() - (60 * 5);
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
->from('deck_attachment') ->from('deck_attachment')
->where($qb->expr()->gt('deleted_at', '0', IQueryBuilder::PARAM_INT)) ->where($qb->expr()->gt('deleted_at', '0', IQueryBuilder::PARAM_INT));
->andWhere($qb->expr()->lt('deleted_at', (string)$timeLimit, 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 = []; $entities = [];
$cursor = $qb->execute(); $cursor = $qb->execute();

Просмотреть файл

@ -33,6 +33,8 @@ use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\NoPermissionException; use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException; use OCA\Deck\NotFoundException;
use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Response;
use OCP\ICache;
use OCP\ICacheFactory;
class AttachmentService { class AttachmentService {
@ -44,6 +46,8 @@ class AttachmentService {
/** @var IAttachmentService[] */ /** @var IAttachmentService[] */
private $services = []; private $services = [];
private $application; private $application;
/** @var ICache */
private $cache;
/** /**
* AttachmentService constructor. * AttachmentService constructor.
@ -54,12 +58,14 @@ class AttachmentService {
* @param $userId * @param $userId
* @throws \OCP\AppFramework\QueryException * @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->attachmentMapper = $attachmentMapper;
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
$this->userId = $userId; $this->userId = $userId;
$this->application = $application; $this->application = $application;
$this->cache = $cacheFactory->createDistributed('deck-card-attachments-');
// Register shipped attachment services // Register shipped attachment services
// TODO: move this to a plugin based approach once we have different types of attachments // TODO: move this to a plugin based approach once we have different types of attachments
@ -92,10 +98,13 @@ class AttachmentService {
* @return array * @return array
* @throws \OCA\Deck\NoPermissionException * @throws \OCA\Deck\NoPermissionException
*/ */
public function findAll($cardId) { public function findAll($cardId, $withDeleted = false) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
$attachments = $this->attachmentMapper->findAll($cardId); $attachments = $this->attachmentMapper->findAll($cardId);
if ($withDeleted) {
$attachments = array_merge($attachments, $this->attachmentMapper->findToDelete($cardId, false));
}
foreach ($attachments as &$attachment) { foreach ($attachments as &$attachment) {
try { try {
$service = $this->getService($attachment->getType()); $service = $this->getService($attachment->getType());
@ -107,9 +116,19 @@ class AttachmentService {
return $attachments; 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) { public function create($cardId, $type, $data) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $cardId);
$attachment = new Attachment(); $attachment = new Attachment();
$attachment->setCardId($cardId); $attachment->setCardId($cardId);
$attachment->setType($type); $attachment->setType($type);
@ -171,6 +190,9 @@ class AttachmentService {
*/ */
public function update($cardId, $attachmentId, $data) { public function update($cardId, $attachmentId, $data) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $cardId);
$attachment = $this->attachmentMapper->find($attachmentId); $attachment = $this->attachmentMapper->find($attachmentId);
$attachment->setData($data); $attachment->setData($data);
try { try {
@ -196,6 +218,8 @@ class AttachmentService {
public function delete($cardId, $attachmentId) { public function delete($cardId, $attachmentId) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $cardId);
$attachment = $this->attachmentMapper->find($attachmentId); $attachment = $this->attachmentMapper->find($attachmentId);
try { try {
$service = $this->getService($attachment->getType()); $service = $this->getService($attachment->getType());
@ -213,6 +237,8 @@ class AttachmentService {
public function restore($cardId, $attachmentId) { public function restore($cardId, $attachmentId) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $cardId);
$attachment = $this->attachmentMapper->find($attachmentId); $attachment = $this->attachmentMapper->find($attachmentId);
try { try {
$service = $this->getService($attachment->getType()); $service = $this->getService($attachment->getType());

Просмотреть файл

@ -54,7 +54,7 @@ class CardService {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
$card = $this->cardMapper->find($cardId); $card = $this->cardMapper->find($cardId);
$assignedUsers = $this->assignedUsersMapper->find($card->getId()); $assignedUsers = $this->assignedUsersMapper->find($card->getId());
$attachments = $this->attachmentService->findAll($cardId); $attachments = $this->attachmentService->findAll($cardId, true);
$card->setAssignedUsers($assignedUsers); $card->setAssignedUsers($assignedUsers);
$card->setAttachments($attachments); $card->setAttachments($attachments);
return $card; return $card;

Просмотреть файл

@ -30,6 +30,8 @@ use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Stack; use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper; use OCA\Deck\Db\StackMapper;
use OCA\Deck\StatusException; use OCA\Deck\StatusException;
use OCP\ICache;
use OCP\ICacheFactory;
class StackService { class StackService {
@ -40,6 +42,7 @@ class StackService {
private $permissionService; private $permissionService;
private $boardService; private $boardService;
private $assignedUsersMapper; private $assignedUsersMapper;
private $attachmentService;
public function __construct( public function __construct(
StackMapper $stackMapper, StackMapper $stackMapper,
@ -47,7 +50,8 @@ class StackService {
LabelMapper $labelMapper, LabelMapper $labelMapper,
PermissionService $permissionService, PermissionService $permissionService,
BoardService $boardService, BoardService $boardService,
AssignedUsersMapper $assignedUsersMapper AssignedUsersMapper $assignedUsersMapper,
AttachmentService $attachmentService
) { ) {
$this->stackMapper = $stackMapper; $this->stackMapper = $stackMapper;
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
@ -55,6 +59,7 @@ class StackService {
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
$this->boardService = $boardService; $this->boardService = $boardService;
$this->assignedUsersMapper = $assignedUsersMapper; $this->assignedUsersMapper = $assignedUsersMapper;
$this->attachmentService = $attachmentService;
} }
public function findAll($boardId) { public function findAll($boardId) {
@ -69,6 +74,7 @@ class StackService {
if (array_key_exists($card->id, $labels)) { if (array_key_exists($card->id, $labels)) {
$cards[$cardIndex]->setLabels($labels[$card->id]); $cards[$cardIndex]->setLabels($labels[$card->id]);
} }
$card->setAttachments($this->attachmentService->count($card->getId()));
} }
$stacks[$stackIndex]->setCards($cards); $stacks[$stackIndex]->setCards($cards);
} }