Skip to content
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

chore(dashboard): remove obsolete js widget #6250

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace OCA\Calendar\AppInfo;

use OCA\Calendar\Dashboard\CalendarWidget;
use OCA\Calendar\Dashboard\CalendarWidgetV2;
use OCA\Calendar\Events\BeforeAppointmentBookedEvent;
use OCA\Calendar\Listener\AppointmentBookedListener;
use OCA\Calendar\Listener\CalendarReferenceListener;
Expand All @@ -21,7 +20,6 @@
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\Dashboard\IAPIWidgetV2;
use OCP\User\Events\UserDeletedEvent;
use function method_exists;

Expand All @@ -40,12 +38,7 @@ public function __construct(array $params = []) {
* @inheritDoc
*/
public function register(IRegistrationContext $context): void {
// TODO: drop conditional code when the app is 27.1+
if (interface_exists(IAPIWidgetV2::class)) {
$context->registerDashboardWidget(CalendarWidgetV2::class);
} else {
$context->registerDashboardWidget(CalendarWidget::class);
}
$context->registerDashboardWidget(CalendarWidget::class);

// TODO: drop conditional code when the app is 23+
if (method_exists($context, 'registerProfileLinkAction')) {
Expand Down
48 changes: 33 additions & 15 deletions lib/Dashboard/CalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Calendar\IManager;
use OCP\Dashboard\IAPIWidget;
use OCP\Dashboard\IAPIWidgetV2;
use OCP\Dashboard\IButtonWidget;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IOptionWidget;
use OCP\Dashboard\IReloadableWidget;
use OCP\Dashboard\Model\WidgetButton;
use OCP\Dashboard\Model\WidgetItem;
use OCP\Dashboard\Model\WidgetItems;
use OCP\Dashboard\Model\WidgetOptions;
use OCP\IDateTimeFormatter;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Util;

class CalendarWidget implements IAPIWidget, IButtonWidget, IIconWidget, IOptionWidget {
class CalendarWidget implements IAPIWidget, IAPIWidgetV2, IButtonWidget, IIconWidget, IOptionWidget, IReloadableWidget {
protected IL10N $l10n;
protected IInitialState $initialStateService;
protected JSDataService $dataService;
Expand All @@ -38,13 +40,6 @@ class CalendarWidget implements IAPIWidget, IButtonWidget, IIconWidget, IOptionW

/**
* CalendarWidget constructor.
*
* @param IL10N $l10n
* @param IInitialState $initialStateService
* @param JSDataService $dataService
* @param IDateTimeFormatter $dateTimeFormatter
* @param IURLGenerator $urlGenerator
* @param IManager $calendarManager
*/
public function __construct(IL10N $l10n,
IInitialState $initialStateService,
Expand Down Expand Up @@ -110,12 +105,7 @@ public function getIconUrl(): string {
* @inheritDoc
*/
public function load(): void {
Util::addScript(Application::APP_ID, 'calendar-dashboard');
Util::addStyle(Application::APP_ID, 'dashboard');

$this->initialStateService->provideLazyInitialState('dashboard_data', function () {
return $this->dataService;
});
// No assets need to be loaded anymore as the widget is rendered from the API
}

public function getItems(string $userId, ?string $since = null, int $limit = 7): array {
Expand Down Expand Up @@ -169,6 +159,27 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
return $widgetItems;
}

/**
* @inheritDoc
*/
public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {
$widgetItems = $this->getItems($userId, $since, $limit);

$halfEmptyContentMessage = '';
if (!empty($widgetItems)) {
$startOfTomorrow = $this->timeFactory->getDateTime('tomorrow')->getTimestamp();
if ($widgetItems[0]->getSinceId() >= $startOfTomorrow) {
$halfEmptyContentMessage = $this->l10n->t('No more events today');
}
}

return new WidgetItems(
$widgetItems,
empty($widgetItems) ? $this->l10n->t('No upcoming events') : '',
$halfEmptyContentMessage,
);
}

/**
* @inheritDoc
*/
Expand All @@ -190,4 +201,11 @@ public function getWidgetButtons(string $userId): array {
public function getWidgetOptions(): WidgetOptions {
return new WidgetOptions(true);
}

/**
* @inheritDoc
*/
public function getReloadInterval(): int {
return 600;
}
}
60 changes: 0 additions & 60 deletions lib/Dashboard/CalendarWidgetV2.php

This file was deleted.

Loading
Loading