95 lines
2.3 KiB
C#
95 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.JSInterop;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Xml.Linq;
|
|
using ZXingBlazor.Components;
|
|
|
|
namespace EgwCoreLib.Razor
|
|
{
|
|
public partial class PdfDisplay
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// URL del documento da mostrare
|
|
/// </summary>
|
|
[Parameter]
|
|
public string PdfUrl { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Larghezza desiderata
|
|
/// </summary>
|
|
[Parameter]
|
|
public string Width { get; set; } = "100%";
|
|
|
|
|
|
/// <summary>
|
|
/// Elenco altezze ammesse
|
|
/// </summary>
|
|
[Parameter]
|
|
public Dictionary<string, string> HeightList
|
|
{
|
|
get => hList;
|
|
set
|
|
{
|
|
if (hList != value && value.Count > 0)
|
|
{
|
|
hList = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private Dictionary<string, string> hList { get; set; } = new Dictionary<string, string>() { { "200", "200px" }, { "400", "400px" }, { "600", "600px" } };
|
|
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
// in base a quanti ne ho preso ultima o in mezzo...
|
|
int numSkip = HeightList.Count() > 3 ? 2 : 0;
|
|
|
|
Height = HeightList.Skip(numSkip).FirstOrDefault().Value;
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
try
|
|
{
|
|
if (!firstRender) return;
|
|
|
|
module = await JS.InvokeAsync<IJSObjectReference>("import", "./_content/EgwCoreLib.Razor/PdfDisplay.razor.js");
|
|
isMobile = await JS.InvokeAsync<bool>("isDevice");
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private IJSObjectReference? module;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string Height { get; set; } = "600px";
|
|
|
|
/// <summary>
|
|
/// Boolean Mobile vs Desktop
|
|
/// </summary>
|
|
private bool isMobile { get; set; }
|
|
|
|
[Inject]
|
|
[NotNull]
|
|
private IJSRuntime? JS { get; set; }
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |