diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 477f96f51..01257a875 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -54,11 +54,13 @@ use OCA\Deck\Reference\BoardReferenceProvider; use OCA\Deck\Reference\CardReferenceProvider; use OCA\Deck\Reference\CommentReferenceProvider; +use OCA\Deck\Reference\CreateCardReferenceProvider; use OCA\Deck\Search\CardCommentProvider; use OCA\Deck\Search\DeckProvider; use OCA\Deck\Service\PermissionService; use OCA\Deck\Sharing\DeckShareProvider; use OCA\Deck\Sharing\Listener; +use OCA\Text\Event\LoadEditor; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -83,6 +85,8 @@ class Application extends App implements IBootstrap { public const COMMENT_ENTITY_TYPE = 'deckCard'; + private $referenceLoaded = false; + public function __construct(array $urlParams = []) { parent::__construct(self::APP_ID, $urlParams); @@ -90,8 +94,12 @@ public function __construct(array $urlParams = []) { // (and use a listener class) $container = $this->getContainer(); $eventDispatcher = $container->get(IEventDispatcher::class); - $eventDispatcher->addListener(RenderReferenceEvent::class, function () { + $eventDispatcher->addListener(RenderReferenceEvent::class, function (RenderReferenceEvent $e) use ($eventDispatcher) { Util::addScript(self::APP_ID, self::APP_ID . '-reference'); + if (!$this->referenceLoaded && class_exists(LoadEditor::class)) { + $this->referenceLoaded = true; + $eventDispatcher->dispatchTyped(new LoadEditor()); + } }); } @@ -129,6 +137,8 @@ public function register(IRegistrationContext $context): void { $context->registerSearchProvider(CardCommentProvider::class); $context->registerDashboardWidget(DeckWidget::class); + $context->registerReferenceProvider(CreateCardReferenceProvider::class); + // reference widget $context->registerReferenceProvider(CardReferenceProvider::class); $context->registerReferenceProvider(BoardReferenceProvider::class); diff --git a/lib/Controller/CardApiController.php b/lib/Controller/CardApiController.php index 1c9e87a18..443ad3719 100644 --- a/lib/Controller/CardApiController.php +++ b/lib/Controller/CardApiController.php @@ -81,8 +81,17 @@ public function get() { * * Get a specific card. */ - public function create($title, $type = 'plain', $order = 999, $description = '', $duedate = null) { + public function create($title, $type = 'plain', $order = 999, $description = '', $duedate = null, $labels = [], $users = []) { $card = $this->cardService->create($title, $this->request->getParam('stackId'), $type, $order, $this->userId, $description, $duedate); + + foreach ($labels as $labelId) { + $this->cardService->assignLabel($card->id, $labelId); + } + + foreach ($users as $user) { + $this->assignmentService->assignUser($card->id, $user['id'], $user['type']); + } + return new DataResponse($card, HTTP::STATUS_OK); } diff --git a/lib/Controller/CardController.php b/lib/Controller/CardController.php index b6f6e6958..d86ac5f93 100644 --- a/lib/Controller/CardController.php +++ b/lib/Controller/CardController.php @@ -78,8 +78,18 @@ public function rename($cardId, $title) { * @param int $order * @return \OCP\AppFramework\Db\Entity */ - public function create($title, $stackId, $type = 'plain', $order = 999, string $description = '') { - return $this->cardService->create($title, $stackId, $type, $order, $this->userId, $description); + public function create($title, $stackId, $type = 'plain', $order = 999, string $description = '', $duedate = null, $labels = [], $users = []) { + $card = $this->cardService->create($title, $stackId, $type, $order, $this->userId, $description, $duedate); + + foreach ($labels as $label) { + $this->assignLabel($card->id, $label); + } + + foreach ($users as $user) { + $this->assignmentService->assignUser($card->id, $user['id'], $user['type']); + } + + return $card; } /** diff --git a/lib/Reference/CardReferenceProvider.php b/lib/Reference/CardReferenceProvider.php index 45e0c0d8c..f00b4f856 100644 --- a/lib/Reference/CardReferenceProvider.php +++ b/lib/Reference/CardReferenceProvider.php @@ -111,6 +111,10 @@ public function matchReference(string $referenceText): bool { $noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+$/', $referenceText) === 1; $indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+$/', $referenceText) === 1; + // link example: https://nextcloud.local/index.php/apps/deck/card/11 + $noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/card\/[0-9]+$/', $referenceText) === 1; + $indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/card\/[0-9]+$/', $referenceText) === 1; + return $noIndexMatch || $indexMatch; } @@ -124,8 +128,8 @@ public function resolveReference(string $referenceText): ?IReference { [$boardId, $cardId] = $ids; try { $card = $this->cardService->find((int) $cardId)->jsonSerialize(); - $board = $this->boardService->find((int) $boardId)->jsonSerialize(); $stack = $this->stackService->find((int) $card['stackId'])->jsonSerialize(); + $board = $this->boardService->find((int)($boardId ?? $stack['boardId']))->jsonSerialize(); } catch (NoPermissionException $e) { // Skip throwing if user has no permissions return null; @@ -202,6 +206,16 @@ private function getBoardCardId(string $url): ?array { return [$matches2[1], $matches2[2]]; } + preg_match('/^' . preg_quote($start, '/') . '\/card\/([0-9]+)$/', $url, $matches); + if ($matches && count($matches) > 1) { + return [null, $matches[1]]; + } + + preg_match('/^' . preg_quote($startIndex, '/') . '\/card\/([0-9]+)$/', $url, $matches2); + if ($matches2 && count($matches2) > 1) { + return [null, $matches2[1]]; + } + return null; } diff --git a/lib/Reference/CreateCardReferenceProvider.php b/lib/Reference/CreateCardReferenceProvider.php new file mode 100644 index 000000000..8e0eaf2c1 --- /dev/null +++ b/lib/Reference/CreateCardReferenceProvider.php @@ -0,0 +1,77 @@ +l10n->t('Create a new deck card'); + } + + /** + * @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 matchReference(string $referenceText): bool { + return false; + } + + /** + * @inheritDoc + */ + public function resolveReference(string $referenceText): ?IReference { + return null; + } + + /** + * @inheritDoc + */ + public function getCachePrefix(string $referenceId): string { + return $this->userId ?? ''; + } + + /** + * We don't use the userId here but rather a reference unique id + * @inheritDoc + */ + public function getCacheKey(string $referenceId): ?string { + return $referenceId; + } +} diff --git a/src/CardCreateDialog.vue b/src/CardCreateDialog.vue index 604640a6f..e3241f6c6 100644 --- a/src/CardCreateDialog.vue +++ b/src/CardCreateDialog.vue @@ -22,101 +22,23 @@