Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create a read-only contactdetails component #4194

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +30,7 @@

public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadContactsFilesActions::class);
$context->registerEventListener(LoadContactsOcaApiEvent::class, LoadContactsOcaApi::class);

Check warning on line 33 in lib/AppInfo/Application.php

View check run for this annotation

Codecov / codecov/patch

lib/AppInfo/Application.php#L33

Added line #L33 was not covered by tests
}

public function boot(IBootContext $context): void {
Expand Down
15 changes: 15 additions & 0 deletions lib/Event/LoadContactsOcaApiEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Contacts\Event;

use OCP\EventDispatcher\Event;

class LoadContactsOcaApiEvent extends Event {
}
34 changes: 34 additions & 0 deletions lib/Listener/LoadContactsOcaApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Contacts\Listener;

use OCA\Contacts\AppInfo\Application;
use OCA\Contacts\Event\LoadContactsOcaApiEvent;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

class LoadContactsOcaApi implements IEventListener {
public function __construct(

Check warning on line 20 in lib/Listener/LoadContactsOcaApi.php

View check run for this annotation

Codecov / codecov/patch

lib/Listener/LoadContactsOcaApi.php#L20

Added line #L20 was not covered by tests
private IInitialState $initialState,
) {
}

public function handle(Event $event): void {
if (!($event instanceof LoadContactsOcaApiEvent)) {
return;

Check warning on line 27 in lib/Listener/LoadContactsOcaApi.php

View check run for this annotation

Codecov / codecov/patch

lib/Listener/LoadContactsOcaApi.php#L25-L27

Added lines #L25 - L27 were not covered by tests
}

// TODO: do we need to provide more initial state?
$this->initialState->provideInitialState('supportedNetworks', []);
Util::addScript(Application::APP_ID, 'contacts-oca');

Check warning on line 32 in lib/Listener/LoadContactsOcaApi.php

View check run for this annotation

Codecov / codecov/patch

lib/Listener/LoadContactsOcaApi.php#L31-L32

Added lines #L31 - L32 were not covered by tests
}
}
26 changes: 26 additions & 0 deletions src/oca.js
Original file line number Diff line number Diff line change
@@ -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<object>} Mounted Vue instance (vm)
*/
async mountContactDetails(el, contactEmailAddress) {
const { mountContactDetails } = await import('./oca/mountContactDetails.js')
return mountContactDetails(el, contactEmailAddress)
},
}
48 changes: 48 additions & 0 deletions src/oca/mountContactDetails.js
Original file line number Diff line number Diff line change
@@ -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<object>}
*/
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
}
Loading
Loading