Skip to content

Commit

Permalink
Working on dynamic resource loading for rv
Browse files Browse the repository at this point in the history
  • Loading branch information
LanceMcCarthy committed May 9, 2024
1 parent a636001 commit 358d2c5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
19 changes: 0 additions & 19 deletions DevCraftAspire.Web/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@

<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>

@* didnt work
<environment include="Development">
<script src="https://localhost:7443/reports/resources/js/telerikReportViewer"></script>
</environment>
<environment include="Staging,Production">
<script src="@(Environment.GetEnvironmentVariable("services__apiservice__https__0"))/reports/resources/js/telerikReportViewer"></script>
</environment>
*@

<style>
#rv1 {
position: relative;
width: 800px;
height: 1200px;
}
</style>

<HeadOutlet />
</head>

Expand Down
40 changes: 22 additions & 18 deletions DevCraftAspire.Web/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
@page "/"
@using Telerik.ReportViewer.Blazor
@using DevCraftAspire.Web.Clients
@inject IJSRuntime JSRuntime
@inject ReportsApiClient ReportsApi

@* Important: prerender the ReportViewer *@
@rendermode InteractiveServer

<environment include="Development">
<script src="https://localhost:7443/reports/resources/js/telerikReportViewer"></script>
</environment>

<environment include="Staging,Production">
<script src="@(Environment.GetEnvironmentVariable("services__apiservice__https__0"))/reports/resources/js/telerikReportViewer"></script>
</environment>

<style>
#rv1 {
position: relative;
width: 800px;
height: 1200px;
}
</style>

@* Important: Viewer's resources are dynamically loaded in OnAfterRenderAsync because I don't know the base URL yet *@
<ReportViewer @ref="ReportViewer1"
ViewerId="rv1"
Expand All @@ -22,25 +35,16 @@

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
Console.WriteLine($"service : {Environment.GetEnvironmentVariable("services__apiservice__https__0")}");

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var rootUrl = "";
var rootUrl = "";
#if DEBUG
rootUrl = "https://localhost:7443";
rootUrl = "https://localhost:7443";
#elif RELEASE
rootUrl = Environment.GetEnvironmentVariable("services__apiservice__https__0");
rootUrl = Environment.GetEnvironmentVariable("services__apiservice__https__0");
#endif
this.ApiServiceUrl = $"{rootUrl}/reports";

await JSRuntime.InvokeVoidAsync("loadScript", $"{rootUrl}/reports");

this.ApiServiceUrl = $"{rootUrl}/reports";
}

await base.OnAfterRenderAsync(firstRender);
await base.OnInitializedAsync();
}
}
3 changes: 2 additions & 1 deletion DevCraftAspire.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"DetailedErrors": true
}

0 comments on commit 358d2c5

Please sign in to comment.