Skip to content

Commit

Permalink
feat: create a readonly contactdetails
Browse files Browse the repository at this point in the history
Signed-off-by: greta <gretadoci@gmail.com>
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
GretaD authored and st3iny committed Dec 18, 2024
1 parent 7a6a92a commit b5458b1
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 0 deletions.
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 __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 {
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 {
}
35 changes: 35 additions & 0 deletions lib/Listener/LoadContactsOcaApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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(
private IInitialState $initialState,
) {
}

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

// TODO: do we need to provide more initial state?
$this->initialState->provideInitialState('supportedNetworks', []);
Util::addScript(Application::APP_ID, 'contacts-oca');
Util::addStyle(Application::APP_ID, 'contacts-oca');
}
}
27 changes: 27 additions & 0 deletions src/oca.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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'

import { mountContactDetails } from './oca/mountContactDetails.js'

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) {
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 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

0 comments on commit b5458b1

Please sign in to comment.