@page "/GestionDeIncidencias" @using Microsoft.AspNetCore.SignalR.Client @using System.Linq; @inject NavigationManager NavigationManager @*@implements IAsyncDisposable*@ @using Newtonsoft.Json @using MC_Gestion.Data.WorkData @using MC_Gestion.Models @using MC_Gestion.Hubs @using Syncfusion.Blazor.Data @using Syncfusion.Blazor.Grids @using Syncfusion.Blazor.DropDowns @using Syncfusion.Blazor.Buttons @using Syncfusion.Blazor.Inputs @using Syncfusion.Blazor.Navigations @using Syncfusion.Blazor.Notifications @using SimpleMsgTelegram @using Areas.Identity @inject IJSRuntime JsRuntime @inject AuthenticationStateProvider AuthenticationStateProvider
@{ var _incidencia = (context as tblIncidencias);
INCIDENCIA: @(_incidencia.indID)
}
@code { #region variables private HubClientMC hubIncidencias = new(); private Models2Hub message = new(); #region Listas de tablas public List? _incidencias { get; set; } public List? _estados { get; set; } public List? _prioridad { get; set; } public List? _puestos { get; set; } public List? _areas { get; set; } public List? _espacios { get; set; } public List? _gruposTrabajo { get; set; } #endregion #region Filtros en cascada public Query? GroupQuery { get; set; } public bool EnablePuesto = false; public Query? AreaQuery { get; set; } public bool EnableEspacio = false; #endregion public long _puesto = 0; public UserData? _userData; public bool _notEdit = false; public bool _IsDroupManager = false; public FieldReadOnly _readOnly = new(); //SfToast AlertPopup; SfGrid? Grid; public string? selectedDescription { get; set; } public long selectedID { get; set; } public string AlertContent = ""; public string AlertTitle = ""; #endregion protected override async Task OnInitializedAsync() { _userData = GetAsync(); if (_userData.IsManager) { _incidencias = Incidencias.GetAll().ToList(); } else { _incidencias = Incidencias.GetAll(_userData.Puesto).ToList(); } await hubIncidencias.OnHubsFunctions(); _estados= IncidenciasEstado.GetAll().ToList(); _prioridad = IncidenciasPrioridad.GetAll().ToList(); _puestos = Puestos.GetAll(_userData.User).ToList(); _espacios = Espacios.GetAll().ToList(); _areas = Areas.GetAll().ToList(); //var _pareas = from _a in _areas join _p in _puestos on _a.areID equals _p.areID select new { _a }; //_areas.Clear(); //foreach (var item in _pareas) //{ // _areas.Add(item._a); //} _gruposTrabajo = GruposDeTrabajo.GetAll().ToList(); _gruposTrabajo.Insert(0, new tblWorkGroup() { gtrID = 0, gtrName = "Individual", gtrDescription = "Sin grupo de trabajo", pueIDManager = 0 }); foreach (var item in _incidencias.GetType().GetFields()) { _readOnly[item.Name] = false; } await base.OnInitializedAsync(); } #region Filtros de combo public void ChangeGroup(ChangeEventArgs args) { this.EnablePuesto = !(args.Value==0); this.GroupQuery = new Query().Where(new WhereFilter() { Field = "gtrID", Operator = "equal", value = args.Value}); } public void ChangeArea(ChangeEventArgs args) { this.EnableEspacio = !(args.Value==0); this.AreaQuery = new Query().Where(new WhereFilter() { Field = "areID", Operator = "equal", value = args.Value}); } public void OnActionFailureGroup(Exception ex){ var e = ex.Message; } public void OnActionFailureAreas(Exception ex){ var e = ex.Message; } #endregion public void ToolbarClick(ClickEventArgs args) { if (args is null) { throw new ArgumentNullException(nameof(args)); } if (args.Item.Id == "Grid_excelexport") { var _excelExportProperties = new ExcelExportProperties(); _excelExportProperties.FileName = $"Incidencias_{DateTime.Now.ToString("yyyyMMdd-hhmmss")}.xlsx"; _excelExportProperties.IncludeHiddenColumn = true; this.Grid.ExportToExcelAsync(_excelExportProperties); } } public void ActionComplete(ActionEventArgs args) { if (args.Data is not null) { _notEdit = ConfirmEdit(args); } if (args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit) { if (!_notEdit) { _readOnly["ineID"] = false; } } else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Add) { args.Data.indActive = true; args.Data.ineID = 1; _readOnly["ineID"] = true; // Triggers once add operation completes } else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Cancel) { } else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save) { // Triggers once save operation completes try { _notEdit = (args.Data.indID == 0) ? false: _notEdit; if (!_notEdit) { Incidencias.Save(args.Data.indID, args.Data.indTitle, args.Data.indDescription, args.Data.ineID, args.Data.indActive, args.Data.inpID, _userData.User, args.Data.pueIDAssingned, args.Data.indNotes, args.Data.areID, args.Data.espID, args.Data.gtrID); if (args.Data.indID == 0) { Models2Hub _message = new(); _message.HubType = 0; _message.hubUser = new() { Email = "", HubID = _userData.User, Name = _userData.Name, PhoneNumber = _userData.Telephon }; _message.incidence = new() { indID = args.Data.indID, Title = args.Data.indTitle, Status = args.Data.ineID.ToString().Trim(), Area = args.Data.areID.ToString().Trim(), Space = args.Data.espID.ToString().Trim(), Priority = args.Data.inpID.ToString().Trim(), WorkGroup = args.Data.gtrID.ToString().Trim() }; hubIncidencias.Send(_message); } } else { Shared.MainLayout.AlertMessage("ERROR", $"No se ha podido grabar el registro: {args.Data.indTitle}","error"); args.Cancel = true; } } catch (Exception ex) { //AlertMessage("ERROR", $"No se ha podido crear el registro: {ex.Message}","error"); args.Cancel = true; } if (Puestos.IsManager(_userData.User)) { _incidencias = Incidencias.GetAll().ToList(); } else { _incidencias = Incidencias.GetAll(_userData.Puesto).ToList(); } } else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Delete) { try { if (!_notEdit) { Incidencias.Delete(args.Data.indID); } } catch (Exception ex) { //AlertMessage("ERROR", $"No se ha podido borrar el registro: {ex.Message}","error"); } _incidencias = Incidencias.GetAll().ToList(); if (Puestos.IsManager(_userData.User)) { _incidencias = Incidencias.GetAll().ToList(); } else { _incidencias = Incidencias.GetAll(_userData.Puesto).ToList(); } } } private bool IsGroupManager(long Group, long Job) { var _return = GruposDeTrabajo.Get(Group); return _return.pueIDManager == Job; } public bool ConfirmEdit(ActionEventArgs args){ bool notEdit = true; if (_userData.IsManager) { notEdit = false; } else { _IsDroupManager = IsGroupManager(args.Data.gtrID, args.Data.pueIDAssingned); if (_IsDroupManager && args.Data.indActive) { notEdit = false; } else { if (args.Data.indActive && !args.Data.indClosed) { notEdit = false; } } } return notEdit; } public UserData GetAsync() { UserData userData = new() { User = "", Puesto = new long[] { 0 }, Name = "", Telephon = "", IsAssingned = false, IsSignedUser = false, IsManager = false}; try { var authState = AuthenticationStateProvider.GetAuthenticationStateAsync().Result; var user = authState.User; userData.IsSignedUser = user.Identity.IsAuthenticated; if (userData.IsSignedUser) { userData.User = user.Claims.First().Value; userData.Name = user.Identity.Name; var _return = Data.RetrieveUserData.GetAsync(userData.User); userData.IsAssingned = _return.IsAssingned; userData.Puesto = _return.Puesto.ToArray(); //Data.WorkDataPuestos.GetAllIDs(userData.User).ToArray(); userData.IsManager = _return.IsManager; } } catch (Exception) { userData = new() { User = "", Puesto = new long[] { 0 }, Name = "", Telephon = "", IsAssingned = false, IsSignedUser = false, IsManager = false}; } return userData; } public void ColorizeCell(QueryCellInfoEventArgs args) { if (args.Data.indClosed) { args.Cell.AddClass(new string[] { "closed-true" }); } else { if (args.Column.Field == "indClosed") { args.Cell.AddClass(new string[] { $"cell-priority-{args.Data.inpID.ToString().Trim()}" }); } } } public class FieldReadOnly { private Dictionary keyValuePairs = new(); public bool this[string Name] { get { if (keyValuePairs.ContainsKey(Name)) { return keyValuePairs[Name]; } else { return false; } } set { if (keyValuePairs.ContainsKey(Name)) { keyValuePairs[Name] = value; } else { keyValuePairs.Add(Name, value); } } } } }