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

Add api to load additional section in profile page #34042

Merged
merged 1 commit into from
Sep 14, 2022
Merged
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
9 changes: 8 additions & 1 deletion core/Controller/ProfilePageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OC\Core\Controller;

use OC\Profile\ProfileManager;
use OCP\Profile\BeforeTemplateRenderedEvent;
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
Expand All @@ -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;
Expand All @@ -44,6 +46,7 @@ class ProfilePageController extends Controller {
private IUserManager $userManager;
private IUserSession $userSession;
private IUserStatusManager $userStatusManager;
private IEventDispatcher $eventDispatcher;

public function __construct(
$appName,
Expand All @@ -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;
Expand All @@ -62,6 +66,7 @@ public function __construct(
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->userStatusManager = $userStatusManager;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions core/src/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
43 changes: 43 additions & 0 deletions core/src/profile/ProfileSections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
*
* @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
}

}
11 changes: 10 additions & 1 deletion core/src/views/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
</div>
</template>
<template v-else>
<div class="profile__blocks-empty-info">
Expand Down Expand Up @@ -204,6 +212,7 @@ export default {
biography,
actions,
isUserAvatarVisible,
sections: OCA.Core.ProfileSections.getSections(),
}
},

Expand Down
4 changes: 2 additions & 2 deletions dist/core-profile.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions dist/core-profile.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @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/>.
*
*/
2 changes: 1 addition & 1 deletion dist/core-profile.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@
'OCP\\Preview\\IProvider' => $baseDir . '/lib/public/Preview/IProvider.php',
'OCP\\Preview\\IProviderV2' => $baseDir . '/lib/public/Preview/IProviderV2.php',
'OCP\\Preview\\IVersionedPreviewFile' => $baseDir . '/lib/public/Preview/IVersionedPreviewFile.php',
'OCP\\Profile\\BeforeTemplateRenderedEvent' => $baseDir . '/lib/public/Profile/BeforeTemplateRenderedEvent.php',
'OCP\\Profile\\ILinkAction' => $baseDir . '/lib/public/Profile/ILinkAction.php',
'OCP\\Profile\\ParameterDoesNotExistException' => $baseDir . '/lib/public/Profile/ParameterDoesNotExistException.php',
'OCP\\Profiler\\IProfile' => $baseDir . '/lib/public/Profiler/IProfile.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Preview\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Preview/IProvider.php',
'OCP\\Preview\\IProviderV2' => __DIR__ . '/../../..' . '/lib/public/Preview/IProviderV2.php',
'OCP\\Preview\\IVersionedPreviewFile' => __DIR__ . '/../../..' . '/lib/public/Preview/IVersionedPreviewFile.php',
'OCP\\Profile\\BeforeTemplateRenderedEvent' => __DIR__ . '/../../..' . '/lib/public/Profile/BeforeTemplateRenderedEvent.php',
'OCP\\Profile\\ILinkAction' => __DIR__ . '/../../..' . '/lib/public/Profile/ILinkAction.php',
'OCP\\Profile\\ParameterDoesNotExistException' => __DIR__ . '/../../..' . '/lib/public/Profile/ParameterDoesNotExistException.php',
'OCP\\Profiler\\IProfile' => __DIR__ . '/../../..' . '/lib/public/Profiler/IProfile.php',
Expand Down
54 changes: 54 additions & 0 deletions lib/public/Profile/BeforeTemplateRenderedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
* @author Morris Jobke <hey@morrisjobke.de>
*
* @license GNU AGPL version 3 or any later version
*
* 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/>.
*
*/
namespace OCP\Profile;

use OCP\EventDispatcher\Event;

/**
* Emitted before the rendering step of the public profile page happens.
*
* @since 25.0.0
*/
class BeforeTemplateRenderedEvent extends Event {
private string $userId;

/**
* @since 25.0.0
*/
public function __construct(string $userId) {
parent::__construct();

$this->userId = $userId;
}

/**
* @since 25.0.0
*/
public function getUserId(): string {
return $this->userId;
}
}