﻿@*
----------------------------------------------------------------------------
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
----------------------------------------------------------------------------
*@

@model AppOwnsData.Models.DashboardEmbedConfig

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Embedded Dashboard</h2>
<div>
    The following dashboard is the first dashboard found in the given group. Please feel free to change the code to match your needs.
</div>

<div id="dashboardContainer"></div>

<div class="infoBox">
    Code is in files:<br />
    1) HomeController.cs<br />
    2) EmbedService.cs<br />
    3) EmbedDashboard.cshtml
</div>

@Html.Partial("AdditionalLinks")

<script>

    // Get a reference to the embedded dashboard HTML element
    const dashboardContainer = $('#dashboardContainer')[0];

    // Read embed application token from Model
    const accessToken = "@Model.EmbedToken.Token";

    // Read embed URL from Model
    const embedUrl = "@Html.Raw(Model.EmbedUrl)";

    // Read dashboard Id from Model
    const embedDashboardId = "@Model.DashboardId";

    // Use the token expiry to regenerate Embed token for seamless end user experience
    // Refer https://aka.ms/RefreshEmbedToken
    const tokenExpiry = "@Model.EmbedToken.Expiration";

    // Get models. models contains enums that can be used.
    const models = window['powerbi-client'].models;

    // Embed configuration used to describe the what and how to embed.
    // This object is used when calling powerbi.embed.
    // This also includes settings and options such as filters.
    // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
    const config = {
        type: 'dashboard',
        tokenType: models.TokenType.Embed,
        accessToken: accessToken,
        embedUrl: embedUrl,
        id: embedDashboardId
    };

    // Embed the dashboard and display it within the div container.
    const dashboard = powerbi.embed(dashboardContainer, config);
</script>