Skip to content

Commit

Permalink
Implement Calendar Dashboard Widget
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr authored and georgehrke committed Aug 21, 2020
1 parent 324e242 commit 2abed44
Show file tree
Hide file tree
Showing 11 changed files with 727 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']
nextcloud-versions: ['master', 'stable17', 'stable18']
nextcloud-versions: ['master']
exclude:
- php-versions: '7.4'
nextcloud-versions: 'stable17'
Expand Down
24 changes: 22 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,39 @@
*/
namespace OCA\Calendar\AppInfo;

use OCA\Calendar\Dashboard\CalendarWidget;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;

/**
* Class Application
*
* @package OCA\Calendar\AppInfo
*/
class Application extends App {
class Application extends App implements IBootstrap {

/** @var string */
public const APP_ID = 'calendar';

/**
* @param array $params
*/
public function __construct(array $params=[]) {
parent::__construct('calendar', $params);
parent::__construct(self::APP_ID, $params);
}

/**
* @inheritDoc
*/
public function register(IRegistrationContext $context): void {
$context->registerDashboardWidget(CalendarWidget::class);
}

/**
* @inheritDoc
*/
public function boot(IBootContext $context): void {
}
}
110 changes: 110 additions & 0 deletions lib/Dashboard/CalendarWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

declare(strict_types=1);
/**
* @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\Calendar\Dashboard;

use OCA\Calendar\AppInfo\Application;
use OCA\Calendar\Service\JSDataService;
use OCP\Dashboard\IWidget;
use OCP\IInitialStateService;
use OCP\IL10N;

class CalendarWidget implements IWidget {

/**
* @var IL10N
*/
private $l10n;

/**
* @var IInitialStateService
*/
private $initialStateService;

/**
* @var JSDataService
*/
private $dataService;

/**
* CalendarWidget constructor.
* @param IL10N $l10n
* @param IInitialStateService $initialStateService
* @param JSDataService $dataService
*/
public function __construct(IL10N $l10n,
IInitialStateService $initialStateService,
JSDataService $dataService) {
$this->l10n = $l10n;
$this->initialStateService = $initialStateService;
$this->dataService = $dataService;
}

/**
* @inheritDoc
*/
public function getId(): string {
return Application::APP_ID;
}

/**
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Upcoming events');
}

/**
* @inheritDoc
*/
public function getOrder(): int {
return 2;
}

/**
* @inheritDoc
*/
public function getIconClass(): string {
return 'icon-calendar-dark';
}

/**
* @inheritDoc
*/
public function getUrl(): ?string {
return null;
}

/**
* @inheritDoc
*/
public function load(): void {
\OCP\Util::addScript('calendar', 'dashboard');

$this->initialStateService->provideLazyInitialState(Application::APP_ID, 'dashboard_data', function () {
return $this->dataService;
});
}
}
70 changes: 70 additions & 0 deletions lib/Service/JSDataService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);
/**
* Calendar App
*
* @author Georg Ehrke
* @copyright 2020 Georg Ehrke <oc.list@georgehrke.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Calendar\Service;

use OCA\Calendar\AppInfo\Application;
use OCP\IConfig;
use OCP\IUserSession;

class JSDataService implements \JsonSerializable {

/** @var IConfig */
private $config;

/** @var IUserSession */
private $userSession;

/**
* JSDataService constructor.
*
* @param IConfig $config
* @param IUserSession $userSession
*/
public function __construct(IConfig $config,
IUserSession $userSession) {
$this->config = $config;
$this->userSession = $userSession;
}

/**
* @inheritDoc
*/
public function jsonSerialize() {
$user = $this->userSession->getUser();

if ($user === null) {
return [];
}

$defaultTimezone = $this->config->getAppValue(Application::APP_ID, 'timezone', 'automatic');
$defaultShowTasks = $this->config->getAppValue(Application::APP_ID, 'showTasks', 'yes');
$timezone = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'timezone', $defaultTimezone);
$showTasks = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'showTasks', $defaultShowTasks) === 'yes';

return [
'timezone' => $timezone,
'show_tasks' => $showTasks,
];
}
}
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@nextcloud/moment": "^1.1.0",
"@nextcloud/router": "^1.1.0",
"@nextcloud/vue": "^2.3.0",
"@nextcloud/vue-dashboard": "^0.1.3",
"autosize": "^4.0.2",
"calendar-js": "git+https://github.com/georgehrke/calendar-js.git",
"cdav-library": "github:nextcloud/cdav-library",
Expand Down
50 changes: 50 additions & 0 deletions src/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* @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/>.
*
*/

import Vue from 'vue'
import { generateFilePath } from '@nextcloud/router'
import { getRequestToken } from '@nextcloud/auth'
import { translate, translatePlural } from '@nextcloud/l10n'
import Dashboard from './views/Dashboard'
import store from './store'

// eslint-disable-next-line
__webpack_nonce__ = btoa(getRequestToken())

// eslint-disable-next-line
__webpack_public_path__ = generateFilePath('calendar', '', 'js/')

Vue.prototype.t = translate
Vue.prototype.n = translatePlural
Vue.prototype.OC = OC
Vue.prototype.OCA = OCA

document.addEventListener('DOMContentLoaded', function() {
OCA.Dashboard.register('calendar', (el) => {
const View = Vue.extend(Dashboard)
new View({
store,
propsData: {},
}).$mount(el)
})

})
Loading

0 comments on commit 2abed44

Please sign in to comment.