Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ public void GetCourseStatisticsAtCentreFilteredByCategory_should_return_course_s
CategoryName = "Office 2007",
CourseTopic = "Microsoft Office",
LearningMinutes = "N/A",
Archived = false,
};

result.Should().HaveCount(259);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ FROM CustomisationTutorials AS ct
private readonly string CourseStatisticsQuery = @$"SELECT
cu.CustomisationID,
cu.CentreID,
cu.Active,
CASE WHEN ap.ArchivedDate IS NOT NULL THEN 0 ELSE cu.Active END AS Active,
cu.AllCentres,
ap.ApplicationId,
ap.ApplicationName,
Expand All @@ -188,7 +188,8 @@ FROM CustomisationTutorials AS ct
cc.CategoryName,
ct.CourseTopic,
cu.LearningTimeMins AS LearningMinutes,
cu.IsAssessed
cu.IsAssessed,
CASE WHEN ap.ArchivedDate IS NOT NULL THEN 1 ELSE 0 END AS Archived
FROM dbo.Customisations AS cu
INNER JOIN dbo.CentreApplications AS ca ON ca.ApplicationID = cu.ApplicationID
INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = ca.ApplicationID
Expand Down
2 changes: 1 addition & 1 deletion DigitalLearningSolutions.Data/Models/Courses/Course.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Course : CourseNameInfo
public int CentreId { get; set; }
public int ApplicationId { get; set; }
public bool Active { get; set; }

public bool Archived { get; set; }
public string CourseNameWithInactiveFlag => !Active ? "Inactive - " + CourseName : CourseName;

public override bool Equals(object? obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ IEnumerable<CourseAdminFieldWithResponseCounts> adminFieldsWithResponses
Active = courseStatistics.Active;
CustomisationName = courseStatistics.CustomisationName;
ApplicationName = courseStatistics.ApplicationName;
Archived = courseStatistics.Archived;
}

public IEnumerable<CourseAdminFieldWithResponseCounts> AdminFieldsWithResponses { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion DigitalLearningSolutions.Data/Services/CourseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public IEnumerable<string> GetTopicsForCentreAndCentrallyManagedCourses(int cent
public CentreCourseDetails GetCentreCourseDetails(int centreId, int? categoryId)
{
var (courses, categories, topics) = (
GetNonArchivedCentreSpecificCourseStatisticsWithAdminFieldResponseCounts(centreId, categoryId),
GetCentreSpecificCourseStatisticsWithAdminFieldResponseCounts(centreId, categoryId),
courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId)
.Select(c => c.CategoryName),
courseTopicsDataService.GetCourseTopicsAvailableAtCentre(centreId).Select(c => c.CourseTopic));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class CourseSetupControllerTests
HideInLearnerPortal = true,
DelegateCount = 1,
CompletedCount = 1,
Archived = false,
},
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CourseStatisticsViewModelFilterOptionsTests
new[]
{
new FilterOptionModel(
"Inactive",
"Inactive/archived",
"Status" + FilteringHelper.Separator + "Active" + FilteringHelper.Separator +
"false",
FilterStatus.Warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DelegateCoursesStatisticsViewModelFilterOptionsTests
new[]
{
new FilterOptionModel(
"Inactive",
"Inactive/archived",
"Status" + FilteringHelper.Separator + "Active" + FilteringHelper.Separator +
"false",
FilterStatus.Warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
using DigitalLearningSolutions.Data.Helpers;
using DigitalLearningSolutions.Data.Models.Courses;
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
using DigitalLearningSolutions.Web.Models.Enums;
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;

public static class CourseStatusFilterOptions
{
private const string Group = "Status";

public static readonly FilterOptionModel IsInactive = new FilterOptionModel(
"Inactive",
"Inactive/archived",
FilteringHelper.BuildFilterValueString(Group, nameof(CourseStatistics.Active), "false"),
FilterStatus.Warning
);
Expand All @@ -22,6 +20,12 @@ public static class CourseStatusFilterOptions
FilteringHelper.BuildFilterValueString(Group, nameof(CourseStatistics.Active), "true"),
FilterStatus.Success
);

public static readonly FilterOptionModel IsArchived = new FilterOptionModel(
"Archived",
FilteringHelper.BuildFilterValueString(Group, nameof(CourseStatistics.Archived), "true"),
FilterStatus.Default
);
}

public static class CourseVisibilityFilterOptions
Expand Down
42 changes: 37 additions & 5 deletions DigitalLearningSolutions.Web/Helpers/FilterableTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,44 @@ public static IEnumerable<SearchableTagViewModel> GetCurrentTagsForDelegateCours
CourseStatistics courseStatistics
)
{
return new List<SearchableTagViewModel>
var tags = new List<SearchableTagViewModel>();

if (courseStatistics.Archived)
{
courseStatistics.Active
? new SearchableTagViewModel(CourseStatusFilterOptions.IsActive)
: new SearchableTagViewModel(CourseStatusFilterOptions.IsInactive),
};
tags.Add(new SearchableTagViewModel(CourseStatusFilterOptions.IsArchived));
}
else if (courseStatistics.Active)
{
tags.Add(new SearchableTagViewModel(CourseStatusFilterOptions.IsActive));
}
else
{
tags.Add(new SearchableTagViewModel(CourseStatusFilterOptions.IsInactive));
}

return tags;
}

public static IEnumerable<SearchableTagViewModel> GetCurrentStatusTagsForDelegateCourses(
CourseStatistics courseStatistics
)
{
var tags = new List<SearchableTagViewModel>();

if (courseStatistics.Archived)
{
tags.Add(new SearchableTagViewModel("Archived", string.Empty, CourseStatusFilterOptions.IsArchived.TagStatus));
}
else if (courseStatistics.Active)
{
tags.Add(new SearchableTagViewModel("Active", string.Empty, CourseStatusFilterOptions.IsActive.TagStatus));
}
else
{
tags.Add(new SearchableTagViewModel("Inactive", string.Empty, CourseStatusFilterOptions.IsInactive.TagStatus));
}

return tags;
}

public static IEnumerable<SearchableTagViewModel> GetCurrentTagsForCourseDelegate(CourseDelegate courseDelegate)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
@use "../shared/cardWithButtons";
@use "nhsuk-frontend/packages/core/all" as *;
@use "../shared/cardWithButtons";
@use "../shared/searchableElements/searchableElements";
@use "../shared/headingButtons.scss";

.admin-field-count {
width: 10%;
}

.status-inactive {
border-left: 6px solid tint($color_nhsuk-red, 80);
}

.status-archived {
border-left: 6px solid $color_nhsuk-grey-2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@
border-left: 6px solid $color_nhsuk-grey-2;
}
}

.status-inactive {
border-left: 6px solid tint($color_nhsuk-red, 80);
}

.status-archived {
border-left: 6px solid $color_nhsuk-grey-2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
using DigitalLearningSolutions.Data.Enums;
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
using DigitalLearningSolutions.Web.Models.Enums;

public class SearchableTagViewModel : FilterOptionModel
{
Expand All @@ -16,6 +15,16 @@ public SearchableTagViewModel(FilterOptionModel filterOption, bool hidden = fals
Hidden = hidden;
}

public SearchableTagViewModel(string displayText, string filterValue, FilterStatus tagStatus, bool hidden = false)
: base(
displayText,
filterValue,
tagStatus
)
{
Hidden = hidden;
}

public bool Hidden { get; set; }

public string NhsTagStyle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public SearchableCourseStatisticsViewModel(CourseStatisticsWithAdminFieldRespons
public string CourseTopic { get; set; }
public string LearningMinutes { get; set; }
public bool Assessed { get; set; }
public string? Status { get; set; }
public IEnumerable<CourseAdminFieldWithResponseCounts> AdminFieldWithResponseCounts { get; set; }
public bool HasAdminFields => AdminFieldWithResponseCounts.Any();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,36 @@ IEnumerable<FilterModel> availableFilters
"Search courses"
)
{
UpdateCourseActiveFlags(result);

Courses = result.ItemsToDisplay.Select(c => new SearchableDelegateCourseStatisticsViewModel(c));
}

private static void UpdateCourseActiveFlags(SearchSortFilterPaginationResult<CourseStatisticsWithAdminFieldResponseCounts> result)
{
foreach (var course in result.ItemsToDisplay)
{
if (course.Active && !course.Archived)
{
course.Active = true;
}
else
{
course.Active = false;
}


if (course.Archived)
{
course.Archived = true;
}
else
{
course.Archived = false;
}
}
}

public IEnumerable<SearchableDelegateCourseStatisticsViewModel> Courses { get; set; }

public override IEnumerable<(string, string)> SortOptions { get; } = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public SearchableDelegateCourseStatisticsViewModel(CourseStatisticsWithAdminFiel
CategoryName = courseStatistics.CategoryName;
CourseTopic = courseStatistics.CourseTopic;
LearningMinutes = courseStatistics.LearningMinutes;
Tags = FilterableTagHelper.GetCurrentTagsForDelegateCourses(courseStatistics);
Tags = FilterableTagHelper.GetCurrentStatusTagsForDelegateCourses(courseStatistics);
Assessed = courseStatistics.IsAssessed;
AdminFieldWithResponseCounts = courseStatistics.AdminFieldsWithResponses;
Status = DeriveCourseStatus(courseStatistics);
}

public int CustomisationId { get; set; }
Expand All @@ -32,6 +33,7 @@ public SearchableDelegateCourseStatisticsViewModel(CourseStatisticsWithAdminFiel
public string CourseTopic { get; set; }
public string LearningMinutes { get; set; }
public bool Assessed { get; set; }
public string? Status { get; set; }

public IEnumerable<CourseAdminFieldWithResponseCounts> AdminFieldWithResponseCounts { get; set; }

Expand All @@ -49,5 +51,19 @@ public SearchableDelegateCourseStatisticsViewModel(CourseStatisticsWithAdminFiel
FilteringHelper.Separator +
nameof(CourseStatisticsWithAdminFieldResponseCounts.HasAdminFields) +
FilteringHelper.Separator + HasAdminFields.ToString().ToLowerInvariant();
private static string DeriveCourseStatus(Course courseStatistics)
{
if (courseStatistics.Archived)
{
return "archived";
}
else switch (courseStatistics.Active)
{
case true:
return "active";
case false:
return "inactive";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
@model IEnumerable<SearchableTagViewModel>

<div class="tags">
@foreach (var tag in Model) {
@foreach (var tag in Model)
{
<div class="card-filter-tag" data-filter-value="@tag.FilterValue" @(tag.Hidden ? "hidden" : string.Empty)>
<strong class="nhsuk-tag @tag.NhsTagStyle()">@tag.DisplayText</strong>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage
@model IEnumerable<SearchableTagViewModel>

<div class="tags">
@foreach (var tag in Model) {
<div class="card-filter-tag" data-filter-value="@tag.FilterValue" @(tag.Hidden ? "hidden" : string.Empty)>
<strong class="nhsuk-tag @tag.NhsTagStyle()">@tag.DisplayText</strong>
</div>
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<div class="nhsuk-details__text">
<partial name="SearchablePage/_FilterableTags" model="@Model.Tags" />

<partial name="_CentreCourseCardDetails" model="@Model" />

<input type="hidden" data-filter-value="@Model.HasAdminFieldsFilter" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates.DelegateCourses
@model SearchableDelegateCourseStatisticsViewModel

<div class="searchable-element nhsuk-panel card-with-buttons word-break" id="@Model.CustomisationId-card">
<div class="searchable-element nhsuk-panel card-with-buttons word-break status-@Model.Status" id="@Model.CustomisationId-card">
<details class="nhsuk-details nhsuk-expander nhsuk-u-margin-bottom-0">
<summary class="nhsuk-details__summary">
<span class="nhsuk-details__summary-text searchable-element-title" id="@Model.CustomisationId-name" name="course-name">
Expand All @@ -10,12 +10,14 @@
</summary>

<div class="nhsuk-details__text">
<partial name="SearchablePage/_FilterableTags" model="@Model.Tags" />

<partial name="SearchablePage/_StatusTags" model="@Model.Tags" />

<partial name="_CentreCourseCardDetails" model="@Model" />

<input type="hidden" data-filter-value="@Model.HasAdminFieldsFilter" />
@if (Model.HasAdminFields) {
@if (Model.HasAdminFields)
{
<partial name="_CentreCourseCardAdminFields" model="@Model" />
}
</div>
Expand Down