mirror of https://github.com/nextcloud/bookmarks
Implement dashboard widget
This commit is contained in:
parent
c1ec2e4b8b
commit
fd18cfe947
|
@ -9,6 +9,7 @@
|
|||
namespace OCA\Bookmarks\AppInfo;
|
||||
|
||||
use OCA\Bookmarks\Activity\ActivityPublisher;
|
||||
use OCA\Bookmarks\Dashboard\Widget;
|
||||
use OCA\Bookmarks\Events\BeforeDeleteEvent;
|
||||
use OCA\Bookmarks\Events\CreateEvent;
|
||||
use OCA\Bookmarks\Events\MoveEvent;
|
||||
|
@ -50,6 +51,7 @@ class Application extends App implements IBootstrap {
|
|||
});
|
||||
|
||||
$context->registerSearchProvider(Provider::class);
|
||||
$context->registerDashboardWidget(Widget::class);
|
||||
|
||||
$context->registerEventListener(CreateEvent::class, HashManager::class);
|
||||
$context->registerEventListener(UpdateEvent::class, HashManager::class);
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) 2020. The Nextcloud Bookmarks contributors.
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
|
||||
*/
|
||||
|
||||
namespace OCA\Bookmarks\Dashboard;
|
||||
|
||||
use OCP\Dashboard\IWidget;
|
||||
use OCP\IL10N;
|
||||
use OCP\Util;
|
||||
|
||||
class Widget implements IWidget {
|
||||
/**
|
||||
* @var IL10N
|
||||
*/
|
||||
private $l;
|
||||
/**
|
||||
* @var \OCP\IURLGenerator
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* Widget constructor.
|
||||
*
|
||||
* @param IL10N $l
|
||||
* @param \OCP\IURLGenerator $url
|
||||
*/
|
||||
public function __construct(IL10N $l, \OCP\IURLGenerator $url) {
|
||||
$this->l = $l;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getId(): string {
|
||||
return 'bookmarks.recent';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle(): string {
|
||||
return $this->l->t('Recent Bookmarks');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getOrder(): int {
|
||||
return 50;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIconClass(): string {
|
||||
return 'icon-favorite';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUrl(): ?string {
|
||||
return $this->url->linkToRouteAbsolute('bookmarks.web_view.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function load(): void {
|
||||
Util::addScript('bookmarks', 'bookmarks-dashboard');
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "bookmarks",
|
||||
"version": "3.4.0",
|
||||
"version": "3.4.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -2628,6 +2628,16 @@
|
|||
"vue2-datepicker": "^3.6.2"
|
||||
}
|
||||
},
|
||||
"@nextcloud/vue-dashboard": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@nextcloud/vue-dashboard/-/vue-dashboard-1.0.1.tgz",
|
||||
"integrity": "sha512-QKOf0qm4UYobuC3djLYwICSuj29H6xnm24IHetc0AMsrfhwPNN1/CC5IWEl1uKCCvwI0NA02HXCVFLtUErlgyg==",
|
||||
"requires": {
|
||||
"@nextcloud/vue": "^2.3.0",
|
||||
"core-js": "^3.6.4",
|
||||
"vue": "^2.6.11"
|
||||
}
|
||||
},
|
||||
"@nextcloud/webpack-vue-config": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@nextcloud/webpack-vue-config/-/webpack-vue-config-1.4.1.tgz",
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
"@nextcloud/initial-state": "^1.1.2",
|
||||
"@nextcloud/router": "^1.2.0",
|
||||
"@nextcloud/vue": "^2.6.5",
|
||||
"@nextcloud/vue-dashboard": "^1.0.1",
|
||||
"copy-text-to-clipboard": "^2.2.0",
|
||||
"humanize-duration": "^3.23.1",
|
||||
"style-loader": "^1.2.1",
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<!--
|
||||
- Copyright (c) 2020. The Nextcloud Bookmarks contributors.
|
||||
-
|
||||
- This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
|
||||
-->
|
||||
|
||||
<template>
|
||||
<DashboardWidget :items="items" :loading="loading">
|
||||
<template v-slot:empty-content>
|
||||
{{ t('bookmarks', 'No bookmarks here') }}
|
||||
</template>
|
||||
</DashboardWidget>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { DashboardWidget } from '@nextcloud/vue-dashboard'
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
import { actions } from '../store'
|
||||
export default {
|
||||
name: 'Dashboard',
|
||||
components: { DashboardWidget },
|
||||
computed: {
|
||||
loading() {
|
||||
return this.$store.state.loading.bookmarks
|
||||
},
|
||||
items() {
|
||||
return this.$store.state.bookmarks.map(bookmark => ({
|
||||
id: bookmark.id,
|
||||
targetUrl: bookmark.url,
|
||||
avatarUrl: generateUrl(`/apps/bookmarks/bookmark/${bookmark.id}/favicon`),
|
||||
mainText: bookmark.title,
|
||||
subText: bookmark.url,
|
||||
}))
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
await this.$store.dispatch(actions.FILTER_BY_RECENT)
|
||||
await this.$store.dispatch(actions.FETCH_PAGE)
|
||||
},
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2020. The Nextcloud Bookmarks contributors.
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
|
||||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
|
||||
import router from './router'
|
||||
import store from './store/'
|
||||
import AppGlobal from './mixins/AppGlobal'
|
||||
import Dashboard from './components/Dashboard.vue'
|
||||
|
||||
Vue.mixin(AppGlobal)
|
||||
Vue.directive('tooltip', Tooltip)
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
OCA.Dashboard.register('bookmarks.recent', (el) => {
|
||||
global.Bookmarks = new Vue({
|
||||
el,
|
||||
store,
|
||||
router,
|
||||
render: h => h(Dashboard),
|
||||
})
|
||||
})
|
||||
})
|
|
@ -7,6 +7,7 @@ const config = {
|
|||
admin: path.join(__dirname, 'src', 'admin.js'),
|
||||
'service-worker': path.join(__dirname, 'src', 'service-worker.js'),
|
||||
flow: path.join(__dirname, 'src', 'flow.js'),
|
||||
dashboard: path.join(__dirname, 'src', 'dashboard.js'),
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
|
|
Loading…
Reference in New Issue