From dd929a7c0fe3152d24b7e7cbef0637e3d912ffe6 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 12 Sep 2022 22:58:53 +0200 Subject: [PATCH] Add api to load additional section in profile page Signed-off-by: Carl Schwan --- core/Controller/ProfilePageController.php | 9 +++- core/src/profile.js | 14 ++++- core/src/profile/ProfileSections.js | 42 +++++++++++++++ core/src/views/Profile.vue | 11 +++- dist/core-profile.js | 4 +- dist/core-profile.js.LICENSE.txt | 22 ++++++++ dist/core-profile.js.map | 2 +- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + .../Profile/BeforeTemplateRenderedEvent.php | 54 +++++++++++++++++++ 10 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 core/src/profile/ProfileSections.js create mode 100644 lib/public/Profile/BeforeTemplateRenderedEvent.php diff --git a/core/Controller/ProfilePageController.php b/core/Controller/ProfilePageController.php index 61573f43753df..4b710911482e4 100644 --- a/core/Controller/ProfilePageController.php +++ b/core/Controller/ProfilePageController.php @@ -27,6 +27,7 @@ namespace OC\Core\Controller; use OC\Profile\ProfileManager; +use OCP\Profile\BeforeTemplateRenderedEvent; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; @@ -36,6 +37,7 @@ use OCP\IUserSession; use OCP\Share\IManager as IShareManager; use OCP\UserStatus\IManager as IUserStatusManager; +use OCP\EventDispatcher\IEventDispatcher; class ProfilePageController extends Controller { private IInitialState $initialStateService; @@ -44,6 +46,7 @@ class ProfilePageController extends Controller { private IUserManager $userManager; private IUserSession $userSession; private IUserStatusManager $userStatusManager; + private IEventDispatcher $eventDispatcher; public function __construct( $appName, @@ -53,7 +56,8 @@ public function __construct( IShareManager $shareManager, IUserManager $userManager, IUserSession $userSession, - IUserStatusManager $userStatusManager + IUserStatusManager $userStatusManager, + IEventDispatcher $eventDispatcher ) { parent::__construct($appName, $request); $this->initialStateService = $initialStateService; @@ -62,6 +66,7 @@ public function __construct( $this->userManager = $userManager; $this->userSession = $userSession; $this->userStatusManager = $userStatusManager; + $this->eventDispatcher = $eventDispatcher; } /** @@ -111,6 +116,8 @@ public function index(string $targetUserId): TemplateResponse { $this->profileManager->getProfileParams($targetUser, $visitingUser), ); + $this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($targetUserId)); + \OCP\Util::addScript('core', 'profile'); return new TemplateResponse( diff --git a/core/src/profile.js b/core/src/profile.js index 5e3711841a643..bed02795c517e 100644 --- a/core/src/profile.js +++ b/core/src/profile.js @@ -25,12 +25,22 @@ import { getRequestToken } from '@nextcloud/auth' import { translate as t } from '@nextcloud/l10n' import VTooltip from 'v-tooltip' -import logger from './logger' +import logger from './logger.js' -import Profile from './views/Profile' +import Profile from './views/Profile.vue' +import ProfileSections from './profile/ProfileSections.js' __webpack_nonce__ = btoa(getRequestToken()) +if (!window.OCA) { + window.OCA = {} +} + +if (!window.OCA.Core) { + window.OCA.Core = {} +} +Object.assign(window.OCA.Core, { ProfileSections: new ProfileSections() }) + Vue.use(VTooltip) Vue.mixin({ diff --git a/core/src/profile/ProfileSections.js b/core/src/profile/ProfileSections.js new file mode 100644 index 0000000000000..03241b0c0c5d5 --- /dev/null +++ b/core/src/profile/ProfileSections.js @@ -0,0 +1,42 @@ + +/** + * @copyright Copyright (c) 2019 Julius Härtl + * + * @author Julius Härtl + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +export default class ProfileSections { + + _sections + + constructor() { + this._sections = [] + } + + /** + * @param {registerSectionCallback} section To be called to mount the section to the profile page + */ + registerSection(section) { + this._sections.push(section) + } + + getSections() { + return this._sections + } +} diff --git a/core/src/views/Profile.vue b/core/src/views/Profile.vue index 93b8316e4da45..c7571fff14804 100644 --- a/core/src/views/Profile.vue +++ b/core/src/views/Profile.vue @@ -118,13 +118,21 @@

-