Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
6 changes: 6 additions & 0 deletions LearningHub.Nhs.WebUI/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.Http;
using LearningHub.Nhs.Models.Extensions;
using LearningHub.Nhs.WebUI.Configuration;
using LearningHub.Nhs.WebUI.Extensions;
using LearningHub.Nhs.WebUI.Filters;
using LearningHub.Nhs.WebUI.Helpers;
using LearningHub.Nhs.WebUI.Models;
Expand Down Expand Up @@ -76,6 +77,11 @@ protected BaseController(
/// </summary>
protected int CurrentUserId => this.User.Identity.GetCurrentUserId();

/// <summary>
/// Gets the CurrentUserId.
/// </summary>
protected int CurrentMoodleUserId => this.User.Identity.GetMoodleUserId();

/// <summary>
/// The OnActionExecuting.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions LearningHub.Nhs.WebUI/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,22 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
var resourcesTask = this.dashboardService.GetResourcesAsync(resourceDashboard, 1);
var cataloguesTask = this.dashboardService.GetCataloguesAsync(catalogueDashboard, 1);

var enrolledCoursesTask = Task.FromResult(new List<MoodleCourseResponseViewModel>());
var enableMoodle = Task.Run(() => this.featureManager.IsEnabledAsync(FeatureFlags.EnableMoodle)).Result;
this.ViewBag.EnableMoodle = enableMoodle;
if (enableMoodle && myLearningDashboard == "my-enrolled-courses")
{
enrolledCoursesTask = this.dashboardService.GetEnrolledCoursesFromMoodleAsync(this.CurrentMoodleUserId, 1);
}

await Task.WhenAll(learningTask, resourcesTask, cataloguesTask);

var model = new DashboardViewModel()
{
MyLearnings = await learningTask,
Resources = await resourcesTask,
Catalogues = await cataloguesTask,
EnrolledCourses = await enrolledCoursesTask,
};

if (!string.IsNullOrEmpty(this.Request.Query["preview"]) && Convert.ToBoolean(this.Request.Query["preview"]))
Expand Down
17 changes: 17 additions & 0 deletions LearningHub.Nhs.WebUI/Extensions/ClaimsPrincipalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Security.Claims;
using System.Security.Principal;

/// <summary>
/// Defines the <see cref="ClaimsPrincipalExtensions" />.
Expand All @@ -23,5 +24,21 @@ public static string GetTimezoneOffsetCacheKey(this ClaimsPrincipal claimsPrinci

return $"usr_{userId}_tz";
}

/// <summary>
/// Get MoodleUserId.
/// </summary>
/// <param name="identity">The identity.</param>
/// <returns>The System.Int32.</returns>
public static int GetMoodleUserId(this IIdentity identity)
{
Claim claim = (identity as ClaimsIdentity)?.FindFirst("moodle_username");
if (claim != null)
{
return int.Parse(claim.Value);
}

return 0;
}
}
}
5 changes: 5 additions & 0 deletions LearningHub.Nhs.WebUI/Helpers/FeatureFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public static class FeatureFlags
/// The DisplayAudioVideoResource.
/// </summary>
public const string DisplayAudioVideoResource = "DisplayAudioVideoResource";

/// <summary>
/// The EnableMoodle.
/// </summary>
public const string EnableMoodle = "EnableMoodle";
}
}
9 changes: 9 additions & 0 deletions LearningHub.Nhs.WebUI/Interfaces/IDashboardService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace LearningHub.Nhs.WebUI.Interfaces
{
using System.Collections.Generic;
using System.Threading.Tasks;
using LearningHub.Nhs.Models.Dashboard;
using LearningHub.Nhs.WebUI.Models;
Expand Down Expand Up @@ -39,5 +40,13 @@ public interface IDashboardService
/// <param name="dashboardEventViewModel">dashboardEventViewModel.</param>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
Task RecordDashBoardEventAsync(DashboardEventViewModel dashboardEventViewModel);

/// <summary>
/// GetEnrolledCoursesFromMoodleAsync.
/// </summary>
/// <param name="currentUserId">The current User Id type.</param>
/// <param name="pageNumber">The page Number.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
Task<List<MoodleCourseResponseViewModel>> GetEnrolledCoursesFromMoodleAsync(int currentUserId, int pageNumber);
}
}
30 changes: 30 additions & 0 deletions LearningHub.Nhs.WebUI/Interfaces/IMoodleApiService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace LearningHub.Nhs.WebUI.Interfaces
{
using System.Collections.Generic;
using System.Threading.Tasks;
using LearningHub.Nhs.Models.Dashboard;
using LearningHub.Nhs.WebUI.Models;

/// <summary>
/// IMoodleApiService.
/// </summary>
public interface IMoodleApiService
{
/// <summary>
/// GetEnrolledCoursesAsync.
/// </summary>
/// <param name="currentUserId">Moodle user id.</param>
/// <param name="pageNumber">pageNumber.</param>
/// <returns> List of MoodleCourseResponseViewModel.</returns>
Task<List<MoodleCourseResponseViewModel>> GetEnrolledCoursesAsync(int currentUserId, int pageNumber);

/// <summary>
/// GetEnrolledCoursesAsync.
/// </summary>
/// <param name="userId">Moodle user id.</param>
/// <param name="courseId">Moodle course id.</param>
/// <param name="pageNumber">pageNumber.</param>
/// <returns> List of MoodleCourseResponseViewModel.</returns>
Task<MoodleCourseCompletionViewModel> GetCourseCompletionAsync(int userId, int courseId, int pageNumber);
}
}
23 changes: 23 additions & 0 deletions LearningHub.Nhs.WebUI/Interfaces/IMoodleHttpClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace LearningHub.Nhs.Services.Interface
{
using System.Net.Http;
using System.Threading.Tasks;

/// <summary>
/// The Moodle Http Client interface.
/// </summary>
public interface IMoodleHttpClient
{
/// <summary>
/// The get cient async.
/// </summary>
/// <returns>The <see cref="Task"/>.</returns>
Task<HttpClient> GetClient();

/// <summary>
/// GetDefaultParameters.
/// </summary>
/// <returns>defaultParameters.</returns>
string GetDefaultParameters();
}
}
6 changes: 6 additions & 0 deletions LearningHub.Nhs.WebUI/Models/DashboardViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace LearningHub.Nhs.WebUI.Models
{
using System.Collections.Generic;
using LearningHub.Nhs.Models.Dashboard;

/// <summary>
Expand Down Expand Up @@ -28,5 +29,10 @@ public DashboardViewModel()
/// Gets or sets a list of catalogues to be displayed in the dashboard.
/// </summary>
public DashboardCatalogueResponseViewModel Catalogues { get; set; }

/// <summary>
/// Gets or sets a list of enrolled courses to be displayed in the dashboard.
/// </summary>
public List<MoodleCourseResponseViewModel> EnrolledCourses { get; set; }
}
}
28 changes: 28 additions & 0 deletions LearningHub.Nhs.WebUI/Models/MoodleCompletionResponseViewModel.cs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this model class to LH Model Repo?

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace LearningHub.Nhs.WebUI.Models
{
/// <summary>
/// MoodleCompletionResponseViewModel.
/// </summary>
public class MoodleCompletionResponseViewModel
{
/// <summary>
/// Gets or sets the completion status.
/// </summary>
public string Exception { get; set; }

/// <summary>
/// Gets or sets error code.
/// </summary>
public string Errorcode { get; set; }

/// <summary>
/// Gets or sets Error message.
/// </summary>
public string Message { get; set; }

/// <summary>
/// Gets or sets Debug info.
/// </summary>
public string Debuginfo { get; set; }
}
}
103 changes: 103 additions & 0 deletions LearningHub.Nhs.WebUI/Models/MoodleCourseCompletionViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
namespace LearningHub.Nhs.WebUI.Models
{
using System.Collections.Generic;

/// <summary>
/// MoodleCourseCompletionViewModel.
/// </summary>
public class MoodleCourseCompletionViewModel
{
/// <summary>
/// Gets or sets the completion status.
/// </summary>
public CompletStatus CompletionStatus { get; set; }

/// <summary>
/// Gets or sets the list of warnings.
/// </summary>
public List<object> Warnings { get; set; }

/// <summary>
/// CompletionStatus.
/// </summary>
public class CompletStatus
{
/// <summary>
/// Gets or sets a value indicating whether the course is completed.
/// </summary>
public bool Completed { get; set; }

/// <summary>
/// Gets or sets the aggregation method.
/// </summary>
public int Aggregation { get; set; }

/// <summary>
/// Gets or sets the list of completions.
/// </summary>
public List<Completion> Completions { get; set; }

/// <summary>
/// Completion.
/// </summary>
public class Completion
{
/// <summary>
/// Gets or sets the type of completion.
/// </summary>
public int Type { get; set; }

/// <summary>
/// Gets or sets the title of the completion requirement.
/// </summary>
public string Title { get; set; }

/// <summary>
/// Gets or sets the status of the completion.
/// </summary>
public string Status { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the requirement is complete.
/// </summary>
public bool Complete { get; set; }

/// <summary>
/// Gets or sets the timestamp when completion was achieved.
/// </summary>
public long? TimeCompleted { get; set; }

/// <summary>
/// Gets or sets the completion details.
/// </summary>
public CompletionDetails Details { get; set; }

/// <summary>
/// CompletionDetails.
/// </summary>
public class CompletionDetails
{
/// <summary>
/// Gets or sets the type of completion requirement.
/// </summary>
public string Type { get; set; }

/// <summary>
/// Gets or sets the criteria for completion.
/// </summary>
public string Criteria { get; set; }

/// <summary>
/// Gets or sets the requirement for completion.
/// </summary>
public string Requirement { get; set; }

/// <summary>
/// Gets or sets the status of the requirement.
/// </summary>
public string Status { get; set; }
}
}
}
}
}
Loading
Loading