Skip to content
Open
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
119 changes: 119 additions & 0 deletions docroot/statistics/coverage/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php declare(strict_types=1);
require_once __DIR__.'/../../../src/Config.php';
$config = new Config(__DIR__.'/../../../settings/Config.ini');
?>
<!DOCTYPE html>
<html>
<head>
<title>Helioviewer Data Coverage</title>
<style>
body {
padding: 0;
margin: 0;
background-color: #f7f7f7;
}

html.fullscreen {
overflow-y: hidden;
}

.hidden { display: none; }
#main iframe {
border: none;
}

#container {
display: grid;
width: 100%;
grid-template-columns: repeat(2);
grid-auto-rows: 1fr;
}

#container .dashboard {
min-height: 700px;
}

#container .dashboard.fullscreen {
height: 100vh;
}

.dashboard iframe {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<main id="main">
<div id="container"></div>
<div id="error" class="error hidden">
Something went wrong... Please try again later.
</div>
</main>

<script src="https://unpkg.com/@superset-ui/embedded-sdk"></script>
<!--<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-1.6.0.nomodule.min.js"></script>-->
<script src="js/guest_token.js"></script>
<script src="js/query.js"></script>

<script>
(async function () {
try {
// Acquire a guest token
const token = await fetchGuestToken("<?=HV_SUPERSET_SIDECAR_URL?>/guest_token.php");
const chart = (new URLSearchParams(window.location.search)).get("chart") ?? "Helioviewer Data Coverage";
// Find the main data coverage dashboard
const queryResult = await findDashboards("<?=HV_SUPERSET_URL?>", token, {
columns: ["id"],
filters: [
{
col: "dashboard_title",
opr: "title_or_slug",
value: chart
}
]
})
if (queryResult.count == 0) {
throw `No ${chart} dashboard available.`
} else {
const responses = await Promise.all(queryResult.result.map((dashboard) => getDashboardUUID("<?=HV_SUPERSET_URL?>", token, dashboard.id)));
const uuids = responses.map((response) => response.result.uuid);
const dashboardToken = await fetchGuestToken("<?=HV_SUPERSET_SIDECAR_URL?>/guest_token.php", {"dashboard_id": uuids});
const makeFullscreen = uuids.length == 1;
uuids.map((uuid) => renderDashboard(uuid, dashboardToken, makeFullscreen));
if (makeFullscreen) {
document.body.parentElement.classList.add('fullscreen');
}
}
} catch (e) {
console.error(e);
const error = document.getElementById('error');
error.textContent = e.toString();
error.classList.remove('hidden');
}
})()

function renderDashboard(uuid, token, isFullscreen) {
// Get a guest token for this dashboard
const container = document.getElementById('container');
const dashboard = document.createElement('div');
dashboard.classList.add('dashboard');
if (isFullscreen) {
dashboard.classList.add('fullscreen');
}
container.appendChild(dashboard);
supersetEmbeddedSdk.embedDashboard({
id: uuid,
supersetDomain: "<?=HV_SUPERSET_URL?>",
mountPoint: dashboard,
fetchGuestToken: () => token,
dashboardUiConfig: {
hideTitle: true,
hideChartControls: false,
hideTab: false
},
});
}
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions docroot/statistics/coverage/js/guest_token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Fetches a guest token from the specified URL.
*
* @async
* @param {string} url - The URL endpoint to fetch the guest token from
* @param {string} body - The JSON string body to send in the POST request
* @returns {Promise<string>} A promise that resolves to the guest token
* @throws {Error} If the fetch request fails or the response is invalid
*/
async function fetchGuestToken(url, body) {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body ?? "")
});
const data = await response.json();
return data.token;
}
34 changes: 34 additions & 0 deletions docroot/statistics/coverage/js/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Finds dashboards from the Superset API using a query filter.
*
* @async
* @param {string} url - The base URL of the Superset instance
* @param {string} token - The guest token for authentication
* @param {Object} query - The query object to filter dashboards
* @returns {Promise<Object>} A promise that resolves to the dashboard data
* @throws {Error} If the fetch request fails or the response is invalid
*/
async function findDashboards(url, token, query) {
const queryString = encodeURIComponent(JSON.stringify(query));
const response = await fetch(`${url}/api/v1/dashboard/?q=${queryString}`, {
method: 'GET',
headers: headers(token)
});
const data = await response.json();
return data;
}

async function getDashboardUUID(url, token, id) {
const response = await fetch(`${url}/api/v1/dashboard/${id}/embedded`, {
method: 'GET',
headers: headers(token)
});
return await response.json();
}

function headers(token) {
return {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
};
}
28 changes: 1 addition & 27 deletions docroot/status/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@
"RHESSI" => $PROVIDERS['RHESSI']
);

const COVERAGE = array (
"AIA" => "SDO_coverage.html",
"HMI" => "SDO_coverage.html",
"EIT" => "SOHO_coverage.html",
"LASCO" => "SOHO_coverage.html",
"COSMO" => "MLSO_coverage.html",
"EUI" => "SOLO_coverage.html",
"COR1-A" => "STEREO_A_coverage.html",
"COR2-A" => "STEREO_A_coverage.html",
"EUVI-A" => "STEREO_A_coverage.html",
"COR1-B" => "STEREO_B_coverage.html",
"COR2-B" => "STEREO_B_coverage.html",
"EUVI-B" => "STEREO_B_coverage.html",
"IRIS" => "IRIS_coverage.html",
"SWAP" => "PROBA2_coverage.html",
"SXT" => "Yohkoh_coverage.html",
"XRT" => "Hinode_coverage.html",
"RHESSI" => "RHESSI_coverage.html"
);

const TABLE_ROW_TEMPLATE = "<tr class='%s'><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td align='center'>%s</td></tr>";

function formatDate(?DateTime $date) {
Expand Down Expand Up @@ -102,13 +82,7 @@ function genRobLink($name, $url) {
}

function genCoverageLink($source) {
$instrument = explode(" ", $source)[0];
if (array_key_exists($instrument, COVERAGE)) {
$coverage_page = "/statistics/bokeh/coverages/" . COVERAGE[$instrument];
} else {
$coverage_page = "#";
}
return "<a href=".$coverage_page.">$source</a>";
return "<a href=\"/statistics/coverage/\">$source</a>";
}

function safe_max($arr) {
Expand Down
4 changes: 4 additions & 0 deletions settings/Config.Example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,7 @@ http_export = ''
# If running the coordinator locally, then change this to
# http://localhost:port
coordinator_url = 'http://coordinator'

[superset]
superset_url = 'http://localhost:8088'
superset_sidecar_url = 'http://localhost:8087'
Loading