Skip to content

Commit 0a7ebcb

Browse files
committed
Add api to load additional section in profile page
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 52d962b commit 0a7ebcb

File tree

9 files changed

+102
-7
lines changed

9 files changed

+102
-7
lines changed

core/Controller/ProfilePageController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace OC\Core\Controller;
2828

2929
use OC\Profile\ProfileManager;
30+
use OCP\Profile\BeforeTemplateRenderedEvent;
3031
use OCP\AppFramework\Controller;
3132
use OCP\AppFramework\Http\TemplateResponse;
3233
use OCP\AppFramework\Services\IInitialState;
@@ -36,6 +37,7 @@
3637
use OCP\IUserSession;
3738
use OCP\Share\IManager as IShareManager;
3839
use OCP\UserStatus\IManager as IUserStatusManager;
40+
use OCP\EventDispatcher\IEventDispatcher;
3941

4042
class ProfilePageController extends Controller {
4143
private IInitialState $initialStateService;
@@ -44,6 +46,7 @@ class ProfilePageController extends Controller {
4446
private IUserManager $userManager;
4547
private IUserSession $userSession;
4648
private IUserStatusManager $userStatusManager;
49+
private IEventDispatcher $EventDispatcher;
4750

4851
public function __construct(
4952
$appName,
@@ -53,7 +56,8 @@ public function __construct(
5356
IShareManager $shareManager,
5457
IUserManager $userManager,
5558
IUserSession $userSession,
56-
IUserStatusManager $userStatusManager
59+
IUserStatusManager $userStatusManager,
60+
IEventDispatcher $eventDispatcher
5761
) {
5862
parent::__construct($appName, $request);
5963
$this->initialStateService = $initialStateService;
@@ -62,6 +66,7 @@ public function __construct(
6266
$this->userManager = $userManager;
6367
$this->userSession = $userSession;
6468
$this->userStatusManager = $userStatusManager;
69+
$this->eventDispatcher = $eventDispatcher;
6570
}
6671

6772
/**
@@ -111,6 +116,8 @@ public function index(string $targetUserId): TemplateResponse {
111116
$this->profileManager->getProfileParams($targetUser, $visitingUser),
112117
);
113118

119+
$this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($targetUserId));
120+
114121
\OCP\Util::addScript('core', 'profile');
115122

116123
return new TemplateResponse(

core/src/profile.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,23 @@ import { getRequestToken } from '@nextcloud/auth'
2525
import { translate as t } from '@nextcloud/l10n'
2626
import VTooltip from 'v-tooltip'
2727

28-
import logger from './logger'
28+
import logger from './logger.js'
2929

30-
import Profile from './views/Profile'
30+
import Profile from './views/Profile.vue'
31+
import ProfileSections from './profile/ProfileSections.js'
3132

3233
__webpack_nonce__ = btoa(getRequestToken())
3334

35+
if (!window.OCA) {
36+
window.OCA = {}
37+
}
38+
39+
if (!window.OCA.Core) {
40+
window.OCA.Core = {}
41+
}
42+
Object.assign(window.OCA.Core, { ProfileSections: new ProfileSections() })
43+
console.debug('Core', window.OCA.Core)
44+
3445
Vue.use(VTooltip)
3546

3647
Vue.mixin({
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
/**
3+
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
4+
*
5+
* @author Julius Härtl <jus@bitgrid.net>
6+
*
7+
* @license AGPL-3.0-or-later
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
export default class ProfileSections {
25+
26+
_sections
27+
28+
constructor() {
29+
this._sections = []
30+
}
31+
32+
/**
33+
* @param {registerSectionCallback} section To be called to mount the section to the profile page
34+
*/
35+
registerSection(section) {
36+
console.debug('register sections')
37+
this._sections.push(section)
38+
}
39+
40+
getSections() {
41+
console.debug('Getiing sections')
42+
return this._sections
43+
}
44+
}

core/src/views/Profile.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,21 @@
118118
</p>
119119
</div>
120120
</div>
121-
<template v-if="headline || biography">
121+
<template v-if="headline || biography || sections.length > 0">
122122
<div v-if="headline" class="profile__blocks-headline">
123123
<h3>{{ headline }}</h3>
124124
</div>
125125
<div v-if="biography" class="profile__blocks-biography">
126126
<p>{{ biography }}</p>
127127
</div>
128+
129+
<!-- additional entries, use it with cautious -->
130+
<div v-for="(section, index) in sections"
131+
:ref="'section-' + index"
132+
:key="index"
133+
class="profile__additionalContent">
134+
<component :is="section($refs['section-'+index], userId)" :userId="userId" />
135+
</div>
128136
</template>
129137
<template v-else>
130138
<div class="profile__blocks-empty-info">
@@ -204,6 +212,7 @@ export default {
204212
biography,
205213
actions,
206214
isUserAvatarVisible,
215+
sections: OCA.Core.ProfileSections.getSections(),
207216
}
208217
},
209218

dist/core-profile.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-profile.js.LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,25 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22+
23+
/**
24+
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
25+
*
26+
* @author Julius Härtl <jus@bitgrid.net>
27+
*
28+
* @license AGPL-3.0-or-later
29+
*
30+
* This program is free software: you can redistribute it and/or modify
31+
* it under the terms of the GNU Affero General Public License as
32+
* published by the Free Software Foundation, either version 3 of the
33+
* License, or (at your option) any later version.
34+
*
35+
* This program is distributed in the hope that it will be useful,
36+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
37+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38+
* GNU Affero General Public License for more details.
39+
*
40+
* You should have received a copy of the GNU Affero General Public License
41+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
42+
*
43+
*/

dist/core-profile.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@
491491
'OCP\\Preview\\IProvider' => $baseDir . '/lib/public/Preview/IProvider.php',
492492
'OCP\\Preview\\IProviderV2' => $baseDir . '/lib/public/Preview/IProviderV2.php',
493493
'OCP\\Preview\\IVersionedPreviewFile' => $baseDir . '/lib/public/Preview/IVersionedPreviewFile.php',
494+
'OCP\\Profile\\BeforeTemplateRenderedEvent' => $baseDir . '/lib/public/Profile/BeforeTemplateRenderedEvent.php',
494495
'OCP\\Profile\\ILinkAction' => $baseDir . '/lib/public/Profile/ILinkAction.php',
495496
'OCP\\Profile\\ParameterDoesNotExistException' => $baseDir . '/lib/public/Profile/ParameterDoesNotExistException.php',
496497
'OCP\\Profiler\\IProfile' => $baseDir . '/lib/public/Profiler/IProfile.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
524524
'OCP\\Preview\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Preview/IProvider.php',
525525
'OCP\\Preview\\IProviderV2' => __DIR__ . '/../../..' . '/lib/public/Preview/IProviderV2.php',
526526
'OCP\\Preview\\IVersionedPreviewFile' => __DIR__ . '/../../..' . '/lib/public/Preview/IVersionedPreviewFile.php',
527+
'OCP\\Profile\\BeforeTemplateRenderedEvent' => __DIR__ . '/../../..' . '/lib/public/Profile/BeforeTemplateRenderedEvent.php',
527528
'OCP\\Profile\\ILinkAction' => __DIR__ . '/../../..' . '/lib/public/Profile/ILinkAction.php',
528529
'OCP\\Profile\\ParameterDoesNotExistException' => __DIR__ . '/../../..' . '/lib/public/Profile/ParameterDoesNotExistException.php',
529530
'OCP\\Profiler\\IProfile' => __DIR__ . '/../../..' . '/lib/public/Profiler/IProfile.php',

0 commit comments

Comments
 (0)