From 59ca1a93c526f963285c2cbc1afc888115c1a691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Scho=CC=88ps?= Date: Tue, 21 Dec 2021 13:06:44 +0100 Subject: [PATCH 1/2] Add Metabase's additional parameters --- README.md | 3 +++ src/MetabaseComponent.php | 25 ++++++++++++++++++++++++- src/MetabaseService.php | 17 ++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ca24f24..032a94f 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ Metabase secret key can be found in metabase settings page (only accessible by a @php($params = ['category' => 'php']) // BEWARE of the colon in ":params" (not "param") because we are passing array variable directly to the component + + + ``` ## Common Problems diff --git a/src/MetabaseComponent.php b/src/MetabaseComponent.php index f79fb5f..f836db4 100644 --- a/src/MetabaseComponent.php +++ b/src/MetabaseComponent.php @@ -10,6 +10,12 @@ class MetabaseComponent extends Component public ?int $question; + public bool $bordered; + + public bool $titled; + + public ?string $theme; + /** * @var string[] */ @@ -22,11 +28,14 @@ class MetabaseComponent extends Component * @param int|null $question * @param array $params */ - public function __construct(?int $dashboard = null, ?int $question = null, array $params = []) + public function __construct(?int $dashboard = null, ?int $question = null, array $params = [], $bordered = true, $titled = false, $theme = null) { $this->dashboard = $dashboard; $this->question = $question; $this->params = $params; + $this->bordered = $bordered; + $this->titled = $titled; + $this->theme = $theme; } /** @@ -38,7 +47,21 @@ public function render() { $metabase = app(MetabaseService::class); $metabase->setParams($this->params); + $metabase->setAdditionalParams($this->getAdditionalParams()); $iframeUrl = $metabase->generateEmbedUrl((int) $this->dashboard, (int) $this->question); return view('metabase::iframe', compact('iframeUrl')); } + + + private function getAdditionalParams() + { + $additionalParameters['bordered'] = $this->bordered; + $additionalParameters['titled'] = $this->titled; + + if($this->theme) { + $additionalParameters['theme'] = $this->theme; + } + + return $additionalParameters; + } } diff --git a/src/MetabaseService.php b/src/MetabaseService.php index 1f1dd06..b8d9ff0 100644 --- a/src/MetabaseService.php +++ b/src/MetabaseService.php @@ -14,6 +14,11 @@ class MetabaseService */ private $params; + /** + * @var array @params + */ + private $additionalParams; + /** * @param array $params * @@ -28,6 +33,16 @@ public function setParams(array $params): void $this->params = $params; } + /** + * @param array $params + * + * @return void + */ + public function setAdditionalParams(array $params): void + { + $this->additionalParams = $params; + } + private string $type = 'dashboard'; /** @@ -62,7 +77,7 @@ public function generateEmbedUrl(?int $dashboard, ?int $question): string ->toString(); return sprintf( - '%s/embed/%s/%s#bordered=true&titled=false', + '%s/embed/%s/%s#' . http_build_query($this->additionalParams), config('services.metabase.url'), $this->type, $token From 2f4d5e945fa105a4b2e15d3ae3fe740939497547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Scho=CC=88ps?= Date: Wed, 22 Dec 2021 10:55:16 +0100 Subject: [PATCH 2/2] Changed default value of parameter bordered --- src/MetabaseComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MetabaseComponent.php b/src/MetabaseComponent.php index f836db4..b9427ea 100644 --- a/src/MetabaseComponent.php +++ b/src/MetabaseComponent.php @@ -28,7 +28,7 @@ class MetabaseComponent extends Component * @param int|null $question * @param array $params */ - public function __construct(?int $dashboard = null, ?int $question = null, array $params = [], $bordered = true, $titled = false, $theme = null) + public function __construct(?int $dashboard = null, ?int $question = null, array $params = [], $bordered = false, $titled = false, $theme = null) { $this->dashboard = $dashboard; $this->question = $question;