-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Dashboard API #21346
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
Merged
Merged
Dashboard API #21346
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
673d70d
Add new dashboard public API
juliusknorr 544fcdb
Deprecate old dashboard API
juliusknorr 5a18749
Add dashboard app
juliusknorr 4b9d47f
Modify dashboard welcome sentences
jancborchardt 829bf1a
Fix Dashboard layout, positioning and responsiveness
jancborchardt a0cd760
Separate icon from translatable text
juliusknorr 86a7d16
Update autoloader
juliusknorr 81e5593
Move to lazy panel registration during registration context
juliusknorr f7c04b0
Deprecate panel register event right away but keep it for not breakin…
juliusknorr 66ce9ed
Initialize panels early to make sure that scripts can be loaded
juliusknorr b71de68
Cleanup public api methods
juliusknorr 879b756
Update Dashboard app icon
jancborchardt 31a1494
Add load method for apps to bootstrap their panels
juliusknorr e6fb1b9
Load more than one panel
juliusknorr 35bdb99
Dashboard strict typing
juliusknorr 0c35218
Include name in translatable greeting
juliusknorr 6b2bb32
Bump bundles
juliusknorr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?xml version="1.0"?> | ||
| <info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd"> | ||
| <id>dashboard</id> | ||
| <name>Dashboard</name> | ||
| <summary>Dashboard app</summary> | ||
| <description><![CDATA[Show something]]></description> | ||
| <version>7.0.0</version> | ||
| <licence>agpl</licence> | ||
| <author>Julius Härtl</author> | ||
| <namespace>Dashboard</namespace> | ||
| <default_enable/> | ||
|
|
||
| <category>customization</category> | ||
|
|
||
| <bugs>https://github.com/nextcloud/server/issues</bugs> | ||
|
|
||
| <dependencies> | ||
| <nextcloud min-version="20" max-version="20"/> | ||
| </dependencies> | ||
|
|
||
| <navigations> | ||
| <navigation> | ||
| <name>Dashboard</name> | ||
| <route>dashboard.dashboard.index</route> | ||
| <icon>dashboard.svg</icon> | ||
| <order>-1</order> | ||
| </navigation> | ||
| </navigations> | ||
| </info> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2020 Julius Härtl <[email protected]> | ||
| * | ||
| * @author Julius Härtl <[email protected]> | ||
| * | ||
| * @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/>. | ||
| * | ||
| */ | ||
|
|
||
| return [ | ||
| 'routes' => [ | ||
| ['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'], | ||
| ] | ||
| ]; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2020 Julius Härtl <[email protected]> | ||
| * | ||
| * @author Julius Härtl <[email protected]> | ||
| * | ||
| * @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\Dashboard\Controller; | ||
|
|
||
| use OCA\Viewer\Event\LoadViewer; | ||
| use OCP\AppFramework\Controller; | ||
| use OCP\AppFramework\Http\TemplateResponse; | ||
| use OCP\Dashboard\IManager; | ||
| use OCP\Dashboard\IPanel; | ||
| use OCP\Dashboard\RegisterPanelEvent; | ||
| use OCP\EventDispatcher\IEventDispatcher; | ||
| use OCP\IInitialStateService; | ||
| use OCP\IRequest; | ||
|
|
||
| class DashboardController extends Controller { | ||
|
|
||
| /** @var IInitialStateService */ | ||
| private $inititalStateService; | ||
| /** @var IEventDispatcher */ | ||
| private $eventDispatcher; | ||
| /** @var IManager */ | ||
| private $dashboardManager; | ||
|
|
||
| public function __construct( | ||
| string $appName, | ||
| IRequest $request, | ||
| IInitialStateService $initialStateService, | ||
| IEventDispatcher $eventDispatcher, | ||
| IManager $dashboardManager | ||
| ) { | ||
| parent::__construct($appName, $request); | ||
|
|
||
| $this->inititalStateService = $initialStateService; | ||
| $this->eventDispatcher = $eventDispatcher; | ||
| $this->dashboardManager = $dashboardManager; | ||
| } | ||
|
|
||
| /** | ||
| * @NoCSRFRequired | ||
| * @NoAdminRequired | ||
| * @return TemplateResponse | ||
| */ | ||
| public function index(): TemplateResponse { | ||
| $this->eventDispatcher->dispatchTyped(new RegisterPanelEvent($this->dashboardManager)); | ||
|
|
||
| $dashboardManager = $this->dashboardManager; | ||
| $panels = array_map(function (IPanel $panel) { | ||
| return [ | ||
| 'id' => $panel->getId(), | ||
| 'title' => $panel->getTitle(), | ||
| 'iconClass' => $panel->getIconClass(), | ||
| 'url' => $panel->getUrl() | ||
| ]; | ||
| }, $dashboardManager->getPanels()); | ||
| $this->inititalStateService->provideInitialState('dashboard', 'panels', $panels); | ||
|
|
||
| if (class_exists(LoadViewer::class)) { | ||
ChristophWurst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->eventDispatcher->dispatchTyped(new LoadViewer()); | ||
| } | ||
|
|
||
| return new TemplateResponse('dashboard', 'index'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| <template> | ||
| <div id="app-dashboard"> | ||
| <h2>{{ greeting.icon }} {{ greeting.text }}</h2> | ||
|
|
||
| <div class="panels"> | ||
| <div v-for="panel in panels" :key="panel.id" class="panel"> | ||
| <a :href="panel.url"> | ||
| <h3 :class="panel.iconClass"> | ||
| {{ panel.title }} | ||
| </h3> | ||
| </a> | ||
| <div :ref="panel.id" :data-id="panel.id" /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import Vue from 'vue' | ||
| import { loadState } from '@nextcloud/initial-state' | ||
| import { getCurrentUser } from '@nextcloud/auth' | ||
|
|
||
| const panels = loadState('dashboard', 'panels') | ||
|
|
||
| export default { | ||
| name: 'App', | ||
| data() { | ||
| return { | ||
| timer: new Date(), | ||
| callbacks: {}, | ||
| panels, | ||
| name: getCurrentUser()?.displayName, | ||
| } | ||
| }, | ||
| computed: { | ||
| greeting() { | ||
| const time = this.timer.getHours() | ||
|
|
||
| if (time > 18) { | ||
| return { icon: '🌙', text: t('dashboard', 'Good evening, {name}', { name: this.name }) } | ||
| } | ||
| if (time > 12) { | ||
| return { icon: '☀', text: t('dashboard', 'Good afternoon, {name}', { name: this.name }) } | ||
| } | ||
| if (time === 12) { | ||
| return { icon: '🍽', text: t('dashboard', 'Time for lunch, {name}', { name: this.name }) } | ||
| } | ||
| if (time > 5) { | ||
| return { icon: '🌄', text: t('dashboard', 'Good morning, {name}', { name: this.name }) } | ||
| } | ||
| return { icon: '🦉', text: t('dashboard', 'Have a night owl, {name}', { name: this.name }) } | ||
| }, | ||
| }, | ||
| watch: { | ||
| callbacks() { | ||
| for (const app in this.callbacks) { | ||
| const element = this.$refs[app] | ||
| if (this.panels[app].mounted) { | ||
| continue | ||
| } | ||
|
|
||
| if (element) { | ||
| this.callbacks[app](element[0]) | ||
| Vue.set(this.panels[app], 'mounted', true) | ||
| } else { | ||
| console.error('Failed to register panel in the frontend as no backend data was provided for ' + app) | ||
| } | ||
| } | ||
| }, | ||
| }, | ||
| mounted() { | ||
| setInterval(() => { | ||
| this.timer = new Date() | ||
| }, 30000) | ||
| }, | ||
| methods: { | ||
| register(app, callback) { | ||
| Vue.set(this.callbacks, app, callback) | ||
| }, | ||
| }, | ||
| } | ||
| </script> | ||
|
|
||
| <style lang="scss" scoped> | ||
| #app-dashboard { | ||
| width: 100%; | ||
| } | ||
| h2 { | ||
| text-align: center; | ||
| font-size: 32px; | ||
| line-height: 130%; | ||
| padding: 80px 16px 32px; | ||
| } | ||
|
|
||
| .panels { | ||
| width: 100%; | ||
| display: flex; | ||
| justify-content: center; | ||
| flex-direction: row; | ||
| align-items: flex-start; | ||
| flex-wrap: wrap; | ||
| } | ||
|
|
||
| .panel { | ||
| width: 250px; | ||
| margin: 16px; | ||
|
|
||
| & > a { | ||
| position: sticky; | ||
| top: 50px; | ||
| display: block; | ||
| background: linear-gradient(var(--color-main-background-translucent), var(--color-main-background-translucent) 80%, rgba(255, 255, 255, 0)); | ||
| backdrop-filter: blur(4px); | ||
|
|
||
| h3 { | ||
| margin: 0; | ||
| font-size: 20px; | ||
| font-weight: bold; | ||
| background-size: 32px; | ||
| background-position: 10px 10px; | ||
| padding: 16px 8px 16px 52px; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import Vue from 'vue' | ||
| import App from './App.vue' | ||
|
|
||
| const Dashboard = Vue.extend(App) | ||
| const Instance = new Dashboard({}).$mount('#app') | ||
|
|
||
| window.OCA.Dashboard = { | ||
| register: (app, callback) => Instance.register(app, callback), | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?php | ||
| \OCP\Util::addScript('dashboard', 'dashboard'); | ||
| ?> | ||
| <div id="app"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const path = require('path') | ||
|
|
||
| module.exports = { | ||
| entry: path.join(__dirname, 'src', 'main.js'), | ||
| output: { | ||
| path: path.resolve(__dirname, './js'), | ||
| publicPath: '/js/', | ||
| filename: 'dashboard.js', | ||
| jsonpFunction: 'webpackJsonpDashboard' | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.