|
| 1 | +<?php |
| 2 | +require_once '../../src/Config.php'; |
| 3 | +$config = new Config('../../settings/Config.ini'); |
| 4 | +?> |
| 5 | +<!DOCTYPE html> |
| 6 | +<html lang="en"> |
| 7 | +<head> |
| 8 | + <meta charset="utf-8" /> |
| 9 | + <title>Helioviewer.org - Data Coverage Statistics</title> |
| 10 | + <style> |
| 11 | + html, body { |
| 12 | + height: 100%; |
| 13 | + margin: 0; |
| 14 | + padding: 0; |
| 15 | + background-color: #1a1a1a; |
| 16 | + color: #e0e0e0; |
| 17 | + } |
| 18 | + #main { |
| 19 | + display: flex; |
| 20 | + flex-direction: column; |
| 21 | + height: 100vh; |
| 22 | + background-color: #1a1a1a; |
| 23 | + } |
| 24 | + #header { |
| 25 | + flex-shrink: 0; |
| 26 | + background-color: #2a2a2a; |
| 27 | + padding: 5px 10px; |
| 28 | + display: flex; |
| 29 | + align-items: center; |
| 30 | + gap: 10px; |
| 31 | + } |
| 32 | + #header img { |
| 33 | + height: 30px; |
| 34 | + width: auto; |
| 35 | + } |
| 36 | + #headerText { |
| 37 | + color: #e0e0e0; |
| 38 | + font-size: 14px; |
| 39 | + margin: 0; |
| 40 | + } |
| 41 | + #dashboard-container { |
| 42 | + flex: 1; |
| 43 | + width: 100vw; |
| 44 | + min-height: 0; |
| 45 | + margin: 0; |
| 46 | + padding: 0; |
| 47 | + } |
| 48 | + #dashboard-container iframe { |
| 49 | + width: 100%; |
| 50 | + height: 100%; |
| 51 | + border: none; |
| 52 | + display: block; |
| 53 | + } |
| 54 | + #error-message { |
| 55 | + display: none; |
| 56 | + padding: 10px; |
| 57 | + margin: 10px; |
| 58 | + background-color: #5c1c1c; |
| 59 | + color: #ff8a80; |
| 60 | + border-radius: 4px; |
| 61 | + } |
| 62 | + #loading-message { |
| 63 | + padding: 10px; |
| 64 | + margin: 10px; |
| 65 | + text-align: center; |
| 66 | + font-size: 14px; |
| 67 | + color: #e0e0e0; |
| 68 | + } |
| 69 | + </style> |
| 70 | +</head> |
| 71 | + |
| 72 | +<body> |
| 73 | + <div id="main"> |
| 74 | + <div id="header"> |
| 75 | + <img src="../resources/images/logos/hvlogo1s_transparent_logo.png" alt="Helioviewer logo" /> |
| 76 | + <div id='headerText'>The Helioviewer Project - Data Coverage</div> |
| 77 | + </div> |
| 78 | + |
| 79 | + <div id="loading-message">Loading dashboard...</div> |
| 80 | + <div id="error-message"></div> |
| 81 | + <div id="dashboard-container"></div> |
| 82 | + </div> |
| 83 | + |
| 84 | + <script src="https://unpkg.com/@superset-ui/embedded-sdk"></script> |
| 85 | + <script type="text/javascript"> |
| 86 | + const DASHBOARD_ID = '<?= HV_SUPERSET_COVERAGE_DASHBOARD_ID ?>'; |
| 87 | + const GUEST_TOKEN_URL = '<?= HV_SUPERSET_SIDECAR_URL ?>/guest_token.php'; |
| 88 | + const SUPERSET_URL = '<?= HV_SUPERSET_URL ?>'; |
| 89 | + |
| 90 | + async function fetchGuestToken() { |
| 91 | + try { |
| 92 | + const response = await fetch(GUEST_TOKEN_URL, { |
| 93 | + method: 'POST', |
| 94 | + headers: { |
| 95 | + 'Content-Type': 'application/json', |
| 96 | + }, |
| 97 | + body: JSON.stringify({ |
| 98 | + dashboard_id: DASHBOARD_ID |
| 99 | + }) |
| 100 | + }); |
| 101 | + |
| 102 | + if (!response.ok) { |
| 103 | + throw new Error(`HTTP error! status: ${response.status}`); |
| 104 | + } |
| 105 | + |
| 106 | + const data = await response.json(); |
| 107 | + |
| 108 | + if (!data.success || !data.token) { |
| 109 | + throw new Error('Failed to retrieve guest token from response'); |
| 110 | + } |
| 111 | + |
| 112 | + return data.token; |
| 113 | + } catch (error) { |
| 114 | + console.error('Error fetching guest token:', error); |
| 115 | + throw error; |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + async function embedDashboard() { |
| 120 | + try { |
| 121 | + const guestToken = await fetchGuestToken(); |
| 122 | + |
| 123 | + // Hide loading message |
| 124 | + document.getElementById('loading-message').style.display = 'none'; |
| 125 | + |
| 126 | + // Embed the dashboard |
| 127 | + supersetEmbeddedSdk.embedDashboard({ |
| 128 | + id: DASHBOARD_ID, |
| 129 | + supersetDomain: SUPERSET_URL, |
| 130 | + mountPoint: document.getElementById('dashboard-container'), |
| 131 | + fetchGuestToken: () => guestToken, |
| 132 | + dashboardUiConfig: { |
| 133 | + hideTitle: true, |
| 134 | + hideChartControls: false, |
| 135 | + hideTab: false, |
| 136 | + }, |
| 137 | + }); |
| 138 | + } catch (error) { |
| 139 | + console.error('Error embedding dashboard:', error); |
| 140 | + document.getElementById('loading-message').style.display = 'none'; |
| 141 | + const errorDiv = document.getElementById('error-message'); |
| 142 | + errorDiv.style.display = 'block'; |
| 143 | + errorDiv.textContent = 'Failed to load dashboard: ' + error.message; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + // Initialize dashboard when page loads |
| 148 | + window.addEventListener('load', embedDashboard); |
| 149 | + </script> |
| 150 | +</body> |
| 151 | +</html> |
0 commit comments