@page "/" @page "/Dashboard" @inject IConfiguration Configuration @inject MesaFabApprovalAuthStateProvider stateProvider @inject IApprovalService approvalService @inject IMemoryCache cache @inject NavigationManager navigationManager @inject ISnackbar snackbar @inject IMRBService mrbService @inject IPCRBService pcrbService @inject IECNService ecnService @inject ICAService caService @inject IJSRuntime jsRuntime Dashboard Dashboard @if (stateProvider.CurrentUser is not null && approvalList is not null && !myApprovalsProcessing) { My Active Approvals Issue ID Role Assigned Date Step @if (context.IssueID > 0) { @context.IssueID } @context.SubRoleCategoryItem @DateTimeUtilities.GetDateAsStringMinDefault(context.AssignedDate) @context.Step } else { Processing } @if (stateProvider.CurrentUser is not null && myMRBs is not null && !myMrbsProcessing) { My MRBs MRB# Title Submitted Date Approval Date Cancel Date Completed Date @context.MRBNumber @context.Title @DateTimeUtilities.GetDateAsStringMinDefault(context.SubmittedDate) @DateTimeUtilities.GetDateAsStringMaxDefault(context.ApprovalDate) @DateTimeUtilities.GetDateAsStringMaxDefault(context.CancelDate) @DateTimeUtilities.GetDateAsStringMaxDefault(context.CloseDate) } else { Processing } @if (stateProvider.CurrentUser is not null && myPCRBs is not null && !myPcrbsProcessing) { My PCRBs PCRB# Title Current Step Submitted Date Last Updated Completed Date @context.PlanNumber @context.Title @(GetCurrentPCRBStep(context.CurrentStep)) @DateTimeUtilities.GetDateAsStringMinDefault(context.InsertTimeStamp) @DateTimeUtilities.GetDateAsStringMinDefault(context.LastUpdateDate) @DateTimeUtilities.GetDateAsStringMaxDefault(context.ClosedDate) } else { Processing } @code { private IEnumerable approvalList = new List(); private IEnumerable myMRBs = new List(); private IEnumerable myPCRBs = new List(); private IEnumerable ecnNumbers = new HashSet(); private IEnumerable caNumbers = new HashSet(); private IEnumerable mrbNumbers = new HashSet(); private IEnumerable pcrbNumbers = new HashSet(); private bool myApprovalsProcessing = false; private bool myMrbsProcessing = false; private bool myPcrbsProcessing = false; private string mrbSearchString = ""; private string pcrbSearchString = ""; protected async override Task OnParametersSetAsync() { try { if (stateProvider.CurrentUser is not null) { myApprovalsProcessing = true; approvalList = (await approvalService.GetApprovalsForUserId(stateProvider.CurrentUser.UserID, true)) .Where(a => a.CompletedDate > DateTime.Now && a.ItemStatus == 0) .ToList() .OrderByDescending(x => x.AssignedDate); myApprovalsProcessing = false; myMrbsProcessing = true; myMRBs = (await mrbService.GetAllMRBs(false)).Where(m => m.OriginatorID == stateProvider.CurrentUser.UserID) .ToList() .OrderByDescending(x => x.SubmittedDate); myMrbsProcessing = false; myPcrbsProcessing = true; myPCRBs = (await pcrbService.GetAllPCRBs(false)).Where(p => p.OwnerID == stateProvider.CurrentUser.UserID) .ToList() .OrderByDescending(p => p.InsertTimeStamp); myPcrbsProcessing = false; } } catch (Exception ex) { myApprovalsProcessing = false; myMrbsProcessing = false; myPcrbsProcessing = false; snackbar.Add($"Unable to load the dashboard, because {ex.Message}", Severity.Error); } } private async Task FollowLink(int issueId) { HashSet tasks = new(); bool isEcn = false; bool isCa = false; bool isMrb = false; bool isPcrb = false; if (ecnNumbers.Contains(issueId)) isEcn = true; if (caNumbers.Contains(issueId)) isCa = true; if (mrbNumbers.Contains(issueId)) isMrb = true; if (pcrbNumbers.Contains(issueId)) isPcrb = true; if (!isEcn && !isCa && !isMrb) { Task isEcnTask = ecnService.ECNNumberIsValid(issueId); tasks.Add(isEcnTask); Task isCaTask = caService.CANumberIsValid(issueId); tasks.Add(isCaTask); Task isMrbTask = mrbService.NumberIsValid(issueId); tasks.Add(isMrbTask); Task isPcrbTask = pcrbService.IdIsValid(issueId); tasks.Add(isPcrbTask); await Task.WhenAll(tasks); if (isEcnTask.Result) { isEcn = true; } else if (isCaTask.Result) { isCa = true; } else if (isMrbTask.Result) { isMrb = true; } else if (isPcrbTask.Result) { isPcrb = true; } } if (isEcn) await GoToExternal($"{Configuration["OldFabApprovalUrl"]}/ECN/Edit?IssueID={issueId}", ""); if (isCa) await GoToExternal($"{Configuration["OldFabApprovalUrl"]}/CorrectiveAction/Edit?IssueID={issueId}", ""); if (isMrb) GoTo($"mrb/{issueId}"); if (isPcrb) GoTo($"pcrb/{issueId}"); } private void GoTo(string page) { cache.Set("redirectUrl", page); navigationManager.NavigateTo("/" + page); } private async Task GoToExternal(string url, string content) { IJSObjectReference windowModule = await jsRuntime.InvokeAsync("import", "./js/OpenInNewWindow.js"); await windowModule.InvokeAsync("OpenInNewWindow", url, content); } private bool FilterFuncForMRBTable(MRB mrb) => MRBFilterFunc(mrb, mrbSearchString); private bool MRBFilterFunc(MRB mrb, string searchString) { if (string.IsNullOrWhiteSpace(searchString)) return true; if (mrb.Title.ToLower().Contains(searchString.Trim().ToLower())) return true; if (mrb.MRBNumber.ToString().Contains(searchString.Trim())) return true; return false; } private bool FilterFuncForPCRBTable(PCRB pcrb) => PCRBFilterFunc(pcrb, pcrbSearchString); private bool PCRBFilterFunc(PCRB pcrb, string searchString) { if (string.IsNullOrWhiteSpace(searchString)) return true; if (pcrb.Title.ToLower().Contains(searchString.Trim().ToLower())) return true; if (pcrb.PlanNumber.ToString().Contains(searchString.Trim())) return true; return false; } private string GetCurrentPCRBStep(int step) { if (step < 0 || step > (PCRB.Stages.Length - 1)) return string.Empty; else return PCRB.Stages[step]; } }