diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-09-12 23:58:53 +0300 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-09-14 13:55:40 +0300 |
commit | 66a7a89898678f30118151733be42ce041f55816 (patch) | |
tree | 4aff2a46fe0b1ef3971f6c0055cebbdf6fac17cb /core | |
parent | 52d962bd5346f8879290c332a2e35ad6d12c84df (diff) |
Add api to load additional section in profile page
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/ProfilePageController.php | 9 | ||||
-rw-r--r-- | core/src/profile.js | 14 | ||||
-rw-r--r-- | core/src/profile/ProfileSections.js | 43 | ||||
-rw-r--r-- | core/src/views/Profile.vue | 11 |
4 files changed, 73 insertions, 4 deletions
diff --git a/core/Controller/ProfilePageController.php b/core/Controller/ProfilePageController.php index 61573f43753..4b710911482 100644 --- a/core/Controller/ProfilePageController.php +++ b/core/Controller/ProfilePageController.php @@ -27,6 +27,7 @@ declare(strict_types=1); 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\IUserManager; 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 @@ class ProfilePageController extends Controller { IShareManager $shareManager, IUserManager $userManager, IUserSession $userSession, - IUserStatusManager $userStatusManager + IUserStatusManager $userStatusManager, + IEventDispatcher $eventDispatcher ) { parent::__construct($appName, $request); $this->initialStateService = $initialStateService; @@ -62,6 +66,7 @@ class ProfilePageController extends Controller { $this->userManager = $userManager; $this->userSession = $userSession; $this->userStatusManager = $userStatusManager; + $this->eventDispatcher = $eventDispatcher; } /** @@ -111,6 +116,8 @@ class ProfilePageController extends Controller { $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 5e3711841a6..79465c6a28d 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 00000000000..4091c8332d6 --- /dev/null +++ b/core/src/profile/ProfileSections.js @@ -0,0 +1,43 @@ + +/** + * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +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 93b8316e4da..c7571fff148 100644 --- a/core/src/views/Profile.vue +++ b/core/src/views/Profile.vue @@ -118,13 +118,21 @@ </p> </div> </div> - <template v-if="headline || biography"> + <template v-if="headline || biography || sections.length > 0"> <div v-if="headline" class="profile__blocks-headline"> <h3>{{ headline }}</h3> </div> <div v-if="biography" class="profile__blocks-biography"> <p>{{ biography }}</p> </div> + + <!-- additional entries, use it with cautious --> + <div v-for="(section, index) in sections" + :ref="'section-' + index" + :key="index" + class="profile__additionalContent"> + <component :is="section($refs['section-'+index], userId)" :userId="userId" /> + </div> </template> <template v-else> <div class="profile__blocks-empty-info"> @@ -204,6 +212,7 @@ export default { biography, actions, isUserAvatarVisible, + sections: OCA.Core.ProfileSections.getSections(), } }, |