From e25da15d11e9bc58454f123174ef69ede9c147f8 Mon Sep 17 00:00:00 2001 From: greta Date: Wed, 23 Oct 2024 14:42:39 +0200 Subject: [PATCH] feat: create a readonly contactdetails Signed-off-by: greta --- lib/AppInfo/Application.php | 3 + lib/Event/LoadContactsOcaApiEvent.php | 15 ++ lib/Listener/LoadContactsOcaApi.php | 34 +++ src/oca.js | 26 +++ src/oca/mountContactDetails.js | 48 ++++ src/views/ReadOnlyContactDetails.vue | 305 ++++++++++++++++++++++++++ vite.config.js | 1 + 7 files changed, 432 insertions(+) create mode 100644 lib/Event/LoadContactsOcaApiEvent.php create mode 100644 lib/Listener/LoadContactsOcaApi.php create mode 100644 src/oca.js create mode 100644 src/oca/mountContactDetails.js create mode 100644 src/views/ReadOnlyContactDetails.vue diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 31f0f19a4..aebba7b70 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -6,7 +6,9 @@ namespace OCA\Contacts\AppInfo; use OCA\Contacts\Dav\PatchPlugin; +use OCA\Contacts\Event\LoadContactsOcaApiEvent; use OCA\Contacts\Listener\LoadContactsFilesActions; +use OCA\Contacts\Listener\LoadContactsOcaApi; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -28,6 +30,7 @@ public function __construct() { public function register(IRegistrationContext $context): void { $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadContactsFilesActions::class); + $context->registerEventListener(LoadContactsOcaApiEvent::class, LoadContactsOcaApi::class); } public function boot(IBootContext $context): void { diff --git a/lib/Event/LoadContactsOcaApiEvent.php b/lib/Event/LoadContactsOcaApiEvent.php new file mode 100644 index 000000000..4418c45c0 --- /dev/null +++ b/lib/Event/LoadContactsOcaApiEvent.php @@ -0,0 +1,15 @@ +initialState->provideInitialState('supportedNetworks', []); + Util::addScript(Application::APP_ID, 'contacts-oca'); + } +} diff --git a/src/oca.js b/src/oca.js new file mode 100644 index 000000000..6bc360184 --- /dev/null +++ b/src/oca.js @@ -0,0 +1,26 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +// eslint-disable-next-line import/no-unresolved, n/no-missing-import +import 'vite/modulepreload-polyfill' + +// Global scss sheets +import './css/contacts.scss' + +// Dialogs css +import '@nextcloud/dialogs/style.css' + +window.OCA ??= {} +window.OCA.Contacts = { + /** + * @param {HTMLElement} el Html element to mount the component at + * @param {string} contactEmailAddress Email address of the contact whose details to display + * @return {Promise} Mounted Vue instance (vm) + */ + async mountContactDetails(el, contactEmailAddress) { + const { mountContactDetails } = await import('./oca/mountContactDetails.js') + return mountContactDetails(el, contactEmailAddress) + }, +} diff --git a/src/oca/mountContactDetails.js b/src/oca/mountContactDetails.js new file mode 100644 index 000000000..091a9ab51 --- /dev/null +++ b/src/oca/mountContactDetails.js @@ -0,0 +1,48 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import Vue from 'vue' +import ReadOnlyContactDetails from '../views/ReadOnlyContactDetails.vue' +import { createPinia, PiniaVuePlugin } from 'pinia' + +/** GLOBAL COMPONENTS AND DIRECTIVE */ +import ClickOutside from 'vue-click-outside' +import { Tooltip as VTooltip } from '@nextcloud/vue' + +import store from '../store/index.js' +import logger from '../services/logger.js' + +/** + * @param {HTMLElement} el + * @param {string} contactEmailAddress + * @return {Promise} + */ +export async function mountContactDetails(el, contactEmailAddress) { + Vue.use(PiniaVuePlugin) + const pinia = createPinia() + + // Register global directives + Vue.directive('ClickOutside', ClickOutside) + Vue.directive('Tooltip', VTooltip) + + Vue.prototype.t = t + Vue.prototype.n = n + + Vue.prototype.appName = appName + Vue.prototype.appVersion = appVersion + Vue.prototype.logger = logger + Vue.prototype.OC = window.OC + Vue.prototype.OCA = window.OCA + + const Component = Vue.extend(ReadOnlyContactDetails) + const vueElement = new Component({ + pinia, + store, + propsData: { + contactEmailAddress, + }, + }).$mount(el) + return vueElement +} diff --git a/src/views/ReadOnlyContactDetails.vue b/src/views/ReadOnlyContactDetails.vue new file mode 100644 index 000000000..4f53ab7bb --- /dev/null +++ b/src/views/ReadOnlyContactDetails.vue @@ -0,0 +1,305 @@ + + + + + + + diff --git a/vite.config.js b/vite.config.js index 69a048f12..aa2e85bc0 100644 --- a/vite.config.js +++ b/vite.config.js @@ -10,6 +10,7 @@ export default createAppConfig({ 'main': path.join(__dirname, 'src', 'main.js'), 'files-action': path.join(__dirname, 'src', 'files-action.js'), 'admin-settings': path.join(__dirname, 'src', 'admin-settings.js'), + 'oca': path.join(__dirname, 'src', 'oca.js'), }, { inlineCSS: false, })