using GPW.CORE.Data.DbModels; using GPW.CORE.Data.Services; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace GPW.CORE.WRKLOG.Components.Compo { public partial class RegAtt : IDisposable { #region Public Properties [Parameter] public RegAttivitaModel CurrData { get; set; } = null!; [Parameter] public bool EnableActionMenu { get; set; } = true; [Parameter] public string FontSize { get; set; } = "0.75em"; [Parameter] public int IdxDipSel { get; set; } = 0; [Parameter] public bool IsClipboard { get; set; } = false; [Parameter] public EventCallback ItemCloned { get; set; } [Parameter] public EventCallback ItemSelected { get; set; } [Parameter] public EventCallback ItemUpdated { get; set; } [Parameter] public List ListFasi { get; set; } = null!; [Parameter] public int MidHour { get; set; } = 12; [Parameter] public double Periodo { get; set; } = 1; #endregion Public Properties #region Public Methods public void Dispose() { AppMServ.EA_SearchUpdated -= AppMServ_EA_SearchUpdated; } #endregion Public Methods #region Protected Fields protected bool isSelected = false; #endregion Protected Fields #region Protected Properties [Inject] protected MessageService AppMServ { get; set; } = null!; protected string blockClass { get { string btnClass = ""; bool highlight = false; // recupero search string SearchVal = AppMServ.SearchVal; // calcolo valore highlight if (!string.IsNullOrEmpty(SearchVal)) { highlight = (CurrData.Descrizione.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)); } btnClass = highlight ? "bg-success bg-opacity-25" : "bg-light"; return btnClass; } } protected string btnClass { get { string btnClass = ""; bool highlight = false; // recupero search string SearchVal = AppMServ.SearchVal; // calcolo valore highlight if (!string.IsNullOrEmpty(SearchVal)) { highlight = (CurrData.Descrizione.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)); } btnClass = highlight ? "btn btn-success" : "btn btn-primary"; return btnClass; } } protected string buttonCss { get => !IsClipboard ? "dropbtn" : ""; } /// /// definizione CSS posizionale secondo condizioni top/left /// protected string cssDropContent { get { string answ = "dropdown-content"; if (dropActionTop) { answ += "-top"; } if (dropActionLeft) { answ += "-left"; } return answ; } } protected string cssSelected { get => isSelected ? "table-info" : ""; } [Inject] protected GpwDataService GDataServ { get; set; } = null!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected async void AddTime(bool isEnd, int deltaMin) { // verifico checkbox IsEnd if (isEnd) { // modifico fine... CurrData.Fine = CurrData.Fine.AddMinutes(deltaMin); checkCoerenzaDate(false); } else { // modifico inizio... CurrData.Inizio = CurrData.Inizio.AddMinutes(deltaMin); checkCoerenzaDate(true); } // salvo await GDataServ.RegAttUpdate(CurrData); await ItemUpdated.InvokeAsync(CurrData); } /// /// Indico item selezionato /// protected async void Clone() { var newData = CurrData.Clone(); newData.IdxRa = 0; AppMServ.clonedRA = newData; await ItemCloned.InvokeAsync(newData); } /// /// Indico item selezionato /// protected async void Delete() { // chiedo verifica if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il record selezionato??")) return; // aggiorno await GDataServ.RegAttDelete(CurrData); // registro fatto await ItemUpdated.InvokeAsync(null); } /// /// Indico item selezionato /// protected async void Edit() { isSelected = true; await ItemSelected.InvokeAsync(CurrData); } protected override void OnInitialized() { AppMServ.EA_SearchUpdated += AppMServ_EA_SearchUpdated; isSelected = false; } /// /// Indico item selezionato /// protected async void ReportSelect(RegAttivitaModel selRecord) { await ItemSelected.InvokeAsync(selRecord); } /// /// Trim linea di testo secondo regole /// /// Stringa origiale /// Fattore di moltiplicazione (std: 130) /// protected string trimLine(object stringOrig, int multFact = 130) { double num = 1; if (CurrData.OreTot != null) { num = (double)CurrData.OreTot; } double perc = num / Periodo; int maxLenght = (int)(perc * multFact); string answ = $"{stringOrig}"; if (answ.Length > maxLenght) { answ = $"{answ.Substring(0, maxLenght)}..."; } return answ; } #endregion Protected Methods #region Private Properties private string blockCss { get { string answ = CurrData.IdxFase == 0 ? "" : " bg-body rounded shadow"; return answ; } } private bool dropActionLeft { get { bool answ = CurrData.Inizio.Hour >= MidHour ? true : false; return answ; } } private bool dropActionTop { get { bool answ = false; switch (CurrData.Inizio.DayOfWeek) { case DayOfWeek.Sunday: case DayOfWeek.Saturday: case DayOfWeek.Friday: answ = true; break; default: break; } return answ; } } private bool VetoInsert { get => GDataServ.VetoInsert; } private string widthPerc { get { string answ = "1%"; if (CurrData != null) { double num = CurrData.OreTot != null ? (double)CurrData.OreTot : 0; answ = $"{num / Periodo:P2}".Replace(",", "."); } return answ; } } #endregion Private Properties #region Private Methods private void AppMServ_EA_SearchUpdated() { InvokeAsync(StateHasChanged); } /// Verifico coerenza date (inizio < fine) indica se la data modificata sia l'inizio private void checkCoerenzaDate(bool modInizio) { // verifica presenza errori bool inError = CurrData.Inizio >= CurrData.Fine; if (inError) { // se ho mod inizio --> tengo ferma fine, inizio 1/2 h prima if (modInizio) { CurrData.Inizio = CurrData.Fine.AddMinutes(-30); } else { CurrData.Fine = CurrData.Inizio.AddMinutes(30); } } } #endregion Private Methods } }