Files
neonoverlordandClaude Fable 5.1 ef00457fa6 1.2.0: footer link like the other cards' "show more"
Two optional app values, link_url and link_text (default "zigbee2mqtt"); with a url the
card ends in a centred muted link that opens in a new tab, and the widget's getUrl() points
there too. No url, no footer. The address stays out of the repo.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-19 20:25:21 -07:00

78 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\ZigbeeCard\Dashboard;
use OCA\ZigbeeCard\AppInfo\Application;
use OCA\ZigbeeCard\Buttons;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IWidget;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Util;
/**
* The dashboard card. It draws nothing itself: it registers the widget id, ships the
* button list as initial state and loads one script + one stylesheet. The JS
* (js/zigbee_card.js) registers the same id with OCA.Dashboard and renders into the
* element the dashboard hands it -- the pattern integration_gotosocial uses, minus Vue.
*/
class ZigbeeWidget implements IWidget, IIconWidget {
public function __construct(
private IL10N $l10n,
private IURLGenerator $url,
private IInitialState $initialState,
private IAppConfig $appConfig,
) {
}
/**
* The footer link, like the other cards' "show more": two optional app values,
* occ config:app:set zigbee_card link_url --value=https://<your zigbee2mqtt frontend>/
* occ config:app:set zigbee_card link_text --value=zigbee2mqtt
* No link_url = no footer.
*/
private function link(): array {
return [
'url' => $this->appConfig->getAppValueString('link_url', ''),
'text' => $this->appConfig->getAppValueString('link_text', 'zigbee2mqtt'),
];
}
public function getId(): string {
return 'zigbee_card';
}
public function getTitle(): string {
return $this->l10n->t('The house');
}
public function getOrder(): int {
return 5;
}
public function getIconClass(): string {
return 'icon-zigbee-card';
}
public function getIconUrl(): string {
return $this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'));
}
/** The card is the whole app; the configured footer link is the only destination. */
public function getUrl(): ?string {
$u = $this->link()['url'];
return $u === '' ? null : $u;
}
public function load(): void {
$this->initialState->provideInitialState('buttons', Buttons::ALL);
$this->initialState->provideInitialState('link', $this->link());
Util::addScript(Application::APP_ID, 'zigbee_card');
Util::addStyle(Application::APP_ID, 'zigbee_card');
}
}