From a131dd3aa27fe31cb126396d1c606a29266a27be Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Fri, 24 Feb 2023 16:35:32 +0100 Subject: draft first dashboard Signed-off-by: Benjamin Brahmer --- lib/Dashboard/ItemWidget.php | 93 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/Dashboard/ItemWidget.php (limited to 'lib/Dashboard/ItemWidget.php') diff --git a/lib/Dashboard/ItemWidget.php b/lib/Dashboard/ItemWidget.php new file mode 100644 index 000000000..f10e63294 --- /dev/null +++ b/lib/Dashboard/ItemWidget.php @@ -0,0 +1,93 @@ +l10n = $l10n; + $this->itemService = $itemService; + $this->initialStateService = $initialStateService; + $this->userId = $userId; + $this->urlGenerator = $urlGenerator; + $this->logger = $loggerInterface; + } + + public function getId(): string + { + return 'news-item-widget'; + } + + public function getTitle(): string + { + $this->logger->debug("Requested title"); + return $this->l10n->t('News Item widget'); + } + + public function getOrder(): int + { + $this->logger->debug("Requested order"); + return 20; + } + + public function getIconClass(): string + { + return 'icon-newsdashboard'; // TODO + $this->logger->debug("Requested icon"); + } + + public function getUrl(): ?string + { + return $this->urlGenerator->linkToRoute('news.page.index'); + $this->logger->debug("Requested url"); + } + + public function load(): void + { + $this->logger->debug("Requested load with user: " . $this->userId); + if ($this->userId !== null) { + $items = $this->getItems($this->userId); + $this->initialStateService->provideInitialState('dashboard-widget-items', $items); + } + + Util::addScript(Application::NAME, 'build/' . Application::NAME . '-dashboard-items'); + Util::addStyle(Application::NAME, 'dashboard'); + } + + public function getItems(string $userId, ?string $since = null, int $limit = 7): array + { + $offset = (int) ($since ?? 0); + $items = $this->itemService->findAllWithFilters($userId, ListType::ALL_ITEMS, $limit, $offset, false); + + return $items; + } +} \ No newline at end of file -- cgit v1.2.3