Skip to content

Commit

Permalink
Merge pull request #229 from nextcloud/enh/dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Aug 14, 2020
2 parents 4048c31 + f7acc79 commit debd295
Show file tree
Hide file tree
Showing 14 changed files with 1,444 additions and 15 deletions.
894 changes: 894 additions & 0 deletions js/dashboard.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/dashboard.js.map

Large diffs are not rendered by default.

35 changes: 28 additions & 7 deletions js/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/main.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCA\Recommendations\Dashboard\RecommendationWidget;

class Application extends App implements IBootstrap {

Expand All @@ -42,6 +43,7 @@ public function __construct(array $urlParams = []) {

public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesLoadAdditionalScriptsListener::class);
$context->registerDashboardWidget(RecommendationWidget::class);
}

public function boot(IBootContext $context): void {
Expand Down
92 changes: 92 additions & 0 deletions lib/Dashboard/RecommendationWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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 OCA\Recommendations\Dashboard;

use OCA\Recommendations\Service\RecommendationService;
use OCP\Dashboard\IWidget;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Util;

class RecommendationWidget implements IWidget {

/** @var IInitialStateService */
private $initialStateService;
/** @var IUserSession */
private $userSession;
/** @var RecommendationService */
private $recommendationService;
/** @var IL10N */
private $l10n;
/** @var IURLGenerator */
private $urlGenerator;

public function __construct(
IInitialStateService $initialStateService,
IUserSession $userSession,
RecommendationService $recommendationService,
IL10N $l10n,
IURLGenerator $urlGenerator
) {
$this->initialStateService = $initialStateService;
$this->userSession = $userSession;
$this->recommendationService = $recommendationService;
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
}

public function getId(): string {
return 'recommendations';
}

public function getTitle(): string {
return $this->l10n->t('Recommended files');
}

public function getOrder(): int {
return 0;
}

public function getIconClass(): string {
return 'icon-files-dark';
}

public function getUrl(): ?string {
return null;
}

public function load(): void {
$user = $this->userSession->getUser();
if ($user === null) {
return;
}
$this->initialStateService->provideInitialState('recommendations', 'recommendations', [
'enabled' => true,
'recommendations' => $this->recommendationService->getRecommendations($user)
]);
Util::addScript('recommendations', 'dashboard');
}
}
2 changes: 1 addition & 1 deletion lib/Service/RecommendationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

class RecommendationService {

private const MAX_RECOMMENDATIONS = 6;
private const MAX_RECOMMENDATIONS = 7;

/** @var IRecommendationSource */
private $sources;
Expand Down
Loading

0 comments on commit debd295

Please sign in to comment.