-
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.
revamped php sample with embedconfig file
- Loading branch information
anuabarnab4
committed
Jan 7, 2025
1 parent
c8ef513
commit 55f6fe4
Showing
3 changed files
with
94 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,52 @@ | ||
|
||
<?php | ||
// ServerURL, DashboardPath and AuthorizeSeverURL to embed widget | ||
$serverUrl = "http://localhost:53623/bi/site/site1"; | ||
$dashboardId ="42d69d1a-dcd8-41b0-93a4-d4cdd2c53241"; | ||
$authorizeServerUrl = "http://localhost:3000/rest/authorizeserver.php"; | ||
$apiHost = "http://localhost:3000"; | ||
$authorizeServerUrl = $apiHost . "/rest/authorizeserver.php"; | ||
$getDataUrl = $apiHost . "/rest/getData.php"; | ||
?> | ||
|
||
<html> | ||
|
||
<head> | ||
<script type="text/javascript" src="https://cdn.boldbi.com/embedded-sdk/latest/boldbi-embed.js"></script> | ||
<script type="text/javascript" src="https://cdn.boldbi.com/embedded-sdk/latest/boldbi-embed.js"></script> | ||
</head> | ||
<body onload="embedSample();"> | ||
<div id="dashboard"></div> | ||
|
||
<body onload="Init();"> | ||
<div id="dashboard"></div> | ||
<script> | ||
function embedSample() { | ||
var dashboardemb = BoldBI.create({ | ||
serverUrl: '<?php echo $serverUrl;?>', | ||
dashboardId: '<?php echo $dashboardId;?>', | ||
embedContainerId: "dashboard",// This should be the container id where you want to embed the dashboard | ||
embedType: BoldBI.EmbedType.Component, | ||
environment: BoldBI.Environment.Enterprise, | ||
height: "700px", | ||
width: "1500px", | ||
async function Init() { | ||
try { | ||
// Fetch data from the PHP backend | ||
const response = await fetch('<?php echo $getDataUrl; ?>'); | ||
console.log("Response ", response); | ||
// Check if the response is okay | ||
if (!response.ok) { | ||
throw new Error("Network response was not ok"); | ||
} | ||
|
||
// Parse the JSON data | ||
const data = await response.json(); | ||
// Call the function to render the dashboard with the fetched data | ||
renderDashboard(data); | ||
} catch (error) { | ||
console.error("Error fetching the embed configuration:", error); | ||
} | ||
} | ||
|
||
function renderDashboard(data) { | ||
this.dashboard = BoldBI.create({ | ||
serverUrl: data.ServerUrl + "/" + data.SiteIdentifier, | ||
dashboardId: data.DashboardId, | ||
embedContainerId: "dashboard", | ||
width: "100%", | ||
height: window.innerHeight + 'px', | ||
authorizationServer: { | ||
url: '<?php echo $authorizeServerUrl;?>' | ||
url: '<?php echo $authorizeServerUrl; ?>' | ||
} | ||
}); | ||
dashboardemb.loadDashboard(); | ||
|
||
this.dashboard.loadDashboard(); | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
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,38 @@ | ||
<?php | ||
header("Access-Control-Allow-Origin: *"); | ||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); | ||
header("Access-Control-Allow-Headers: Content-Type, Authorization"); | ||
|
||
// Rest of your PHP script | ||
header("Content-Type: application/json"); | ||
|
||
// Read the JSON file | ||
$data = file_get_contents('embedConfig.json'); | ||
|
||
if ($data === false) { | ||
http_response_code(500); // Internal Server Error | ||
echo "embedConfig.json file not found!"; | ||
exit(); | ||
} | ||
|
||
// Parse the JSON data | ||
$dataArray = json_decode($data, true); | ||
|
||
if (json_last_error() !== JSON_ERROR_NONE) { | ||
http_response_code(500); // Internal Server Error | ||
echo json_encode(array("error" => "Could not parse the JSON data.")); | ||
exit(); | ||
} | ||
|
||
// Extract specific values | ||
$clientEmbedConfigData = array( | ||
"DashboardId" => $dataArray["DashboardId"], | ||
"ServerUrl" => $dataArray["ServerUrl"], | ||
"SiteIdentifier" => $dataArray["SiteIdentifier"], | ||
"EmbedType" => $dataArray["EmbedType"], | ||
"Environment" => $dataArray["Environment"], | ||
); | ||
|
||
// Return the specific values of parsed data as JSON response | ||
echo json_encode($clientEmbedConfigData, JSON_PRETTY_PRINT); | ||
?> |