From cf827daa8114046041b8115f987e8f4dc7ebe095 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Tue, 5 Nov 2024 09:47:15 +0100 Subject: [PATCH 1/4] feat(contacts-menu): implement custom javascript hook action Signed-off-by: Richard Steinmetz --- core/src/components/ContactsMenu/Contact.vue | 28 +++++++- .../Contacts/ContactsMenu/ActionFactory.php | 19 +++++ .../ContactsMenu/Actions/JavascriptAction.php | 71 +++++++++++++++++++ .../ContactsMenu/Actions/LinkAction.php | 3 + .../Contacts/ContactsMenu/IActionFactory.php | 18 +++++ 5 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php diff --git a/core/src/components/ContactsMenu/Contact.vue b/core/src/components/ContactsMenu/Contact.vue index d7de04efe172a..40fcb82cdebd5 100644 --- a/core/src/components/ContactsMenu/Contact.vue +++ b/core/src/components/ContactsMenu/Contact.vue @@ -22,8 +22,8 @@ @@ -45,14 +57,20 @@ diff --git a/lib/private/Contacts/ContactsMenu/ActionFactory.php b/lib/private/Contacts/ContactsMenu/ActionFactory.php index 71ebe575fdd80..f8ecccb288a8b 100644 --- a/lib/private/Contacts/ContactsMenu/ActionFactory.php +++ b/lib/private/Contacts/ContactsMenu/ActionFactory.php @@ -5,7 +5,9 @@ */ namespace OC\Contacts\ContactsMenu; +use OC\Contacts\ContactsMenu\Actions\JavascriptAction; use OC\Contacts\ContactsMenu\Actions\LinkAction; +use OCP\Contacts\ContactsMenu\IAction; use OCP\Contacts\ContactsMenu\IActionFactory; use OCP\Contacts\ContactsMenu\ILinkAction; @@ -28,4 +30,21 @@ public function newLinkAction(string $icon, string $name, string $href, string $ public function newEMailAction(string $icon, string $name, string $email, string $appId = ''): ILinkAction { return $this->newLinkAction($icon, $name, 'mailto:' . $email, $appId); } + + /** + * {@inheritDoc} + */ + public function newJavascriptAction( + string $icon, + string $name, + string $hook, + string $appId = '', + ): IAction { + $action = new JavascriptAction(); + $action->setIcon($icon); + $action->setName($name); + $action->setHook($hook); + $action->setAppId($appId); + return $action; + } } diff --git a/lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php b/lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php new file mode 100644 index 0000000000000..73591e18612d3 --- /dev/null +++ b/lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php @@ -0,0 +1,71 @@ +icon = $icon; + } + + public function getName(): string { + return $this->name; + } + + public function setName(string $name) { + $this->name = $name; + } + + public function setPriority(int $priority) { + $this->priority = $priority; + } + + public function getPriority(): int { + return $this->priority; + } + + public function setAppId(string $appId) { + $this->appId = $appId; + } + + public function getAppId(): string { + return $this->appId; + } + + public function getHook(): string { + return $this->hook; + } + + public function setHook(string $hook): void { + $this->hook = $hook; + } + + function jsonSerialize() { + return [ + 'type' => self::TYPE, + 'title' => $this->name, + 'icon' => $this->icon, + 'appId' => $this->appId, + 'hook' => $this->hook, + ]; + } +} diff --git a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php index 0d4cc9b9b013c..5104a6c669c6f 100644 --- a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php +++ b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php @@ -8,6 +8,8 @@ use OCP\Contacts\ContactsMenu\ILinkAction; class LinkAction implements ILinkAction { + public const TYPE = 'LinkAction'; + private string $icon = ''; private string $name = ''; private string $href = ''; @@ -64,6 +66,7 @@ public function getAppId(): string { */ public function jsonSerialize(): array { return [ + 'type' => self::TYPE, 'title' => $this->name, 'icon' => $this->icon, 'hyperlink' => $this->href, diff --git a/lib/public/Contacts/ContactsMenu/IActionFactory.php b/lib/public/Contacts/ContactsMenu/IActionFactory.php index a4785d1c70c30..64da0f68ebe42 100644 --- a/lib/public/Contacts/ContactsMenu/IActionFactory.php +++ b/lib/public/Contacts/ContactsMenu/IActionFactory.php @@ -34,4 +34,22 @@ public function newLinkAction(string $icon, string $name, string $href, string $ * @return ILinkAction */ public function newEMailAction(string $icon, string $name, string $email, string $appId = ''): ILinkAction; + + /** + * Construct and return a new javascript hook action for the contacts menu + * + * @since 31.0.0 + * + * @param string $icon full path to the action's icon + * @param string $name localized name of the action + * @param string $hook id of the javascript hook as registered in the frontend + * @param string $appId the appName registering the action + * @return IAction + */ + public function newJavascriptAction( + string $icon, + string $name, + string $hook, + string $appId = '', + ): IAction; } From 202fa02475cf79880c3d45d6ee844345e36631c2 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Mon, 25 Nov 2024 17:56:07 +0100 Subject: [PATCH 2/4] fixup! feat(contacts-menu): implement custom javascript hook action --- core/src/components/ContactsMenu/Contact.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/components/ContactsMenu/Contact.vue b/core/src/components/ContactsMenu/Contact.vue index 40fcb82cdebd5..18c2d86a732a9 100644 --- a/core/src/components/ContactsMenu/Contact.vue +++ b/core/src/components/ContactsMenu/Contact.vue @@ -43,7 +43,7 @@ :key="`${idx}-hook`" :close-after-click="true" class="other-actions" - @click="callContactsMenuHook(action.hook)"> + @click="callContactsMenuHook(action.hook, contact)"> From b48320c892491da97130b3c8b8fd517532ec3c4e Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Tue, 26 Nov 2024 21:42:43 +0100 Subject: [PATCH 3/4] fixup! feat(contacts-menu): implement custom javascript hook action --- core/src/components/ContactsMenu/Contact.vue | 40 +++++------ .../Contacts/ContactsMenu/ActionFactory.php | 19 ----- .../ContactsMenu/Actions/JavascriptAction.php | 71 ------------------- .../ContactsMenu/Actions/LinkAction.php | 3 - .../Contacts/ContactsMenu/IActionFactory.php | 18 ----- 5 files changed, 18 insertions(+), 133 deletions(-) delete mode 100644 lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php diff --git a/core/src/components/ContactsMenu/Contact.vue b/core/src/components/ContactsMenu/Contact.vue index 18c2d86a732a9..4a2b284286065 100644 --- a/core/src/components/ContactsMenu/Contact.vue +++ b/core/src/components/ContactsMenu/Contact.vue @@ -22,7 +22,7 @@ {{ action.title }} - + {{ action.title }} - - - {{ action.title }} - + + + {{ action.displayName(contact) }} + @@ -60,10 +58,8 @@ import NcActionText from '@nextcloud/vue/dist/Components/NcActionText.js' import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js' import NcActions from '@nextcloud/vue/dist/Components/NcActions.js' import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js' -import { - callContactsMenuHook, - hasContactsMenuHook, -} from '@nextcloud/vue/dist/Functions/contactsMenu.js' +import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js' +import { getEnabledContactsMenuActions } from '@nextcloud/vue/dist/Functions/contactsMenu.js' export default { name: 'Contact', @@ -73,6 +69,7 @@ export default { NcActionButton, NcActions, NcAvatar, + NcIconSvgWrapper, }, props: { contact: { @@ -87,6 +84,9 @@ export default { } return this.contact.actions }, + jsActions() { + return getEnabledContactsMenuActions(this.contact) + }, preloadedUserStatus() { if (this.contact.status) { return { @@ -98,10 +98,6 @@ export default { return undefined }, }, - methods: { - hasContactsMenuHook, - callContactsMenuHook, - }, } diff --git a/lib/private/Contacts/ContactsMenu/ActionFactory.php b/lib/private/Contacts/ContactsMenu/ActionFactory.php index f8ecccb288a8b..71ebe575fdd80 100644 --- a/lib/private/Contacts/ContactsMenu/ActionFactory.php +++ b/lib/private/Contacts/ContactsMenu/ActionFactory.php @@ -5,9 +5,7 @@ */ namespace OC\Contacts\ContactsMenu; -use OC\Contacts\ContactsMenu\Actions\JavascriptAction; use OC\Contacts\ContactsMenu\Actions\LinkAction; -use OCP\Contacts\ContactsMenu\IAction; use OCP\Contacts\ContactsMenu\IActionFactory; use OCP\Contacts\ContactsMenu\ILinkAction; @@ -30,21 +28,4 @@ public function newLinkAction(string $icon, string $name, string $href, string $ public function newEMailAction(string $icon, string $name, string $email, string $appId = ''): ILinkAction { return $this->newLinkAction($icon, $name, 'mailto:' . $email, $appId); } - - /** - * {@inheritDoc} - */ - public function newJavascriptAction( - string $icon, - string $name, - string $hook, - string $appId = '', - ): IAction { - $action = new JavascriptAction(); - $action->setIcon($icon); - $action->setName($name); - $action->setHook($hook); - $action->setAppId($appId); - return $action; - } } diff --git a/lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php b/lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php deleted file mode 100644 index 73591e18612d3..0000000000000 --- a/lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php +++ /dev/null @@ -1,71 +0,0 @@ -icon = $icon; - } - - public function getName(): string { - return $this->name; - } - - public function setName(string $name) { - $this->name = $name; - } - - public function setPriority(int $priority) { - $this->priority = $priority; - } - - public function getPriority(): int { - return $this->priority; - } - - public function setAppId(string $appId) { - $this->appId = $appId; - } - - public function getAppId(): string { - return $this->appId; - } - - public function getHook(): string { - return $this->hook; - } - - public function setHook(string $hook): void { - $this->hook = $hook; - } - - function jsonSerialize() { - return [ - 'type' => self::TYPE, - 'title' => $this->name, - 'icon' => $this->icon, - 'appId' => $this->appId, - 'hook' => $this->hook, - ]; - } -} diff --git a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php index 5104a6c669c6f..0d4cc9b9b013c 100644 --- a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php +++ b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php @@ -8,8 +8,6 @@ use OCP\Contacts\ContactsMenu\ILinkAction; class LinkAction implements ILinkAction { - public const TYPE = 'LinkAction'; - private string $icon = ''; private string $name = ''; private string $href = ''; @@ -66,7 +64,6 @@ public function getAppId(): string { */ public function jsonSerialize(): array { return [ - 'type' => self::TYPE, 'title' => $this->name, 'icon' => $this->icon, 'hyperlink' => $this->href, diff --git a/lib/public/Contacts/ContactsMenu/IActionFactory.php b/lib/public/Contacts/ContactsMenu/IActionFactory.php index 64da0f68ebe42..a4785d1c70c30 100644 --- a/lib/public/Contacts/ContactsMenu/IActionFactory.php +++ b/lib/public/Contacts/ContactsMenu/IActionFactory.php @@ -34,22 +34,4 @@ public function newLinkAction(string $icon, string $name, string $href, string $ * @return ILinkAction */ public function newEMailAction(string $icon, string $name, string $email, string $appId = ''): ILinkAction; - - /** - * Construct and return a new javascript hook action for the contacts menu - * - * @since 31.0.0 - * - * @param string $icon full path to the action's icon - * @param string $name localized name of the action - * @param string $hook id of the javascript hook as registered in the frontend - * @param string $appId the appName registering the action - * @return IAction - */ - public function newJavascriptAction( - string $icon, - string $name, - string $hook, - string $appId = '', - ): IAction; } From 279f0b9ff525a9b0e9fbb0b2a791537ee6d43249 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Wed, 27 Nov 2024 13:39:34 +0100 Subject: [PATCH 4/4] fixup! feat(contacts-menu): implement custom javascript hook action --- core/src/components/ContactsMenu/Contact.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/components/ContactsMenu/Contact.vue b/core/src/components/ContactsMenu/Contact.vue index 4a2b284286065..ec74697341c78 100644 --- a/core/src/components/ContactsMenu/Contact.vue +++ b/core/src/components/ContactsMenu/Contact.vue @@ -44,7 +44,8 @@ class="other-actions" @click="action.callback(contact)"> {{ action.displayName(contact) }} @@ -116,6 +117,10 @@ export default { padding: 12px; filter: var(--background-invert-if-dark); } + + &__icon-svg { + padding: 5px; + } } &__avatar {