Skip to content

Commit dee48ff

Browse files
authored
Merge pull request #1352 from TechnologyEnhancedLearning/Develop/Features/TD-5765
TD- 5765 Certificates subpage - implementation
2 parents 38ce56d + 4484d20 commit dee48ff

File tree

24 files changed

+904
-9
lines changed

24 files changed

+904
-9
lines changed

LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>

LearningHub.Nhs.WebUI/Controllers/MyLearningController.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,77 @@ public async Task<IActionResult> ViewProgress(int resourceId, int resourceRefere
736736
return this.View(vm);
737737
}
738738

739+
/// <summary>
740+
/// Get user certificates.
741+
/// </summary>
742+
/// <param name="certificateRequest">The certificateRequest.</param>
743+
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
744+
[Route("mylearning/certificates")]
745+
[HttpGet]
746+
[HttpPost]
747+
public async Task<IActionResult> Certificates(MyLearningUserCertificatesViewModel certificateRequest = null)
748+
{
749+
var myLearningRequestModel = new MyLearningRequestModel
750+
{
751+
SearchText = certificateRequest.SearchText?.Trim(),
752+
Skip = certificateRequest.CurrentPageIndex * MyLearningPageSize,
753+
Take = MyLearningPageSize,
754+
File = certificateRequest.File,
755+
Video = certificateRequest.Video,
756+
Article = certificateRequest.Article,
757+
Case = certificateRequest.Case,
758+
Image = certificateRequest.Image,
759+
Audio = certificateRequest.Audio,
760+
Elearning = certificateRequest.Elearning,
761+
Html = certificateRequest.Html,
762+
Assessment = certificateRequest.Assessment,
763+
Courses = certificateRequest.Courses,
764+
};
765+
766+
switch (certificateRequest.MyLearningFormActionType)
767+
{
768+
case MyLearningFormActionTypeEnum.NextPageChange:
769+
certificateRequest.CurrentPageIndex += 1;
770+
myLearningRequestModel.Skip = certificateRequest.CurrentPageIndex * MyLearningPageSize;
771+
break;
772+
773+
case MyLearningFormActionTypeEnum.PreviousPageChange:
774+
certificateRequest.CurrentPageIndex -= 1;
775+
myLearningRequestModel.Skip = certificateRequest.CurrentPageIndex * MyLearningPageSize;
776+
break;
777+
case MyLearningFormActionTypeEnum.BasicSearch:
778+
779+
myLearningRequestModel = new MyLearningRequestModel
780+
{
781+
SearchText = certificateRequest.SearchText?.Trim(),
782+
Skip = certificateRequest.CurrentPageIndex * MyLearningPageSize,
783+
Take = MyLearningPageSize,
784+
};
785+
break;
786+
case MyLearningFormActionTypeEnum.ClearAllFilters:
787+
788+
myLearningRequestModel = new MyLearningRequestModel
789+
{
790+
SearchText = certificateRequest.SearchText?.Trim(),
791+
Skip = certificateRequest.CurrentPageIndex * MyLearningPageSize,
792+
Take = MyLearningPageSize,
793+
};
794+
break;
795+
}
796+
797+
var result = await this.myLearningService.GetUserCertificateDetails(myLearningRequestModel);
798+
var response = new MyLearningUserCertificatesViewModel(myLearningRequestModel);
799+
800+
if (result != null)
801+
{
802+
response.TotalCount = result.TotalCount;
803+
response.UserCertificates = result.Certificates;
804+
}
805+
806+
response.MyLearningPaging = new MyLearningPagingModel() { CurrentPage = certificateRequest.CurrentPageIndex, PageSize = MyLearningPageSize, TotalItems = response.TotalCount, HasItems = response.TotalCount > 0 };
807+
return this.View(response);
808+
}
809+
739810
/// <summary>
740811
/// Gets the certificate details of an activity.
741812
/// </summary>
@@ -784,6 +855,7 @@ public async Task<IActionResult> GetCertificateDetails(int resourceReferenceId,
784855
/// <param name="minorVersion">The minorVersion.</param>
785856
/// <param name="userId">The userId.</param>
786857
/// <returns>The <see cref="IActionResult"/>.</returns>
858+
[HttpGet]
787859
[HttpPost]
788860
[Route("mylearning/downloadcertificate")]
789861
public async Task<IActionResult> DownloadCertificate(int resourceReferenceId, int? majorVersion = 0, int? minorVersion = 0, int? userId = 0)

LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ public static Dictionary<string, string> GetActivityParameters(object model)
437437
var routeData = model.GetType().GetProperties().ToDictionary(p => p.Name, p => p.GetValue(model)?.ToString());
438438
routeData.Remove("MostRecentResources");
439439
routeData.Remove("Activities");
440+
routeData.Remove("UserCertificates");
440441
routeData.Remove("TotalCount");
441442
routeData.Remove("MyLearningPaging");
442443
routeData.Remove("Skip");

LearningHub.Nhs.WebUI/Interfaces/IMyLearningService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ public interface IMyLearningService
4949
/// <returns>The <see cref="Task"/>.</returns>
5050
Task<Tuple<int, MyLearningDetailedItemViewModel>> GetResourceCertificateDetails(int resourceReferenceId, int? majorVersion = 0, int? minorVersion = 0, int? userId = 0);
5151

52+
/// <summary>
53+
/// Gets the user certificates.
54+
/// </summary>
55+
/// <param name="requestModel">The request model.</param>
56+
/// <returns>The <see cref="Task"/>.</returns>
57+
Task<MyLearningCertificatesDetailedViewModel> GetUserCertificateDetails(MyLearningRequestModel requestModel);
58+
5259
/// <summary>
5360
/// Gets the resource URL for a given resource reference ID.
5461
/// </summary>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace LearningHub.Nhs.WebUI.Models
2+
{
3+
using System.Collections.Generic;
4+
using System.Reflection;
5+
using LearningHub.Nhs.Models.MyLearning;
6+
using LearningHub.Nhs.Models.Paging;
7+
using LearningHub.Nhs.WebUI.Models.Learning;
8+
using NHSUKViewComponents.Web.ViewModels;
9+
10+
/// <summary>
11+
/// Defines the <see cref="MyLearningUserCertificatesViewModel" />.
12+
/// </summary>
13+
public class MyLearningUserCertificatesViewModel : MyLearningRequestModel
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="MyLearningUserCertificatesViewModel"/> class.
17+
/// </summary>
18+
public MyLearningUserCertificatesViewModel()
19+
{
20+
this.UserCertificates = new List<UserCertificateViewModel>();
21+
}
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="MyLearningUserCertificatesViewModel"/> class.
25+
/// </summary>
26+
/// <param name="requestModel">MyLearningRequestModel.</param>
27+
public MyLearningUserCertificatesViewModel(MyLearningRequestModel requestModel)
28+
{
29+
this.UserCertificates = new List<UserCertificateViewModel>();
30+
foreach (PropertyInfo prop in requestModel.GetType().GetProperties())
31+
{
32+
this.GetType().GetProperty(prop.Name).SetValue(this, prop.GetValue(requestModel, null), null);
33+
}
34+
}
35+
36+
/// <summary>
37+
/// Gets or sets the learning form event.
38+
/// </summary>
39+
public MyLearningFormActionTypeEnum MyLearningFormActionType { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the page item index.
43+
/// </summary>
44+
public int CurrentPageIndex { get; set; } = 0;
45+
46+
/// <summary>
47+
/// Gets or sets the TotalCount.
48+
/// </summary>
49+
public int TotalCount { get; set; }
50+
51+
/// <summary>
52+
/// Gets or sets the Activities.
53+
/// </summary>
54+
public List<UserCertificateViewModel> UserCertificates { get; set; }
55+
56+
/// <summary>
57+
/// Gets or sets the learning result paging.
58+
/// </summary>
59+
public PagingViewModel MyLearningPaging { get; set; }
60+
61+
/// <summary>
62+
/// sets the list of type checkboxes.
63+
/// </summary>
64+
/// <returns>The <see cref="List{CheckboxListItemViewModel}"/>.</returns>
65+
public List<CheckboxListItemViewModel> TypeFilterCheckbox()
66+
{
67+
var checkboxes = new List<CheckboxListItemViewModel>()
68+
{
69+
new CheckboxListItemViewModel("Article", "Article", null),
70+
new CheckboxListItemViewModel("Assessment", "Assessment", null),
71+
new CheckboxListItemViewModel("Audio", "Audio", null),
72+
new CheckboxListItemViewModel("Case", "Case", null),
73+
new CheckboxListItemViewModel("Elearning", "elearning", null),
74+
new CheckboxListItemViewModel("File", "File", null),
75+
new CheckboxListItemViewModel("Html", "HTML", null),
76+
new CheckboxListItemViewModel("Image", "Image", null),
77+
new CheckboxListItemViewModel("Video", "Video", null),
78+
new CheckboxListItemViewModel("Weblink", "Weblink", null),
79+
new CheckboxListItemViewModel("Courses", "Courses", null),
80+
};
81+
return checkboxes;
82+
}
83+
}
84+
}

LearningHub.Nhs.WebUI/Models/SideMenu/SideNavigationConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static IEnumerable<SideNavigationGroup> GetGroupedMenus()
7777
Text = "Certificates",
7878
Controller = "MyLearning",
7979
Action = "Certificates",
80-
IsActive = route => MatchRoute(route, "Activity", "Certificates"),
80+
IsActive = route => MatchRoute(route, "MyLearning", "Certificates"),
8181
},
8282
new SideNavigationItem
8383
{

LearningHub.Nhs.WebUI/Services/MyLearningService.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Net.Http;
66
using System.Text;
77
using System.Threading.Tasks;
8-
using elfhHub.Nhs.Models.Common;
98
using LearningHub.Nhs.Models.MyLearning;
109
using LearningHub.Nhs.WebUI.Configuration;
1110
using LearningHub.Nhs.WebUI.Interfaces;
@@ -189,6 +188,38 @@ public async Task<Tuple<int, MyLearningDetailedItemViewModel>> GetResourceCertif
189188
return viewModel;
190189
}
191190

191+
/// <summary>
192+
/// Gets the user certificates.
193+
/// </summary>
194+
/// <param name="requestModel">The request model.</param>
195+
/// <returns>The <see cref="Task"/>.</returns>
196+
public async Task<MyLearningCertificatesDetailedViewModel> GetUserCertificateDetails(MyLearningRequestModel requestModel)
197+
{
198+
MyLearningCertificatesDetailedViewModel viewModel = null;
199+
200+
var json = JsonConvert.SerializeObject(requestModel);
201+
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
202+
203+
var client = await this.OpenApiHttpClient.GetClientAsync();
204+
205+
var request = $"MyLearning/GetUserCertificateDetails";
206+
var response = await client.PostAsync(request, stringContent).ConfigureAwait(false);
207+
208+
if (response.IsSuccessStatusCode)
209+
{
210+
var result = response.Content.ReadAsStringAsync().Result;
211+
viewModel = JsonConvert.DeserializeObject<MyLearningCertificatesDetailedViewModel>(result);
212+
}
213+
else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized
214+
||
215+
response.StatusCode == System.Net.HttpStatusCode.Forbidden)
216+
{
217+
throw new Exception("AccessDenied");
218+
}
219+
220+
return viewModel;
221+
}
222+
192223
/// <summary>
193224
/// GetCourseUrl.
194225
/// </summary>

LearningHub.Nhs.WebUI/Styles/nhsuk/pages/mylearning.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@
196196
}
197197
}
198198

199+
.nhsuk-card--radius-6 {
200+
border-radius: 6px;
201+
overflow: hidden;
202+
}
203+
204+
.nhsuk-card__heading.nhsuk-heading-m.nhsuk-font-weight-regular {
205+
font-weight: 400 !important;
206+
}
207+
199208
label {
200209
font-family: $font-stack;
201210
}

0 commit comments

Comments
 (0)