-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intègre le dashboard Metabase à la page stats
- Loading branch information
1 parent
822d340
commit 5ba0ee2
Showing
12 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @ts-check | ||
|
||
import { querySelectorOrError } from "./util"; | ||
|
||
customElements.define('d-responsive-iframe', class extends HTMLElement { | ||
connectedCallback() { | ||
/** @type {HTMLIFrameElement} */ | ||
const iframe = querySelectorOrError(this, 'iframe'); | ||
|
||
// Inspiré de : https://towardsdev.com/the-most-elegant-way-to-implement-dynamic-size-iframe-2-0-319b974f1048 | ||
|
||
const resizeObserver = new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
window.parent.postMessage({ | ||
type: 'resize', | ||
width: entry.borderBoxSize[0].inlineSize, | ||
}); | ||
} | ||
}); | ||
|
||
resizeObserver.observe(document.body); | ||
|
||
const maxWidth = +(this.getAttribute('maxWidth') || iframe.clientWidth); | ||
const extraPadding = +(this.getAttribute('extraPadding') || '0'); // px | ||
|
||
window.addEventListener('message', function (event) { | ||
// Replace the localhost origin with either env variable or an actual domain | ||
|
||
if (event.origin === 'http://localhost:8000') { | ||
if (event.data.type === 'resize') { | ||
const windowWidth = event.data.width; | ||
const newWidth = Math.min(windowWidth - extraPadding, maxWidth); | ||
try { | ||
iframe.style.width = `${newWidth}px`; | ||
} | ||
catch { } | ||
} | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Adapter; | ||
|
||
use Firebase\JWT\JWT; | ||
|
||
final class JWTEncoder | ||
{ | ||
public function encode(array $payload, string $secretKey): string | ||
{ | ||
return JWT::encode($payload, $secretKey, 'HS256'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Adapter; | ||
|
||
use App\Application\DateUtilsInterface; | ||
|
||
final class MetabaseEmbedFactory | ||
{ | ||
private const DASHBOARD_ID_STATS = 2; | ||
|
||
public function __construct( | ||
private string $metabaseSiteUrl, | ||
private string $metabaseSecretKey, | ||
private JWTEncoder $jwtEncoder, | ||
private DateUtilsInterface $dateUtils, | ||
) { | ||
} | ||
|
||
public function makeDashboardUrl(): string | ||
{ | ||
// Ce code a été adapté du code d'intégration fourni par Metabase dans les options de partage d'une visualisation. | ||
// Plus d'infos sur le "static embedding" : https://www.metabase.com/docs/latest/embedding/static-embedding | ||
|
||
$payload = [ | ||
'resource' => ['dashboard' => self::DASHBOARD_ID_STATS], | ||
'params' => (object) [], // sic: L'array doit être converti en 'object', voir : https://github.com/metabase/metabase/issues/6487#issuecomment-1535278810 | ||
'exp' => round($this->dateUtils->getNow()->getTimestamp()) + 10 * 60, // 10 minute expiration | ||
]; | ||
|
||
$token = $this->jwtEncoder->encode($payload, $this->metabaseSecretKey); | ||
|
||
return \sprintf('%s/embed/dashboard/%s#bordered=true&titled=true', $this->metabaseSiteUrl, $token); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters