Skip to content

Commit 55a154e

Browse files
committed
draft first dashboard
1 parent 7dfa189 commit 55a154e

File tree

8 files changed

+156
-2
lines changed

8 files changed

+156
-2
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ appstore:
172172

173173
# on macOS there is no option "--parents" for the "cp" command
174174
mkdir -p $(appstore_sign_dir)/$(app_name)/js/build $(appstore_sign_dir)/$(app_name)/js/admin
175-
cp js/build/app.min.js $(appstore_sign_dir)/$(app_name)/js/build
176-
cp js/build/news-admin-settings.js* $(appstore_sign_dir)/$(app_name)/js/build
175+
cp js/build/* $(appstore_sign_dir)/$(app_name)/js/build
177176

178177
# export the key and cert to a file
179178
@if [ ! -f $(cert_dir)/$(app_name).key ] || [ ! -f $(cert_dir)/$(app_name).crt ]; then \

css/dashboard.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.icon-newsdashboard {
2+
background-image: url('../img/app-dark.svg');
3+
filter: var(--background-invert-if-dark);
4+
}
5+
6+
.widget-list li {
7+
list-style-type: disc;
8+
}
9+
10+
#app-dashboard .panels .panel--header h2 {
11+
display: flex;
12+
}

lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OCA\News\Search\FeedSearchProvider;
2525
use OCA\News\Search\FolderSearchProvider;
2626
use OCA\News\Search\ItemSearchProvider;
27+
use OCA\News\Dashboard\ItemWidget;
2728

2829
use OCP\AppFramework\Bootstrap\IBootContext;
2930
use OCP\AppFramework\Bootstrap\IBootstrap;
@@ -85,6 +86,7 @@ public function register(IRegistrationContext $context): void
8586
$context->registerSearchProvider(FeedSearchProvider::class);
8687
$context->registerSearchProvider(ItemSearchProvider::class);
8788

89+
$context->registerDashboardWidget(ItemWidget::class);
8890

8991
$context->registerEventListener(BeforeUserDeletedEvent::class, UserDeleteHook::class);
9092

lib/Dashboard/ItemWidget.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace OCA\News\Dashboard;
4+
5+
use OCA\News\Service\ItemServiceV2;
6+
use OCP\AppFramework\Services\IInitialState;
7+
use OCP\Dashboard\IAPIWidget;
8+
use OCP\IL10N;
9+
use OCP\IURLGenerator;
10+
use OCP\Dashboard\Model\WidgetItem;
11+
12+
use Psr\Log\LoggerInterface;
13+
14+
use OCA\News\AppInfo\Application;
15+
use OCA\News\Db\ListType;
16+
use OCP\Util;
17+
18+
class ItemWidget implements IAPIWidget {
19+
20+
21+
private $l10n;
22+
private $itemService;
23+
private $initialStateService;
24+
private $userId;
25+
private $urlGenerator;
26+
private $logger;
27+
28+
public function __construct(IL10N $l10n,
29+
IURLGenerator $urlGenerator,
30+
ItemServiceV2 $itemService,
31+
IInitialState $initialStateService,
32+
LoggerInterface $loggerInterface,
33+
?string $userId) {
34+
$this->l10n = $l10n;
35+
$this->itemService = $itemService;
36+
$this->initialStateService = $initialStateService;
37+
$this->userId = $userId;
38+
$this->urlGenerator = $urlGenerator;
39+
$this->logger = $loggerInterface;
40+
}
41+
42+
public function getId(): string {
43+
return 'news-widget';
44+
}
45+
46+
public function getTitle(): string {
47+
$this->logger->debug("Requested title");
48+
return $this->l10n->t('News widget');
49+
}
50+
51+
public function getOrder(): int {
52+
$this->logger->debug("Requested order");
53+
return 20;
54+
}
55+
56+
public function getIconClass(): string {
57+
return 'icon-newsdashboard'; // TODO
58+
$this->logger->debug("Requested icon");
59+
}
60+
61+
public function getUrl(): ?string {
62+
return $this->urlGenerator->linkToRoute('news.page.index');
63+
$this->logger->debug("Requested url");
64+
}
65+
66+
public function load(): void {
67+
$this->logger->debug("Requested load with user: " . $this->userId);
68+
if ($this->userId !== null) {
69+
$items = $this->getItems($this->userId);
70+
$this->initialStateService->provideInitialState('dashboard-widget-items', $items);
71+
}
72+
73+
Util::addScript(Application::NAME, 'build/' . Application::NAME . '-dashboard-items');
74+
Util::addStyle(Application::NAME, 'dashboard');
75+
}
76+
77+
public function getItems(string $userId, ?string $since = null, int $limit = 7): array {
78+
$offset = (int) ($since ?? 0);
79+
$items = $this->itemService->findAllWithFilters($userId, ListType::ALL_ITEMS ,$limit, $offset, false);
80+
81+
return $items;
82+
}
83+
}

src/components/ItemDashboard.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template>
2+
<NcDashboardWidget :items="items">
3+
4+
</NcDashboardWidget>
5+
</template>
6+
7+
<script>
8+
import NcDashboardWidget from '@nextcloud/vue/dist/Components/NcDashboardWidget.js'
9+
import { loadState } from '@nextcloud/initial-state'
10+
11+
const newsItems = loadState('news', 'dashboard-widget-items')
12+
13+
console.log(newsItems)
14+
15+
export default {
16+
name: 'MyDashboardWidget',
17+
components: {
18+
NcDashboardWidget,
19+
},
20+
props: [],
21+
data() {
22+
return {
23+
newsItems: newsItems
24+
}
25+
},
26+
27+
computed: {
28+
items() {
29+
return this.newsItems.map((g) => {
30+
return {
31+
id: g.id,
32+
mainText: g.title,
33+
subText: g.intro,
34+
}
35+
})
36+
}
37+
}
38+
}
39+
</script>

src/dashboard-items.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Vue from 'vue'
2+
import MyDashboardWidget from './components/ItemDashboard.vue'
3+
4+
document.addEventListener('DOMContentLoaded', () => {
5+
console.log("I'm alive")
6+
OCA.Dashboard.register('news-widget', (el) => {
7+
console.log("Dashboard registered")
8+
const View = Vue.extend(MyDashboardWidget)
9+
new View().$mount(el)
10+
})
11+
})

src/vueBootstrap.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Vue from 'vue'
2+
import { translate, translatePlural } from '@nextcloud/l10n'
3+
4+
Vue.prototype.t = translate
5+
Vue.prototype.n = translatePlural
6+
Vue.prototype.OC = window.OC
7+
Vue.prototype.OCA = window.OCA

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const webpackConfig = require('@nextcloud/webpack-vue-config')
66

77
webpackConfig.entry = {
88
'admin-settings': path.join(__dirname, 'src', 'main-admin.js'),
9+
'dashboard-items': path.join(__dirname, 'src', 'dashboard-items.js'),
910
}
1011
webpackConfig.output.path = path.resolve('./js/build/')
1112
webpackConfig.output.publicPath = path.join('/apps/', process.env.npm_package_name, '/js/build/')

0 commit comments

Comments
 (0)