-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21346 from nextcloud/enh/20930/dashboard
Dashboard API
- Loading branch information
Showing
32 changed files
with
743 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 <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/>. | ||
* | ||
*/ | ||
|
||
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 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 <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\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)) { | ||
$this->eventDispatcher->dispatchTyped(new LoadViewer()); | ||
} | ||
|
||
return new TemplateResponse('dashboard', 'index'); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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.