Skip to content

Commit 15f02cf

Browse files
authored
Merge pull request #1314 from TechnologyEnhancedLearning/Develop/Feature/TD-5888-Make-LH-able-to-Host-Blazor
Develop/feature/td 5888 make lh able to host blazor Merging so against one task branch which we will take only certain files from anyway
2 parents 3279ef6 + 1217fba commit 15f02cf

38 files changed

+898
-230
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ obj
5656
/AdminUI/LearningHub.Nhs.AdminUI/web.config
5757
/LearningHub.Nhs.WebUI/web.config
5858
/WebAPI/LearningHub.Nhs.API/web.config
59+
/LearningHub.Nhs.WebUI/nuget.config
60+
/LearningHub.Nhs.WebUI.BlazorClient/Properties/launchSettings.json
61+
/LearningHub.Nhs.WebUI.BlazorClient/wwwroot/appsettings.json
62+
/LearningHub.Nhs.WebUI.BlazorClient/wwwroot/appsettings.Development.json
63+
/LearningHub.Nhs.WebUI.BlazorClient/nuget.config

LearningHub.Nhs.Shared/Configuration/FindwiseSettingsPublic.cs renamed to LearningHub.Nhs.Shared/Configuration/ExposableFindwiseSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// Contains only non-sensitive data such as page sizes for various search types.
1010
/// </para>
1111
/// </summary>
12-
public class FindwiseSettingsPublic : IFindwiseSettingsPublic
12+
public class ExposableFindwiseSettings : IExposableFindwiseSettings
1313
{
1414
/// <summary>
1515
/// Gets or sets the ResourceSearchPageSize.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace LearningHub.Nhs.Shared.Configuration
2+
{
3+
using LearningHub.Nhs.Shared.Interfaces.Configuration;
4+
/// <summary>
5+
/// Represents configuration values that are safe to expose to clientside frontend applications
6+
/// (such as Blazor WebAssembly) or public-facing APIs.
7+
///
8+
/// <para>
9+
/// Implements <see cref="IExposableSettings"/> and contains only non-sensitive, non-secret
10+
/// values such as public API endpoints and pagination settings. This separation ensures
11+
/// that secure or private configuration data is not inadvertently exposed to clients.
12+
/// </para>
13+
/// </summary>
14+
public class ExposableSettings : IExposableSettings
15+
{
16+
/// <inheritdoc/>
17+
public string LearningHubApiUrl { get; set; }
18+
19+
/// <summary>
20+
/// Gets or sets the UserApiUrl.
21+
/// </summary>
22+
public string UserApiUrl { get; set; }
23+
24+
/// <summary>
25+
/// Gets or sets the OpenApiUrl.
26+
/// </summary>
27+
public string OpenApiUrl { get; set; }
28+
/// <summary>
29+
/// Backend for Frontend (BFF) URL for the Learning Hub API accessed by samesite cookie and uses httpclients with bearers to access external apis.
30+
/// </summary>
31+
public string LearningHubApiBFFUrl { get; set; }
32+
/// <inheritdoc/>
33+
public IExposableFindwiseSettings FindwiseSettings { get; set; }
34+
35+
}
36+
}

LearningHub.Nhs.Shared/Configuration/PublicSettings.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace LearningHub.Nhs.Shared.Helpers
8+
{
9+
public static class FormattingHelper
10+
{
11+
12+
/// <summary>
13+
/// 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.
14+
/// </summary>
15+
/// <param name="durationInMilliseconds">The number of milliseconds.</param>
16+
/// <returns>The duration string.</returns>
17+
public static string GetDurationText(int durationInMilliseconds)
18+
{
19+
if (durationInMilliseconds > 0)
20+
{
21+
// Azure media player rounds duration to nearest second. e.g. 8:59.88 becomes 9:00. LH needs to match.
22+
int nearestSecond = (int)Math.Round(((double)durationInMilliseconds) / 1000);
23+
var duration = new TimeSpan(0, 0, nearestSecond);
24+
string returnValue = string.Empty;
25+
26+
// If duration greater than an hour, don't return the seconds part.
27+
if (duration.Hours > 0)
28+
{
29+
returnValue = $"{duration.Hours} hr {duration.Minutes} min ";
30+
31+
// Exclude "0 min" from the return value.
32+
if (returnValue.EndsWith(" 0 min "))
33+
{
34+
returnValue = returnValue.Replace("0 min ", string.Empty);
35+
}
36+
}
37+
else
38+
{
39+
returnValue = $"{duration.Minutes} min {duration.Seconds} sec ";
40+
41+
// Exclude "0 min" and "0 sec" from the return value.
42+
if (returnValue.StartsWith("0 min "))
43+
{
44+
returnValue = returnValue.Replace("0 min ", string.Empty);
45+
}
46+
47+
if (returnValue.EndsWith(" 0 sec "))
48+
{
49+
returnValue = returnValue.Replace("0 sec ", string.Empty);
50+
}
51+
}
52+
53+
return returnValue;
54+
}
55+
else
56+
{
57+
return string.Empty;
58+
}
59+
}
60+
}
61+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using LearningHub.Nhs.Models.Enums;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace LearningHub.Nhs.Shared.Helpers
9+
{
10+
public static class MoodleHelper
11+
{
12+
/// TODO: Remove this method after adding to Moodle resource types to models project.
13+
/// <summary>
14+
/// Returns a prettified resource type name, suitable for display in the UI. Includes video/audio duration string.
15+
/// </summary>
16+
/// <param name="resourceType">The resource type.</param>
17+
/// <param name="durationInMilliseconds">The media duration in milliseconds.</param>
18+
/// <returns>The resource type name, and duration if applicable.</returns>
19+
public static string GetPrettifiedResourceTypeNameMoodle(ResourceTypeEnum resourceType, int? durationInMilliseconds = 0)
20+
{
21+
switch (resourceType)
22+
{
23+
case ResourceTypeEnum.Assessment:
24+
return "Assessment";
25+
case ResourceTypeEnum.Article:
26+
return "Article";
27+
case ResourceTypeEnum.Audio:
28+
string durationText = FormattingHelper.GetDurationText(durationInMilliseconds ?? 0);
29+
durationText = string.IsNullOrEmpty(durationText) ? string.Empty : " - " + durationText;
30+
return "Audio" + durationText;
31+
case ResourceTypeEnum.Equipment:
32+
return "Equipment";
33+
case ResourceTypeEnum.Image:
34+
return "Image";
35+
case ResourceTypeEnum.Scorm:
36+
return "elearning";
37+
case ResourceTypeEnum.Video:
38+
durationText = FormattingHelper.GetDurationText(durationInMilliseconds ?? 0);
39+
durationText = string.IsNullOrEmpty(durationText) ? string.Empty : " - " + durationText;
40+
return "Video" + durationText;
41+
case ResourceTypeEnum.WebLink:
42+
return "Web link";
43+
case ResourceTypeEnum.GenericFile:
44+
return "File";
45+
case ResourceTypeEnum.Embedded:
46+
return "Embedded";
47+
case ResourceTypeEnum.Case:
48+
return "Case";
49+
case ResourceTypeEnum.Html:
50+
return "HTML";
51+
case ResourceTypeEnum.Moodle:
52+
return "Course";
53+
default:
54+
return "File";
55+
}
56+
}
57+
58+
/// TODO: Remove this method after adding to Moodle resource types to models project.
59+
/// <summary>
60+
/// Findwise Moodle resource type dictionary.
61+
/// </summary>
62+
public static readonly Dictionary<string, ResourceTypeEnum> FindwiseResourceMoodleTypeDict = new Dictionary<string, ResourceTypeEnum>()
63+
{
64+
{ "video", ResourceTypeEnum.Video },
65+
{ "article", ResourceTypeEnum.Article },
66+
{ "case", ResourceTypeEnum.Case },
67+
{ "weblink", ResourceTypeEnum.WebLink },
68+
{ "audio", ResourceTypeEnum.Audio },
69+
{ "scorm", ResourceTypeEnum.Scorm },
70+
{ "assessment", ResourceTypeEnum.Assessment },
71+
{ "genericfile", ResourceTypeEnum.GenericFile },
72+
{ "image", ResourceTypeEnum.Image },
73+
{ "html", ResourceTypeEnum.Html },
74+
{ "moodle", ResourceTypeEnum.Moodle },
75+
};
76+
77+
/// <summary>
78+
/// Returns a prettified resource type name, suitable for display in the UI. Excludes video/audio duration string.
79+
/// </summary>
80+
/// <param name="resourceType">The resource type.</param>
81+
/// <returns>The resource type name, and duration if applicable.</returns>
82+
public static string GetPrettifiedResourceTypeName(ResourceTypeEnum resourceType)
83+
{
84+
switch (resourceType)
85+
{
86+
case ResourceTypeEnum.Assessment:
87+
return "Assessment";
88+
case ResourceTypeEnum.Article:
89+
return "Article";
90+
case ResourceTypeEnum.Audio:
91+
return "Audio";
92+
case ResourceTypeEnum.Equipment:
93+
return "Equipment";
94+
case ResourceTypeEnum.Image:
95+
return "Image";
96+
case ResourceTypeEnum.Scorm:
97+
return "elearning";
98+
case ResourceTypeEnum.Video:
99+
return "Video";
100+
case ResourceTypeEnum.WebLink:
101+
return "Web link";
102+
case ResourceTypeEnum.GenericFile:
103+
return "File";
104+
case ResourceTypeEnum.Embedded:
105+
return "Embedded";
106+
case ResourceTypeEnum.Case:
107+
return "Case";
108+
case ResourceTypeEnum.Html:
109+
return "HTML";
110+
default:
111+
return "File";
112+
}
113+
}
114+
}
115+
}

LearningHub.Nhs.Shared/Interfaces/Configuration/IFindwiseSettingsPublic.cs renamed to LearningHub.Nhs.Shared/Interfaces/Configuration/IExposableFindwiseSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// It does not contain any secure credentials or internal service configuration.
1010
/// </para>
1111
/// </summary>
12-
public interface IFindwiseSettingsPublic
12+
public interface IExposableFindwiseSettings
1313
{
1414
/// <summary>
1515
/// Gets or sets the page size for resource search results.

LearningHub.Nhs.Shared/Interfaces/Configuration/IPublicSettings.cs renamed to LearningHub.Nhs.Shared/Interfaces/Configuration/IExposableSettings.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@
1616
/// without risking exposure of sensitive information.
1717
/// </para>
1818
/// </summary>
19-
public interface IPublicSettings
19+
public interface IExposableSettings
2020
{
2121
/// <summary>
2222
/// Gets or sets the LearningHubApiUrl.
2323
/// </summary>
2424
public string LearningHubApiUrl { get; set; }
2525

26-
public IFindwiseSettingsPublic FindwiseSettings { get; set; }
26+
/// <summary>
27+
/// Gets or sets the UserApiUrl.
28+
/// </summary>
29+
public string UserApiUrl { get; set; }
30+
31+
/// <summary>
32+
/// Gets or sets the OpenApiUrl.
33+
/// </summary>
34+
public string OpenApiUrl { get; set; }
35+
/// <summary>
36+
/// Gets or sets the LearningHubApiBFFUrl used to proxy via same domain cookie to the BFF LearningHubAPI calls.
37+
/// </summary>
38+
public string LearningHubApiBFFUrl { get; set; }
39+
40+
public IExposableFindwiseSettings FindwiseSettings { get; set; }
2741
}
2842
}

LearningHub.Nhs.Shared/LearningHub.Nhs.Shared.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
11-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.50" />
10+
<Folder Include="Models\Contribute\" />
11+
<Folder Include="Models\Paging\" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<Folder Include="Models\Contribute\" />
16-
<Folder Include="Models\Paging\" />
15+
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.2" />
16+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.50" />
1717
</ItemGroup>
18-
18+
1919
</Project>
20+
21+

0 commit comments

Comments
 (0)