Merge pull request #4422 from nextcloud/enh/noid/discoverable-searchable-ref-provider

This commit is contained in:
Julius Härtl
2023-02-10 14:45:23 +01:00
committed by GitHub
18 changed files with 891 additions and 46 deletions

10
composer.lock generated
View File

@@ -1257,12 +1257,12 @@
"source": {
"type": "git",
"url": "https://github.com/nextcloud-deps/ocp.git",
"reference": "1aaead8ad471e72441257d41fb15eb55ea174d00"
"reference": "5636b942e35ee391b1103150261d83d3d753d657"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/1aaead8ad471e72441257d41fb15eb55ea174d00",
"reference": "1aaead8ad471e72441257d41fb15eb55ea174d00",
"url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/5636b942e35ee391b1103150261d83d3d753d657",
"reference": "5636b942e35ee391b1103150261d83d3d753d657",
"shasum": ""
},
"require": {
@@ -1294,7 +1294,7 @@
"issues": "https://github.com/nextcloud-deps/ocp/issues",
"source": "https://github.com/nextcloud-deps/ocp/tree/master"
},
"time": "2023-01-11T00:37:34+00:00"
"time": "2023-02-08T00:37:37+00:00"
},
{
"name": "nikic/php-parser",
@@ -5477,5 +5477,5 @@
"platform-overrides": {
"php": "8.0"
},
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.2.0"
}

3
img/card.svg Normal file
View File

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" style="height: 240px; width: 240px;" viewBox="0 0 24 24">
<path fill="currentColor" d="M12,15H10V13H12V15M18,15H14V13H18V15M8,11H6V9H8V11M18,11H10V9H18V11M20,20H4A2,2 0 0,1 2,18V6A2,2 0 0,1 4,4H20A2,2 0 0,1 22,6V18A2,2 0 0,1 20,20M4,6V18H20V6H4Z" />
</svg>

After

Width:  |  Height:  |  Size: 298 B

View File

@@ -50,7 +50,9 @@ use OCA\Deck\Listeners\LiveUpdateListener;
use OCA\Deck\Middleware\DefaultBoardMiddleware;
use OCA\Deck\Middleware\ExceptionMiddleware;
use OCA\Deck\Notification\Notifier;
use OCA\Deck\Reference\BoardReferenceProvider;
use OCA\Deck\Reference\CardReferenceProvider;
use OCA\Deck\Reference\CommentReferenceProvider;
use OCA\Deck\Search\CardCommentProvider;
use OCA\Deck\Search\DeckProvider;
use OCA\Deck\Service\PermissionService;
@@ -88,7 +90,7 @@ class Application extends App implements IBootstrap {
$container = $this->getContainer();
$eventDispatcher = $container->get(IEventDispatcher::class);
$eventDispatcher->addListener(RenderReferenceEvent::class, function () {
Util::addScript(self::APP_ID, self::APP_ID . '-card-reference');
Util::addScript(self::APP_ID, self::APP_ID . '-reference');
});
}
@@ -128,7 +130,8 @@ class Application extends App implements IBootstrap {
// reference widget
$context->registerReferenceProvider(CardReferenceProvider::class);
// $context->registerEventListener(RenderReferenceEvent::class, CardReferenceListener::class);
$context->registerReferenceProvider(BoardReferenceProvider::class);
$context->registerReferenceProvider(CommentReferenceProvider::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);

View File

@@ -0,0 +1,128 @@
<?php
/**
* @copyright Copyright (c) 2022 Julien Veyssier <eneiluj@posteo.net>
*
* @author Julien Veyssier <eneiluj@posteo.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCA\Deck\Reference;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\Service\BoardService;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\Collaboration\Reference\Reference;
use OCP\IL10N;
use OCP\IURLGenerator;
class BoardReferenceProvider implements IReferenceProvider {
private IURLGenerator $urlGenerator;
private BoardService $boardService;
private ?string $userId;
private IL10N $l10n;
public function __construct(BoardService $boardService,
IURLGenerator $urlGenerator,
IL10N $l10n,
?string $userId) {
$this->urlGenerator = $urlGenerator;
$this->boardService = $boardService;
$this->userId = $userId;
$this->l10n = $l10n;
}
/**
* @inheritDoc
*/
public function matchReference(string $referenceText): bool {
$start = $this->urlGenerator->getAbsoluteURL('/apps/' . Application::APP_ID);
$startIndex = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . Application::APP_ID);
// link example: https://nextcloud.local/index.php/apps/deck/#/board/2
$noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/#\/board\/[0-9]+$/', $referenceText) === 1;
$indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/board\/[0-9]+$/', $referenceText) === 1;
return $noIndexMatch || $indexMatch;
}
/**
* @inheritDoc
*/
public function resolveReference(string $referenceText): ?IReference {
if ($this->matchReference($referenceText)) {
$boardId = $this->getBoardId($referenceText);
if ($boardId !== null) {
$board = $this->boardService->find($boardId)->jsonSerialize();
$board = $this->sanitizeSerializedBoard($board);
/** @var IReference $reference */
$reference = new Reference($referenceText);
$reference->setTitle($this->l10n->t('Deck board') . ': ' . $board['title']);
$ownerDisplayName = $board['owner']['displayname'] ?? $board['owner']['uid'] ?? '???';
$reference->setDescription($this->l10n->t('Owned by %1$s', [$ownerDisplayName]));
$imageUrl = $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath(Application::APP_ID, 'deck-dark.svg')
);
$reference->setImageUrl($imageUrl);
$reference->setRichObject(Application::APP_ID . '-board', [
'id' => $boardId,
'board' => $board,
]);
return $reference;
}
}
return null;
}
private function sanitizeSerializedBoard(array $board): array {
unset($board['labels']);
$board['owner'] = $board['owner']->jsonSerialize();
unset($board['acl']);
unset($board['users']);
return $board;
}
private function getBoardId(string $url): ?int {
$start = $this->urlGenerator->getAbsoluteURL('/apps/' . Application::APP_ID);
$startIndex = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . Application::APP_ID);
preg_match('/^' . preg_quote($start, '/') . '\/#\/board\/([0-9]+)$/', $url, $matches);
if (!$matches) {
preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/board\/([0-9]+)$/', $url, $matches);
}
if ($matches && count($matches) > 1) {
return (int) $matches[1];
}
return null;
}
public function getCachePrefix(string $referenceId): string {
$boardId = $this->getBoardId($referenceId);
if ($boardId !== null) {
return (string) $boardId;
}
return $referenceId;
}
public function getCacheKey(string $referenceId): ?string {
return $this->userId ?? '';
}
}

View File

@@ -30,28 +30,73 @@ use OCA\Deck\Model\CardDetails;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\CardService;
use OCA\Deck\Service\StackService;
use OCP\Collaboration\Reference\ADiscoverableReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\Collaboration\Reference\ISearchableReferenceProvider;
use OCP\Collaboration\Reference\Reference;
use OCP\IL10N;
use OCP\IURLGenerator;
class CardReferenceProvider implements IReferenceProvider {
class CardReferenceProvider extends ADiscoverableReferenceProvider implements ISearchableReferenceProvider {
private CardService $cardService;
private IURLGenerator $urlGenerator;
private BoardService $boardService;
private StackService $stackService;
private ?string $userId;
private IL10N $l10n;
public function __construct(CardService $cardService,
BoardService $boardService,
StackService $stackService,
IURLGenerator $urlGenerator,
IL10N $l10n,
?string $userId) {
$this->cardService = $cardService;
$this->urlGenerator = $urlGenerator;
$this->boardService = $boardService;
$this->stackService = $stackService;
$this->userId = $userId;
$this->l10n = $l10n;
}
/**
* @inheritDoc
*/
public function getId(): string {
return Application::APP_ID . '-ref-cards';
}
/**
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Deck boards, cards and comments');
}
/**
* @inheritDoc
*/
public function getOrder(): int {
return 10;
}
/**
* @inheritDoc
*/
public function getIconUrl(): string {
return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath(Application::APP_ID, 'deck-dark.svg')
);
}
/**
* @inheritDoc
*/
public function getSupportedSearchProviderIds(): array {
return [
'search-deck-card-board',
'search-deck-comment',
];
}
/**

View File

@@ -0,0 +1,191 @@
<?php
/**
* @copyright Copyright (c) 2022 Julien Veyssier <eneiluj@posteo.net>
*
* @author Julien Veyssier <eneiluj@posteo.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCA\Deck\Reference;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\Db\Assignment;
use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\Label;
use OCA\Deck\Model\CardDetails;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\CardService;
use OCA\Deck\Service\CommentService;
use OCA\Deck\Service\StackService;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\Collaboration\Reference\Reference;
use OCP\IL10N;
use OCP\IURLGenerator;
class CommentReferenceProvider implements IReferenceProvider {
private CardService $cardService;
private IURLGenerator $urlGenerator;
private BoardService $boardService;
private StackService $stackService;
private ?string $userId;
private IL10N $l10n;
private CommentService $commentService;
public function __construct(CardService $cardService,
BoardService $boardService,
StackService $stackService,
CommentService $commentService,
IURLGenerator $urlGenerator,
IL10N $l10n,
?string $userId) {
$this->cardService = $cardService;
$this->urlGenerator = $urlGenerator;
$this->boardService = $boardService;
$this->stackService = $stackService;
$this->userId = $userId;
$this->l10n = $l10n;
$this->commentService = $commentService;
}
/**
* @inheritDoc
*/
public function matchReference(string $referenceText): bool {
$start = $this->urlGenerator->getAbsoluteURL('/apps/' . Application::APP_ID);
$startIndex = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . Application::APP_ID);
// link example: https://nextcloud.local/index.php/apps/deck/#/board/2/card/11/comments/501
$noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+\/comments\/\d+$/', $referenceText) === 1;
$indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+\/comments\/\d+$/', $referenceText) === 1;
return $noIndexMatch || $indexMatch;
}
/**
* @inheritDoc
*/
public function resolveReference(string $referenceText): ?IReference {
if ($this->matchReference($referenceText)) {
$ids = $this->getIds($referenceText);
if ($ids !== null) {
[$boardId, $cardId, $commentId] = $ids;
$card = $this->cardService->find($cardId)->jsonSerialize();
$board = $this->boardService->find($boardId)->jsonSerialize();
$stack = $this->stackService->find((int) $card['stackId'])->jsonSerialize();
$card = $this->sanitizeSerializedCard($card);
$board = $this->sanitizeSerializedBoard($board);
$stack = $this->sanitizeSerializedStack($stack);
$comment = $this->commentService->getFormatted($cardId, $commentId);
/** @var IReference $reference */
$reference = new Reference($referenceText);
$reference->setTitle($comment['message']);
$boardOwnerDisplayName = $board['owner']['displayname'] ?? $board['owner']['uid'] ?? '???';
$reference->setDescription(
$this->l10n->t('From %1$s, in %2$s/%3$s, owned by %4$s', [
$comment['actorDisplayName'],
$board['title'],
$stack['title'],
$boardOwnerDisplayName
])
);
$imageUrl = $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath('core', 'actions/comment.svg')
);
$reference->setImageUrl($imageUrl);
$reference->setRichObject(Application::APP_ID . '-comment', [
'id' => $ids,
'board' => $board,
'card' => $card,
'stack' => $stack,
'comment' => $comment,
]);
return $reference;
}
}
return null;
}
private function sanitizeSerializedStack(array $stack): array {
$stack['cards'] = array_map(function (CardDetails $cardDetails) {
$result = $cardDetails->jsonSerialize();
unset($result['assignedUsers']);
return $result;
}, $stack['cards']);
return $stack;
}
private function sanitizeSerializedBoard(array $board): array {
unset($board['labels']);
$board['owner'] = $board['owner']->jsonSerialize();
unset($board['acl']);
unset($board['users']);
return $board;
}
private function sanitizeSerializedCard(array $card): array {
$card['labels'] = array_map(function (Label $label) {
return $label->jsonSerialize();
}, $card['labels']);
$card['assignedUsers'] = array_map(function (Assignment $assignment) {
$result = $assignment->jsonSerialize();
$result['participant'] = $result['participant']->jsonSerialize();
return $result;
}, $card['assignedUsers']);
$card['owner'] = $card['owner']->jsonSerialize();
unset($card['relatedStack']);
unset($card['relatedBoard']);
$card['attachments'] = array_map(function (Attachment $attachment) {
return $attachment->jsonSerialize();
}, $card['attachments']);
return $card;
}
private function getIds(string $url): ?array {
$start = $this->urlGenerator->getAbsoluteURL('/apps/' . Application::APP_ID);
$startIndex = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . Application::APP_ID);
preg_match('/^' . preg_quote($start, '/') . '\/#\/board\/([0-9]+)\/card\/([0-9]+)\/comments\/(\d+)$/', $url, $matches);
if (!$matches) {
preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/board\/([0-9]+)\/card\/([0-9]+)\/comments\/(\d+)$/', $url, $matches);
}
if ($matches && count($matches) > 3) {
return [
(int) $matches[1],
(int) $matches[2],
(int) $matches[3],
];
}
return null;
}
public function getCachePrefix(string $referenceId): string {
return $referenceId;
}
public function getCacheKey(string $referenceId): ?string {
return $this->userId ?? '';
}
}

View File

@@ -26,13 +26,16 @@ declare(strict_types=1);
namespace OCA\Deck\Search;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\Db\Board;
use OCP\Search\SearchResultEntry;
class BoardSearchResultEntry extends SearchResultEntry {
public function __construct(Board $board, $urlGenerator) {
parent::__construct(
'',
$urlGenerator->getAbsoluteURL(
$urlGenerator->imagePath(Application::APP_ID, 'deck-dark.svg')
),
$board->getTitle(),
'',
$urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId(),

View File

@@ -49,7 +49,7 @@ class CardCommentProvider implements IProvider {
}
public function getId(): string {
return 'deck-comment';
return 'search-deck-comment';
}
public function getName(): string {
@@ -65,7 +65,7 @@ class CardCommentProvider implements IProvider {
$results
);
}
return SearchResult::paginated(
$this->l10n->t('Card comments'),
$results,

View File

@@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCA\Deck\Search;
use OCA\Deck\AppInfo\Application;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\Stack;
@@ -33,6 +34,14 @@ use OCP\Search\SearchResultEntry;
class CardSearchResultEntry extends SearchResultEntry {
public function __construct(Board $board, Stack $stack, Card $card, $urlGenerator) {
parent::__construct('', $card->getTitle(), $board->getTitle() . ' » ' . $stack->getTitle(), $urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId() . '/card/' . $card->getId(), 'icon-deck');
parent::__construct(
$urlGenerator->getAbsoluteURL(
$urlGenerator->imagePath(Application::APP_ID, 'card.svg')
),
$card->getTitle(),
$board->getTitle() . ' » ' . $stack->getTitle(),
$urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId() . '/card/' . $card->getId(),
'icon-deck'
);
}
}

View File

@@ -36,7 +36,9 @@ class CommentSearchResultEntry extends SearchResultEntry {
public function __construct(string $commentId, string $commentMessage, string $commentAuthor, Card $card, IURLGenerator $urlGenerator, IL10N $l10n) {
parent::__construct(
'',
$urlGenerator->getAbsoluteURL(
$urlGenerator->imagePath('core', 'actions/comment.svg')
),
// TRANSLATORS This is describing the author and card title related to a comment e.g. "Jane on MyTask"
$l10n->t('%s on %s', [$commentAuthor, $card->getTitle()]),
$commentMessage,

View File

@@ -29,6 +29,7 @@ namespace OCA\Deck\Search;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\Card;
use OCA\Deck\Service\SearchService;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Search\IProvider;
@@ -36,30 +37,26 @@ use OCP\Search\ISearchQuery;
use OCP\Search\SearchResult;
class DeckProvider implements IProvider {
/**
* @var SearchService
*/
private $searchService;
/**
* @var IURLGenerator
*/
private $urlGenerator;
private IL10N $l10n;
private SearchService $searchService;
private IURLGenerator $urlGenerator;
public function __construct(
SearchService $searchService,
IURLGenerator $urlGenerator
IURLGenerator $urlGenerator,
IL10N $l10n
) {
$this->l10n = $l10n;
$this->searchService = $searchService;
$this->urlGenerator = $urlGenerator;
}
public function getId(): string {
return 'deck';
return 'search-deck-card-board';
}
public function getName(): string {
return 'Deck';
return $this->l10n->t('Deck boards and cards');
}
public function search(IUser $user, ISearchQuery $query): SearchResult {
@@ -99,14 +96,14 @@ class DeckProvider implements IProvider {
// if both cards and boards results are less then the limit, we know we won't get more
if (count($resultEntries) < $query->getLimit()) {
return SearchResult::complete(
'Deck',
$this->getName(),
$resultEntries
);
}
$newCursor = $this->getNewCursor($boardObjects, $cardObjects);
return SearchResult::paginated(
'Deck',
$this->getName(),
$resultEntries,
$newCursor
);

View File

@@ -76,6 +76,42 @@ class CommentService {
return new DataResponse($result);
}
/**
* @param int $cardId
* @param int $commentId
* @return IComment
* @throws NoPermissionException
* @throws NotFoundException
*/
private function get(int $cardId, int $commentId): IComment {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
try {
$comment = $this->commentsManager->get((string) $commentId);
if ($comment->getObjectType() !== Application::COMMENT_ENTITY_TYPE || (int) $comment->getObjectId() !== $cardId) {
throw new CommentNotFoundException();
}
} catch (CommentNotFoundException $e) {
throw new NotFoundException('No comment found.');
}
if ($comment->getParentId() !== '0') {
$this->permissionService->checkPermission($this->cardMapper, $comment->getParentId(), Acl::PERMISSION_READ);
}
return $comment;
}
/**
* @param int $cardId
* @param int $commentId
* @return array
* @throws NoPermissionException
* @throws NotFoundException
*/
public function getFormatted(int $cardId, int $commentId): array {
$comment = $this->get($cardId, $commentId);
return $this->formatComment($comment);
}
/**
* @param string $cardId
* @param string $message
@@ -126,21 +162,10 @@ class CommentService {
if (!is_numeric($commentId)) {
throw new BadRequestException('A valid comment id must be provided');
}
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
try {
$comment = $this->commentsManager->get($commentId);
if ($comment->getObjectType() !== Application::COMMENT_ENTITY_TYPE || $comment->getObjectId() !== $cardId) {
throw new CommentNotFoundException();
}
} catch (CommentNotFoundException $e) {
throw new NotFoundException('No comment found.');
}
$comment = $this->get((int) $cardId, (int) $commentId);
if ($comment->getActorType() !== 'users' || $comment->getActorId() !== $this->userId) {
throw new NoPermissionException('Only authors are allowed to edit their comment.');
}
if ($comment->getParentId() !== '0') {
$this->permissionService->checkPermission($this->cardMapper, $comment->getParentId(), Acl::PERMISSION_READ);
}
$comment->setMessage($message);
$this->commentsManager->save($comment);

View File

@@ -23,6 +23,8 @@ import { registerWidget } from '@nextcloud/vue-richtext'
import { Tooltip } from '@nextcloud/vue'
import Vue from 'vue'
import CardReferenceWidget from './views/CardReferenceWidget.vue'
import BoardReferenceWidget from './views/BoardReferenceWidget.vue'
import CommentReferenceWidget from './views/CommentReferenceWidget.vue'
import { translate, translatePlural } from '@nextcloud/l10n'
@@ -48,3 +50,33 @@ registerWidget('deck-card', (el, { richObjectType, richObject, accessible }) =>
},
}).$mount(el)
})
registerWidget('deck-board', (el, { richObjectType, richObject, accessible }) => {
el.parentNode.style['max-width'] = '400px'
el.parentNode.style['margin-left'] = '0'
el.parentNode.style['margin-right'] = '0'
const Widget = Vue.extend(BoardReferenceWidget)
new Widget({
propsData: {
richObjectType,
richObject,
accessible,
},
}).$mount(el)
})
registerWidget('deck-comment', (el, { richObjectType, richObject, accessible }) => {
el.parentNode.style['max-width'] = '400px'
el.parentNode.style['margin-left'] = '0'
el.parentNode.style['margin-right'] = '0'
const Widget = Vue.extend(CommentReferenceWidget)
new Widget({
propsData: {
richObjectType,
richObject,
accessible,
},
}).$mount(el)
})

View File

@@ -0,0 +1,128 @@
<!--
- @copyright Copyright (c) 2023 Julien Veyssier <julien-nc@posteo.net>
-
- @author 2023 Julien Veyssier <julien-nc@posteo.net>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<div class="deck-board-reference">
<div class="line">
<DeckIcon :size="20" class="title-icon" />
<strong>
<a :href="boardLink"
:title="boardTooltip"
target="_blank"
class="link">
{{ board.title }}
</a>
</strong>
</div>
<div class="line">
{{ t('deck', 'Owner') + ': ' }}
<NcUserBubble :user="boardOwnerUserId"
:display-name="boardOwnerDisplayName" />
</div>
</div>
</template>
<script>
import DeckIcon from '../components/icons/DeckIcon.vue'
import NcUserBubble from '@nextcloud/vue/dist/Components/NcUserBubble.js'
import moment from '@nextcloud/moment'
import { generateUrl } from '@nextcloud/router'
export default {
name: 'BoardReferenceWidget',
components: {
DeckIcon,
NcUserBubble,
},
props: {
richObjectType: {
type: String,
default: '',
},
richObject: {
type: Object,
default: null,
},
accessible: {
type: Boolean,
default: true,
},
},
computed: {
board() {
return this.richObject.board
},
boardLink() {
return generateUrl('/apps/deck/#/board/{boardId}', { boardId: this.board.id })
},
boardTooltip() {
return t('deck', 'Deck board {name}\n* Last modified on {lastMod}', {
name: this.board.title,
lastMod: moment.unix(this.board.lastModified).format('LLL'),
})
},
boardOwnerUserId() {
return this.board.owner?.uid ?? '???'
},
boardOwnerDisplayName() {
return this.board.owner?.displayname ?? this.boardOwnerUserId
},
},
methods: {
},
}
</script>
<style scoped lang="scss">
.deck-board-reference {
width: 100%;
// needed for the specific case of Text
.editor__content & {
width: calc(100% - 24px);
}
white-space: normal;
padding: 12px;
.link {
text-decoration: underline;
color: var(--color-main-text) !important;
padding: 0 !important;
}
.line {
display: flex;
align-items: center;
.icon {
margin-right: 4px;
}
.title-icon {
margin-right: 8px;
}
}
}
</style>

View File

@@ -1,7 +1,7 @@
<!--
- @copyright Copyright (c) 2022 2022 Julien Veyssier <eneiluj@posteo.net>
- @copyright Copyright (c) 2022 Julien Veyssier <julien-nc@posteo.net>
-
- @author 2022 Julien Veyssier <eneiluj@posteo.net>
- @author 2022 Julien Veyssier <julien-nc@posteo.net>
-
- @license GNU AGPL version 3 or any later version
-
@@ -22,7 +22,7 @@
<template>
<div class="deck-card-reference">
<div class="line">
<DeckIcon :size="20" class="title-icon" />
<CardBulletedOutlineIcon :size="20" class="title-icon" />
<strong>
<a :href="cardLink"
:title="cardTooltip"
@@ -41,6 +41,7 @@
</span>
</div>
<div class="line">
<DeckIcon :size="20" class="title-icon" />
<a v-tooltip.top="{ content: stackTooltip }"
:href="boardLink"
target="_blank"
@@ -83,6 +84,7 @@
<script>
import CalendarBlankIcon from 'vue-material-design-icons/CalendarBlank.vue'
import TextIcon from 'vue-material-design-icons/Text.vue'
import CardBulletedOutlineIcon from 'vue-material-design-icons/CardBulletedOutline.vue'
import DeckIcon from '../components/icons/DeckIcon.vue'
import AvatarList from '../components/cards/AvatarList.vue'
@@ -99,6 +101,7 @@ export default {
AvatarList,
DeckIcon,
CalendarBlankIcon,
CardBulletedOutlineIcon,
TextIcon,
RichText,
},

View File

@@ -0,0 +1,276 @@
<!--
- @copyright Copyright (c) 2023 Julien Veyssier <julien-nc@posteo.net>
-
- @author 2023 Julien Veyssier <julien-nc@posteo.net>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<div class="deck-comment-reference">
<div class="line">
<CardBulletedOutlineIcon :size="20" class="title-icon" />
<strong>
<a :href="cardLink"
:title="cardTooltip"
target="_blank"
class="link">
{{ card.title }}
</a>
</strong>
<div v-if="dueDate" class="spacer" />
<span v-if="dueDate"
v-tooltip.top="{ content: formattedDueDate }"
class="due-date">
<CalendarBlankIcon :size="20"
class="icon" />
{{ dueDate }}
</span>
</div>
<div class="line">
<DeckIcon :size="20" class="title-icon" />
<a v-tooltip.top="{ content: stackTooltip }"
:href="boardLink"
target="_blank"
class="link">
{{ t('deck', '{stack} in {board}', { stack: stack.title, board: board.title }) }}
</a>
</div>
<div>
<transition-group v-if="card.labels && card.labels.length"
name="zoom"
tag="ul"
class="labels"
@click.stop="openCard">
<li v-for="label in labelsSorted" :key="label.id" :style="labelStyle(label)">
<span>{{ label.title }}</span>
</li>
</transition-group>
</div>
<div class="line description-assignees">
<TextIcon v-if="card.description" :size="20" class="icon" />
<div v-if="card.description"
:class="{
'description': true,
'short-description': shortDescription,
}">
<RichText v-tooltip.top="{ content: shortDescription ? t('deck', 'Click to expand description') : undefined }"
:text="card.description"
:use-markdown="true"
@click.native="shortDescription = !shortDescription" />
</div>
<div v-if="card.assignedUsers .length > 0"
class="spacer" />
<AvatarList v-if="card.assignedUsers .length > 0"
:users="card.assignedUsers"
class="card-assignees" />
</div>
<div v-if="comment" class="line comment-wrapper">
<CommentProcessingOutlineIcon :size="20" class="icon" />
<div :class="{
'comment': true,
'short-comment': shortComment,
}">
<RichText v-tooltip.top="{ content: shortComment ? t('deck', 'Click to expand comment') : undefined }"
:text="commentMessageText"
:use-markdown="false"
@click.native="shortComment = !shortComment" />
</div>
</div>
</div>
</template>
<script>
import CalendarBlankIcon from 'vue-material-design-icons/CalendarBlank.vue'
import TextIcon from 'vue-material-design-icons/Text.vue'
import CardBulletedOutlineIcon from 'vue-material-design-icons/CardBulletedOutline.vue'
import CommentProcessingOutlineIcon from 'vue-material-design-icons/CommentProcessingOutline.vue'
import DeckIcon from '../components/icons/DeckIcon.vue'
import AvatarList from '../components/cards/AvatarList.vue'
import labelStyle from '../mixins/labelStyle.js'
import { RichText } from '@nextcloud/vue-richtext'
import moment from '@nextcloud/moment'
import { generateUrl } from '@nextcloud/router'
export default {
name: 'CommentReferenceWidget',
components: {
AvatarList,
DeckIcon,
CalendarBlankIcon,
TextIcon,
CardBulletedOutlineIcon,
RichText,
CommentProcessingOutlineIcon,
},
mixins: [labelStyle],
props: {
richObjectType: {
type: String,
default: '',
},
richObject: {
type: Object,
default: null,
},
accessible: {
type: Boolean,
default: true,
},
},
data() {
return {
shortDescription: true,
shortComment: true,
}
},
computed: {
card() {
return this.richObject.card
},
board() {
return this.richObject.board
},
stack() {
return this.richObject.stack
},
comment() {
return this.richObject.comment
},
commentMessageText() {
const e = document.createElement('div')
e.innerHTML = this.comment.message
return e.textContent
},
cardLink() {
return generateUrl('/apps/deck/#/board/{boardId}/card/{cardId}', { boardId: this.board.id, cardId: this.card.id })
},
boardLink() {
return generateUrl('/apps/deck/#/board/{boardId}', { boardId: this.board.id })
},
cardTooltip() {
return t('deck', '* Created on {created}\n* Last modified on {lastMod}\n* {nbAttachments} attachments\n* {nbComments} comments', {
created: moment.unix(this.card.createdAt).format('LLL'),
lastMod: moment.unix(this.card.lastModified).format('LLL'),
nbAttachments: this.card.attachments.length,
nbComments: this.card.commentsCount,
})
},
stackTooltip() {
return t('deck', '{nbCards} cards', { nbCards: this.stack.cards.length })
},
dueDate() {
return this.card.duedate
? moment(this.card.duedate).fromNow()
: null
},
formattedDueDate() {
return this.card.duedate
? t('deck', 'Due on {date}', { date: moment(this.card.duedate).format('LLL') })
: null
},
labelsSorted() {
return [...this.card.labels].sort((a, b) => (a.title < b.title) ? -1 : 1)
},
},
methods: {
},
}
</script>
<style scoped lang="scss">
/* stylelint-disable-next-line no-invalid-position-at-import-rule */
@import '../css/labels';
.deck-comment-reference {
width: 100%;
// needed for the specific case of Text
.editor__content & {
width: calc(100% - 24px);
}
white-space: normal;
padding: 12px;
.link {
text-decoration: underline;
color: var(--color-main-text) !important;
padding: 0 !important;
}
.line {
display: flex;
align-items: center;
.icon {
margin-right: 4px;
}
.title-icon {
margin-right: 8px;
}
}
.due-date {
display: flex;
align-items: center;
}
.labels {
margin: 8px 0;
}
.comment-wrapper,
.description-assignees {
width: 100%;
display: flex;
align-items: start;
.icon {
align-self: start;
margin-top: 8px;
}
.comment,
.description {
margin-right: 8px;
padding-top: 6px;
max-height: 250px;
overflow: scroll;
&.short-comment,
&.short-description {
max-height: 25px;
overflow: hidden;
}
}
.card-assignees {
margin-top: 0;
height: 36px;
flex-grow: unset;
}
}
.spacer {
flex-grow: 1;
}
}
</style>

View File

@@ -21,7 +21,7 @@ class SearchContext implements Context {
$this->boardContext = $environment->getContext('BoardContext');
}
/**
* @When /^searching for "([^"]*)"$/
* @param string $term
@@ -39,7 +39,7 @@ class SearchContext implements Context {
* https://cloud.nextcloud.com/ocs/v2.php/search/providers/talk-conversations/search?term=an&from=%2Fapps%2Fdashboard%2F
*/
public function searchingForComments(string $term) {
$this->requestContext->sendOCSRequest('GET', '/search/providers/deck-comment/search?term=' . urlencode($term), []);
$this->requestContext->sendOCSRequest('GET', '/search/providers/search-deck-comment/search?term=' . urlencode($term), []);
$this->requestContext->getResponse()->getBody()->seek(0);
$data = (string)$this->getResponse()->getBody();
$this->unifiedSearchResult = json_decode($data, true);

View File

@@ -12,7 +12,7 @@ webpackConfig.entry = {
dashboard: path.join(__dirname, 'src', 'init-dashboard.js'),
calendar: path.join(__dirname, 'src', 'init-calendar.js'),
talk: path.join(__dirname, 'src', 'init-talk.js'),
'card-reference': path.join(__dirname, 'src', 'init-card-reference.js'),
reference: path.join(__dirname, 'src', 'init-reference.js'),
}
webpackConfig.stats = {