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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ obj
/AdminUI/LearningHub.Nhs.AdminUI/web.config
/LearningHub.Nhs.WebUI/web.config
/WebAPI/LearningHub.Nhs.API/web.config
/LearningHub.Nhs.WebUI/nuget.config
/LearningHub.Nhs.WebUI.BlazorClient/Properties/launchSettings.json
/LearningHub.Nhs.WebUI.BlazorClient/wwwroot/appsettings.json
/LearningHub.Nhs.WebUI.BlazorClient/wwwroot/appsettings.Development.json
/LearningHub.Nhs.WebUI.BlazorClient/nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// Contains only non-sensitive data such as page sizes for various search types.
/// </para>
/// </summary>
public class FindwiseSettingsPublic : IFindwiseSettingsPublic
public class ExposableFindwiseSettings : IExposableFindwiseSettings
{
/// <summary>
/// Gets or sets the ResourceSearchPageSize.
Expand Down
36 changes: 36 additions & 0 deletions LearningHub.Nhs.Shared/Configuration/ExposableSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace LearningHub.Nhs.Shared.Configuration
{
using LearningHub.Nhs.Shared.Interfaces.Configuration;
/// <summary>
/// Represents configuration values that are safe to expose to clientside frontend applications
/// (such as Blazor WebAssembly) or public-facing APIs.
///
/// <para>
/// Implements <see cref="IExposableSettings"/> and contains only non-sensitive, non-secret
/// values such as public API endpoints and pagination settings. This separation ensures
/// that secure or private configuration data is not inadvertently exposed to clients.
/// </para>
/// </summary>
public class ExposableSettings : IExposableSettings
{
/// <inheritdoc/>
public string LearningHubApiUrl { get; set; }

/// <summary>
/// Gets or sets the UserApiUrl.
/// </summary>
public string UserApiUrl { get; set; }

/// <summary>
/// Gets or sets the OpenApiUrl.
/// </summary>
public string OpenApiUrl { get; set; }
/// <summary>
/// Backend for Frontend (BFF) URL for the Learning Hub API accessed by samesite cookie and uses httpclients with bearers to access external apis.
/// </summary>
public string LearningHubApiBFFUrl { get; set; }
/// <inheritdoc/>
public IExposableFindwiseSettings FindwiseSettings { get; set; }

}
}
31 changes: 0 additions & 31 deletions LearningHub.Nhs.Shared/Configuration/PublicSettings.cs

This file was deleted.

61 changes: 61 additions & 0 deletions LearningHub.Nhs.Shared/Helpers/FormattingHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearningHub.Nhs.Shared.Helpers
{
public static class FormattingHelper
{

/// <summary>
/// Returns a number of milliseconds converted into a duration string, such as "10 min 15 sec". Includes rounding to match the behaviour of the Azure Media Player.
/// </summary>
/// <param name="durationInMilliseconds">The number of milliseconds.</param>
/// <returns>The duration string.</returns>
public static string GetDurationText(int durationInMilliseconds)
{
if (durationInMilliseconds > 0)
{
// Azure media player rounds duration to nearest second. e.g. 8:59.88 becomes 9:00. LH needs to match.
int nearestSecond = (int)Math.Round(((double)durationInMilliseconds) / 1000);
var duration = new TimeSpan(0, 0, nearestSecond);
string returnValue = string.Empty;

// If duration greater than an hour, don't return the seconds part.
if (duration.Hours > 0)
{
returnValue = $"{duration.Hours} hr {duration.Minutes} min ";

// Exclude "0 min" from the return value.
if (returnValue.EndsWith(" 0 min "))
{
returnValue = returnValue.Replace("0 min ", string.Empty);
}
}
else
{
returnValue = $"{duration.Minutes} min {duration.Seconds} sec ";

// Exclude "0 min" and "0 sec" from the return value.
if (returnValue.StartsWith("0 min "))
{
returnValue = returnValue.Replace("0 min ", string.Empty);
}

if (returnValue.EndsWith(" 0 sec "))
{
returnValue = returnValue.Replace("0 sec ", string.Empty);
}
}

return returnValue;
}
else
{
return string.Empty;
}
}
}
}
115 changes: 115 additions & 0 deletions LearningHub.Nhs.Shared/Helpers/MoodleHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using LearningHub.Nhs.Models.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearningHub.Nhs.Shared.Helpers
{
public static class MoodleHelper
{
/// TODO: Remove this method after adding to Moodle resource types to models project.
/// <summary>
/// Returns a prettified resource type name, suitable for display in the UI. Includes video/audio duration string.
/// </summary>
/// <param name="resourceType">The resource type.</param>
/// <param name="durationInMilliseconds">The media duration in milliseconds.</param>
/// <returns>The resource type name, and duration if applicable.</returns>
public static string GetPrettifiedResourceTypeNameMoodle(ResourceTypeEnum resourceType, int? durationInMilliseconds = 0)
{
switch (resourceType)
{
case ResourceTypeEnum.Assessment:
return "Assessment";
case ResourceTypeEnum.Article:
return "Article";
case ResourceTypeEnum.Audio:
string durationText = FormattingHelper.GetDurationText(durationInMilliseconds ?? 0);
durationText = string.IsNullOrEmpty(durationText) ? string.Empty : " - " + durationText;
return "Audio" + durationText;
case ResourceTypeEnum.Equipment:
return "Equipment";
case ResourceTypeEnum.Image:
return "Image";
case ResourceTypeEnum.Scorm:
return "elearning";
case ResourceTypeEnum.Video:
durationText = FormattingHelper.GetDurationText(durationInMilliseconds ?? 0);
durationText = string.IsNullOrEmpty(durationText) ? string.Empty : " - " + durationText;
return "Video" + durationText;
case ResourceTypeEnum.WebLink:
return "Web link";
case ResourceTypeEnum.GenericFile:
return "File";
case ResourceTypeEnum.Embedded:
return "Embedded";
case ResourceTypeEnum.Case:
return "Case";
case ResourceTypeEnum.Html:
return "HTML";
case ResourceTypeEnum.Moodle:
return "Course";
default:
return "File";
}
}

/// TODO: Remove this method after adding to Moodle resource types to models project.
/// <summary>
/// Findwise Moodle resource type dictionary.
/// </summary>
public static readonly Dictionary<string, ResourceTypeEnum> FindwiseResourceMoodleTypeDict = new Dictionary<string, ResourceTypeEnum>()
{
{ "video", ResourceTypeEnum.Video },
{ "article", ResourceTypeEnum.Article },
{ "case", ResourceTypeEnum.Case },
{ "weblink", ResourceTypeEnum.WebLink },
{ "audio", ResourceTypeEnum.Audio },
{ "scorm", ResourceTypeEnum.Scorm },
{ "assessment", ResourceTypeEnum.Assessment },
{ "genericfile", ResourceTypeEnum.GenericFile },
{ "image", ResourceTypeEnum.Image },
{ "html", ResourceTypeEnum.Html },
{ "moodle", ResourceTypeEnum.Moodle },
};

/// <summary>
/// Returns a prettified resource type name, suitable for display in the UI. Excludes video/audio duration string.
/// </summary>
/// <param name="resourceType">The resource type.</param>
/// <returns>The resource type name, and duration if applicable.</returns>
public static string GetPrettifiedResourceTypeName(ResourceTypeEnum resourceType)
{
switch (resourceType)
{
case ResourceTypeEnum.Assessment:
return "Assessment";
case ResourceTypeEnum.Article:
return "Article";
case ResourceTypeEnum.Audio:
return "Audio";
case ResourceTypeEnum.Equipment:
return "Equipment";
case ResourceTypeEnum.Image:
return "Image";
case ResourceTypeEnum.Scorm:
return "elearning";
case ResourceTypeEnum.Video:
return "Video";
case ResourceTypeEnum.WebLink:
return "Web link";
case ResourceTypeEnum.GenericFile:
return "File";
case ResourceTypeEnum.Embedded:
return "Embedded";
case ResourceTypeEnum.Case:
return "Case";
case ResourceTypeEnum.Html:
return "HTML";
default:
return "File";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// It does not contain any secure credentials or internal service configuration.
/// </para>
/// </summary>
public interface IFindwiseSettingsPublic
public interface IExposableFindwiseSettings
{
/// <summary>
/// Gets or sets the page size for resource search results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@
/// without risking exposure of sensitive information.
/// </para>
/// </summary>
public interface IPublicSettings
public interface IExposableSettings
{
/// <summary>
/// Gets or sets the LearningHubApiUrl.
/// </summary>
public string LearningHubApiUrl { get; set; }

public IFindwiseSettingsPublic FindwiseSettings { get; set; }
/// <summary>
/// Gets or sets the UserApiUrl.
/// </summary>
public string UserApiUrl { get; set; }

/// <summary>
/// Gets or sets the OpenApiUrl.
/// </summary>
public string OpenApiUrl { get; set; }
/// <summary>
/// Gets or sets the LearningHubApiBFFUrl used to proxy via same domain cookie to the BFF LearningHubAPI calls.
/// </summary>
public string LearningHubApiBFFUrl { get; set; }

public IExposableFindwiseSettings FindwiseSettings { get; set; }
}
}
12 changes: 7 additions & 5 deletions LearningHub.Nhs.Shared/LearningHub.Nhs.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.50" />
<Folder Include="Models\Contribute\" />
<Folder Include="Models\Paging\" />
</ItemGroup>

<ItemGroup>
<Folder Include="Models\Contribute\" />
<Folder Include="Models\Paging\" />
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.2" />
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.50" />
</ItemGroup>

</Project>


Loading
Loading