diff --git a/src/Ermes.Application/Ermes/Dashboard/DashboardAppService.cs b/src/Ermes.Application/Ermes/Dashboard/DashboardAppService.cs index af2575a0..c51224fa 100644 --- a/src/Ermes.Application/Ermes/Dashboard/DashboardAppService.cs +++ b/src/Ermes.Application/Ermes/Dashboard/DashboardAppService.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace Ermes.Dashboard { @@ -114,6 +115,20 @@ public virtual async Task GetStatistics(GetStatisticsInput var hasPermission = _permissionChecker.IsGranted(_session.Roles, AppPermissions.Reports.Report_CanSeeCrossOrganization); if (!hasPermission) queryReport = queryReport.DataOwnership(person.OrganizationId.HasValue ? new List() { person.OrganizationId.Value } : null); + + if (input.ReportHazards != null && input.ReportHazards.Count > 0) + { + var hazardList = input.ReportHazards.Select(a => a.ToString()).ToList(); + queryReport = queryReport.Where(a => hazardList.Contains(a.HazardString)); + } + + if (input.ReportVisibility != VisibilityType.All) + { + if (input.ReportVisibility == VisibilityType.Private) + queryReport = queryReport.Where(r => !r.IsPublic); + else + queryReport = queryReport.Where(r => r.IsPublic); + } ///////////////////// //Missions/////////// @@ -122,6 +137,14 @@ public virtual async Task GetStatistics(GetStatisticsInput hasPermission = _permissionChecker.IsGranted(_session.Roles, AppPermissions.Missions.Mission_CanSeeCrossOrganization); if (!hasPermission) queryMission = queryMission.DataOwnership(person.OrganizationId.HasValue ? new List() { person.OrganizationId.Value } : null); + + if (input.MissionStatus != null && input.MissionStatus.Count > 0) + { + //input.Status.Contains throw an exception + //I need to go through the strings rather then the enum + var list = input.MissionStatus.Select(a => a.ToString()).ToList(); + queryMission = queryMission.Where(a => list.Contains(a.CurrentStatusString)); + } ////////////////////// //Persons//////////// @@ -133,7 +156,8 @@ public virtual async Task GetStatistics(GetStatisticsInput orgIdList = _session.LoggedUserPerson.OrganizationId.HasValue ? new int[] { _session.LoggedUserPerson.OrganizationId.Value } : null; string personName = _session.LoggedUserPerson.Username ?? _session.LoggedUserPerson.Email; - var items = _geoJsonBulkRepository.GetPersonActions(start, end, orgIdList, null, null, null, boundingBox, personName, null, _languageManager.CurrentLanguage.Name); + var teamIds = input.TeamIds?.ToArray(); + var items = _geoJsonBulkRepository.GetPersonActions(start, end, orgIdList, input.ActionStatusTypes, null, teamIds, boundingBox, personName, null, _languageManager.CurrentLanguage.Name); var deserialized = JsonConvert.DeserializeObject(items); var actions = deserialized != null && deserialized.PersonActions != null ? deserialized.PersonActions : new List(); //////////////////// @@ -147,15 +171,56 @@ public virtual async Task GetStatistics(GetStatisticsInput if (_session.LoggedUserPerson.OrganizationId.HasValue) queryMapRequests = queryMapRequests.DataOwnership(new List() { _session.LoggedUserPerson.OrganizationId.Value }); } - queryMapRequests = queryMapRequests.Where(x => x.StatusString != MapRequestStatusType.Canceled.ToString()); - ////////////////////// - //Alerts/////////// - IQueryable queryAlerts = boundingBox != null ? _geoJsonBulkRepository.GetAlerts(start, end, boundingBox) : _alertManager.GetAlerts(start, end); + if (input.MapRequestStatus != null && input.MapRequestStatus.Count > 0) + { + var list = input.MapRequestStatus.Select(a => a.ToString()).ToList(); + queryMapRequests = queryMapRequests.Where(a => list.Contains(a.StatusString)); + } + else + queryMapRequests = queryMapRequests.Where(a => a.StatusString != MapRequestStatusType.Canceled.ToString()); + + if (input.MapRequestTypes != null && input.MapRequestTypes.Count > 0) + { + var list = input.MapRequestTypes.Select(a => a.ToString()).ToList(); + queryMapRequests = queryMapRequests.Where(a => list.Contains(a.TypeString)); + } ////////////////////// //Communications/////////// + bool includeNone = false; + var roles = await _personManager.GetPersonRoleNamesAsync(person.Id); IQueryable queryCommunications = boundingBox != null ? _geoJsonBulkRepository.GetCommunications(start, end, boundingBox) : _communicationManager.GetCommunications(start, end); + if (input.CommunicationScopes != null && input.CommunicationScopes.Count > 0) + { + var list = input.CommunicationScopes.Select(a => a.ToString()).ToList(); + queryCommunications = queryCommunications.Where(a => list.Contains(a.ScopeString)); + includeNone = input.CommunicationScopes.Contains(CommunicationScopeType.Public); + + } + if (input.CommunicationRestrictions != null && input.CommunicationRestrictions.Count > 0) + { + if (includeNone) + input.CommunicationRestrictions.Add(CommunicationRestrictionType.None); + if (roles.Any(r => r == AppRoles.CITIZEN)) + input.CommunicationRestrictions = new List { CommunicationRestrictionType.None, CommunicationRestrictionType.Citizen }; + + + var list = input.CommunicationRestrictions.Select(a => a.ToString()).ToList(); + queryCommunications = queryCommunications.Where(a => list.Contains(a.RestrictionString)); + } + else + { + input.CommunicationRestrictions = new List() { CommunicationRestrictionType.None, CommunicationRestrictionType.Professional, CommunicationRestrictionType.Organization, CommunicationRestrictionType.Citizen }; + if (roles.Any(r => r == AppRoles.CITIZEN)) + input.CommunicationRestrictions = input.CommunicationRestrictions.Where(a => a == CommunicationRestrictionType.None || a == CommunicationRestrictionType.Citizen).ToList(); + + if (input.CommunicationRestrictions.Count > 0) + { + var list = input.CommunicationRestrictions.Select(a => a.ToString()).ToList(); + queryCommunications = queryCommunications.Where(a => list.Contains(a.RestrictionString)); + } + } //Admin can see everything hasPermission = _permissionChecker.IsGranted(_session.Roles, AppPermissions.Communications.Communication_CanSeeCrossOrganization); @@ -261,15 +326,6 @@ public virtual async Task GetStatistics(GetStatisticsInput Value = g.Count() }) .ToList(), - AlertsByRestriction = queryAlerts - .GroupBy(a => a.Restriction) - .Select(g => new GroupDto() - { - Id = g.Key, - Label = g.Key, - Value = g.Count() - }) - .ToList(), Stations = stations }; } diff --git a/src/Ermes.Application/Ermes/Dashboard/Dto/GetStatisticsInput.cs b/src/Ermes.Application/Ermes/Dashboard/Dto/GetStatisticsInput.cs index c4c398c3..59977ea8 100644 --- a/src/Ermes.Application/Ermes/Dashboard/Dto/GetStatisticsInput.cs +++ b/src/Ermes.Application/Ermes/Dashboard/Dto/GetStatisticsInput.cs @@ -1,4 +1,5 @@ using Ermes.Dto.Spatial; +using Ermes.Enums; using Ermes.Filters; using System; using System.Collections.Generic; @@ -12,5 +13,19 @@ public class GetStatisticsInput : IDateRangeFilter, IBBoxFilter public DateTime? EndDate { get; set; } public PointPosition NorthEastBoundary { get; set; } public PointPosition SouthWestBoundary { get; set; } + + public List ActionStatusTypes { get; set; } + public List TeamIds { get; set; } + + public List ReportHazards { get; set; } + public VisibilityType ReportVisibility { get; set; } + + public List MissionStatus { get; set; } + + public List CommunicationRestrictions { get; set; } + public List CommunicationScopes { get; set; } + + public List MapRequestStatus { get; set; } + public List MapRequestTypes { get; set; } } } diff --git a/src/Ermes.Application/Ermes/Dashboard/Dto/GetStatisticsOutput.cs b/src/Ermes.Application/Ermes/Dashboard/Dto/GetStatisticsOutput.cs index f2dd9574..d8a4d186 100644 --- a/src/Ermes.Application/Ermes/Dashboard/Dto/GetStatisticsOutput.cs +++ b/src/Ermes.Application/Ermes/Dashboard/Dto/GetStatisticsOutput.cs @@ -14,7 +14,6 @@ public class GetStatisticsOutput public Dictionary> ActivationsByDay { get; set; } public List CommunicationsByRestriction { get; set; } public List MapRequestByType { get; set; } - public List AlertsByRestriction { get; set; } public List Stations { get; set; } } diff --git a/src/Ermes.Web/Release-Notes.txt b/src/Ermes.Web/Release-Notes.txt index f5dc101a..724683d8 100644 --- a/src/Ermes.Web/Release-Notes.txt +++ b/src/Ermes.Web/Release-Notes.txt @@ -1,6 +1,6 @@ Ver. -------------------------------- - +- Feature - Subfilters for GetStatistics API added (sdk to be updated)(#179) Ver. 4.18.3 - 2024-03-13 --------------------------------