Skip to content

Commit

Permalink
Bugs/185446 Fix project status filter (#950)
Browse files Browse the repository at this point in the history
* Filters section now stays open when filtering on proj status

* Changed WithdrawnDuringOpening mapping value to "Withdrawn in pre-opening" to match UI

* updated checks to be consistent
  • Loading branch information
zhodges-nimble authored Nov 7, 2024
1 parent 80b9b8f commit 68a7cb8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void ToProjectStatusType_ReturnsExpectedEnum(string input, ProjectStatus
//[InlineData("AnyNotRecognised", ProjectStatus.Preopening)]
[InlineData(ProjectStatus.Cancelled, "Cancelled during pre-opening")]
[InlineData(ProjectStatus.Closed, "Closed")]
[InlineData(ProjectStatus.WithdrawnDuringPreOpening, "Withdrawn during pre-opening")]
[InlineData(ProjectStatus.WithdrawnDuringPreOpening, "Withdrawn in pre-opening")]
[InlineData(ProjectStatus.ApplicationCompetitionStage, "Application Competition stage")]
[InlineData(ProjectStatus.ApplicationStage, "Application stage")]
[InlineData(ProjectStatus.OpenNotIncludedInFigures, "Open free school - Not included in figures")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,13 @@ public record GetDashboardParameters
public string Wave { get; set; }
public int Page { get; set; }
public int Count { get; set; }

}

public class GetDashboardService : IGetDashboardService
public class GetDashboardService(MfspContext context) : IGetDashboardService
{
private readonly MfspContext _context;

public GetDashboardService(MfspContext context)
{
_context = context;
}


public async Task<(List<GetDashboardResponse>, int)> Execute(GetDashboardParameters parameters)
{
var query = _context.Kpi.AsQueryable();
var query = context.Kpi.AsQueryable();

query = ApplyFilters(query, parameters);

Expand Down Expand Up @@ -71,14 +62,10 @@ public GetDashboardService(MfspContext context)
private static IQueryable<Kpi> ApplyFilters(IQueryable<Kpi> query, GetDashboardParameters parameters)
{
if (!string.IsNullOrEmpty(parameters.UserId))
{
query = query.Where(kpi => kpi.User.Email == parameters.UserId);
}

if (parameters.Regions.Any())
{
if (parameters.Regions.Count != 0)
query = query.Where(kpi => parameters.Regions.Any(region => kpi.SchoolDetailsGeographicalRegion == region));
}

if (!string.IsNullOrEmpty(parameters.Project))
{
Expand All @@ -87,38 +74,28 @@ private static IQueryable<Kpi> ApplyFilters(IQueryable<Kpi> query, GetDashboardP
|| kpi.ProjectStatusProjectId == parameters.Project);
}

if (parameters.LocalAuthority.Any())
{
if (parameters.LocalAuthority.Count != 0)
query = query.Where(kpi => parameters.LocalAuthority.Any(localAuthority => kpi.LocalAuthority == localAuthority));
}

if (parameters.ProjectManagedBy.Count > 0)
{
if (parameters.ProjectManagedBy.Count != 0)
query = query.Where(kpi => parameters.ProjectManagedBy.Any(projectManagedBy => kpi.KeyContactsFsgLeadContact == projectManagedBy));
}

if (parameters.ProjectStatus.Count > 0)
{

if (parameters.ProjectStatus.Count != 0)
query = query.Where(kpi => parameters.ProjectStatus.Any(projectStatus => kpi.ProjectStatusProjectStatus == projectStatus));
}

if (!string.IsNullOrEmpty(parameters.Wave))
{
query = query.Where(kpi => kpi.ProjectStatusFreeSchoolApplicationWave == parameters.Wave);
}

return query;
}


public async Task<IEnumerable<string>> ExecuteProjectIds(GetDashboardParameters parameters)
{
var query = _context.Kpi.AsQueryable();
var query = context.Kpi.AsQueryable();

query = ApplyFilters(query, parameters);

await
query
await query
.OrderByDescending(kpi => kpi.ProjectStatusProvisionalOpeningDateAgreedWithTrust)
.ThenBy(kpi => kpi.ProjectStatusCurrentFreeSchoolName)
.ToListAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static string FromProjectStatusType(ProjectStatusType projectStatus)
ProjectStatusType.Open => "Open",
ProjectStatusType.Closed => "Closed",
ProjectStatusType.Cancelled => "Cancelled during pre-opening",
ProjectStatusType.WithdrawnDuringPreOpening => "Withdrawn during pre-opening",
ProjectStatusType.WithdrawnDuringPreOpening => "Withdrawn in pre-opening",
ProjectStatusType.Rejected => "Rejected at application stage",
ProjectStatusType.ApplicationCompetitionStage => "Application Competition stage",
ProjectStatusType.ApplicationStage => "Application stage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public async Task Execute(string projectId, UpdateProjectStatusRequest request)
dbProject.ProjectStatusDateCancelled = updateRequest.CancelledDate;
dbProject.ProjectStatusDateWithdrawn = updateRequest.WithdrawnDate;


await _context.SaveChangesAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public class DashboardBasePageModel(
[BindProperty(Name = "search-by-project-status", SupportsGet = true)]
public List<string> ProjectStatusSearchTerm { get; set; } = new();

[BindProperty] public bool UserCanCreateProject { get; set; }

[BindProperty] public List<string> ProjectManagers { get; set; }

public DashboardModel Dashboard { get; set; } = new();

protected readonly ICreateUserService CreateUserService = createUserService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
!string.IsNullOrWhiteSpace(Model.ProjectSearchTerm)
|| Model.RegionSearchTerm.Any()
|| Model.LocalAuthoritySearchTerm.Any()
|| Model.ProjectManagedBySearchTerm.Any();
|| Model.ProjectManagedBySearchTerm.Any()
|| Model.ProjectStatusSearchTerm.Any();

var openFilter = isFilterActive ? "open" : "";

Expand Down

0 comments on commit 68a7cb8

Please sign in to comment.