diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a1860c7bb..7d4fe3c83 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -33,6 +33,7 @@ use OCP\Notification\IManager as NotificationManager; use OCP\Group\Events\GroupDeletedEvent; use OCP\User\Events\UserDeletedEvent; +use OCA\Polls\Dashboard\PollWidget; use OCA\Polls\Event\CommentAddEvent; use OCA\Polls\Event\CommentDeleteEvent; use OCA\Polls\Event\OptionConfirmedEvent; @@ -109,6 +110,7 @@ public function register(IRegistrationContext $context): void { $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class); $context->registerSearchProvider(SearchProvider::class); + $context->registerDashboardWidget(PollWidget::class); } public function registerNotifications(NotificationManager $notificationManager): void { diff --git a/lib/Dashboard/PollWidget.php b/lib/Dashboard/PollWidget.php new file mode 100644 index 000000000..444b08dbe --- /dev/null +++ b/lib/Dashboard/PollWidget.php @@ -0,0 +1,65 @@ + + * + * @author Michael Longo + * + * @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 . + * + */ + +namespace OCA\Polls\Dashboard; + +use OCP\Dashboard\IWidget; +use OCP\IL10N; +use OCP\IURLGenerator; + +class PollWidget implements IWidget { + private IL10N $l10n; + private IURLGenerator $urlGenerator; + + public function __construct( + IL10N $l10n, + IURLGenerator $urlGenerator + ) { + $this->l10n = $l10n; + $this->urlGenerator = $urlGenerator; + } + + public function getId(): string { + return 'polls'; + } + + public function getTitle(): string { + return $this->l10n->t('Polls'); + } + + public function getOrder(): int { + return 50; + } + + public function getIconClass(): string { + return 'icon-polls'; + } + + public function getUrl(): ?string { + return $this->urlGenerator->linkToRouteAbsolute('polls.page.index'); + } + + public function load(): void { + \OCP\Util::addScript('polls', 'polls-dashboard'); + } +} diff --git a/src/js/assets/scss/dashboard.scss b/src/js/assets/scss/dashboard.scss new file mode 100644 index 000000000..4eedc9250 --- /dev/null +++ b/src/js/assets/scss/dashboard.scss @@ -0,0 +1,7 @@ +.icon-polls { + background-image: url(../../../../img/polls-black.svg); +} + +body.dark .icon-polls { + background-image: url(../../../../img/polls.svg); +} \ No newline at end of file diff --git a/src/js/init-dashboard.js b/src/js/init-dashboard.js new file mode 100644 index 000000000..4040d68ca --- /dev/null +++ b/src/js/init-dashboard.js @@ -0,0 +1,53 @@ +/* jshint esversion: 6 */ +/** + * @copyright Copyright (c) 2022 Michael Longo + * + * @author Michael Longo + * + * @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 . + * + */ + +import Vue from 'vue' +import store from './store/index.js' +import { getRequestToken, getCurrentUser } from '@nextcloud/auth' +import { translate, translatePlural } from '@nextcloud/l10n' +import { generateFilePath } from '@nextcloud/router' + +import Dashboard from './views/Dashboard.vue' +import './assets/scss/dashboard.scss' + +Vue.config.debug = process.env.NODE_ENV !== 'production' +Vue.config.devTools = process.env.NODE_ENV !== 'production' + +/* eslint-disable-next-line camelcase, no-undef */ +__webpack_nonce__ = btoa(getRequestToken()) +/* eslint-disable-next-line camelcase, no-undef */ +__webpack_public_path__ = generateFilePath('polls', '', 'js/') + +Vue.prototype.t = translate +Vue.prototype.n = translatePlural +Vue.prototype.getCurrentUser = getCurrentUser + +document.addEventListener('DOMContentLoaded', () => { + OCA.Dashboard.register('polls', (el) => { + const View = Vue.extend(Dashboard) + new View({ + propsData: {}, + store, + }).$mount(el) + }) +}) diff --git a/src/js/views/Dashboard.vue b/src/js/views/Dashboard.vue new file mode 100644 index 000000000..4ad6193c8 --- /dev/null +++ b/src/js/views/Dashboard.vue @@ -0,0 +1,160 @@ + + + + + + diff --git a/webpack.config.js b/webpack.config.js index 34dbcb7c0..39e59c54d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,6 +6,7 @@ webpackConfig.entry = { main: path.join(__dirname, 'src/js/', 'main.js'), userSettings: path.join(__dirname, 'src/js/', 'userSettings.js'), adminSettings: path.join(__dirname, 'src/js/', 'adminSettings.js'), + dashboard: path.join(__dirname, 'src/js/', 'init-dashboard.js'), } webpackConfig.output = {