using GPW.CORE.Data.DbModels; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace GPW.CORE.ADM.Components.Compo { public partial class UserQrCode { #region Public Properties [Parameter] public bool LinkInt { get; set; } = true; [Parameter] public bool LinkCore { get; set; } = true; [Parameter] public DipendentiModel? RecordDip { get; set; } = null; #endregion Public Properties #region Protected Fields protected string rawCode = ""; #endregion Protected Fields #region Protected Methods protected int idxDipendente { get => RecordDip != null ? RecordDip.IdxDipendente : 0; } protected string getUrlCode(string baseUrl, string authKey) { return $"{baseUrl}jumper?idxDipendente={RecordDip.IdxDipendente}&authKey={authKey}"; } protected override async Task OnAfterRenderAsync(bool firstRender) { if (RecordDip != null) { string baseUrl = LinkInt ? UrlLinkInt : UrlLinkExt; // aggiungo parte core/legacy baseUrl += LinkCore ? UrlLinkCore : UrlLinkLega; //calcolo authKey valida x url --> escaped! string authKeyFix = System.Web.HttpUtility.UrlEncode(RecordDip.AuthKey); string newCode = getUrlCode(baseUrl, authKeyFix); if (rawCode != newCode) { rawCode = newCode; await JSRuntime.InvokeVoidAsync("clearContent", $"qrCodeImg_{RecordDip.IdxDipendente}"); await JSRuntime.InvokeVoidAsync("displayQr", $"qrCodeImg_{RecordDip.IdxDipendente}", rawCode); } } } protected override void OnInitialized() { initConf(); } #endregion Protected Methods #region Private Fields private string UrlLinkExt = ""; private string UrlLinkInt = ""; private string UrlLinkCore = ""; private string UrlLinkLega = ""; #endregion Private Fields #region Private Properties private int _idxDip { get; set; } = 0; [Inject] private IConfiguration Configuration { get; set; } = null!; [Inject] private IJSRuntime JSRuntime { get; set; } = null!; #endregion Private Properties #region Private Methods /// /// init valori da config /// /// private void initConf() { UrlLinkInt = Configuration.GetValue("OptPar:UrlLinkInt") ?? ""; UrlLinkExt = Configuration.GetValue("OptPar:UrlLinkExt") ?? ""; UrlLinkCore = Configuration.GetValue("OptPar:UrlLinkCore") ?? ""; UrlLinkLega = Configuration.GetValue("OptPar:UrlLinkLega") ?? ""; } #endregion Private Methods } }