Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
21 changes: 13 additions & 8 deletions LearningHub.Nhs.Shared/Configuration/PublicSettings.cs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous pr created public setting so dont worry what is added or lost its the bff end point that is relevant

Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ public class PublicSettings : IPublicSettings
/// <inheritdoc/>
public string LearningHubApiUrl { get; set; }

/// <inheritdoc/>
public int ResourceSearchPageSize { get; set; }

/// <inheritdoc/>
public int CatalogueSearchPageSize { get; set; }

/// <inheritdoc/>
public int AllCatalogueSearchPageSize { 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 IFindwiseSettingsPublic FindwiseSettings { get; set; }

}
}
61 changes: 61 additions & 0 deletions LearningHub.Nhs.Shared/Helpers/FormattingHelper.cs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is things being pulled into shared to support searchservice

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a new and temporary file i think, but needed to move it to support search

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";
}
}
}
}
14 changes: 14 additions & 0 deletions LearningHub.Nhs.Shared/Interfaces/Configuration/IPublicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ public interface IPublicSettings
/// </summary>
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>
/// Gets or sets the LearningHubApiBFFUrl used to proxy via same domain cookie to the BFF LearningHubAPI calls.
/// </summary>
public string LearningHubApiBFFUrl { get; set; }

public IFindwiseSettingsPublic 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>


12 changes: 0 additions & 12 deletions LearningHub.Nhs.Shared/Models/Search/SearchRequestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;//qqqq
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a good example of how we can easily move aspnetcore.mvc it just moves to the presentation layer the controller uses it and it should work


/// <summary>
/// Defines the <see cref="SearchRequestViewModel" />.
Expand All @@ -13,67 +12,56 @@ public class SearchRequestViewModel
/// Gets or sets the search string.
/// </summary>
[Required(ErrorMessage = "Search text is required")]
[FromQuery]
public string Term { get; set; }

/// <summary>
/// Gets or sets the filters.
/// </summary>
[FromQuery]
public IEnumerable<string> Filters { get; set; }

/// <summary>
/// Gets or sets the sort item index.
/// </summary>
[FromQuery]
public int? Sortby { get; set; }

/// <summary>
/// Gets or sets the catalogue current page index.
/// </summary>
[FromQuery]
public int? CataloguePageIndex { get; set; }

/// <summary>
/// Gets or sets the resource current page index.
/// </summary>
[FromQuery]
public int? ResourcePageIndex { get; set; }

/// <summary>
/// Gets or sets the group id.
/// </summary>
[FromQuery]
public string GroupId { get; set; }

/// <summary>
/// Gets or sets a value indicating whether gets or sets the feedback submitted.
/// </summary>
[FromQuery]
public bool? FeedbackSubmitted { get; set; }

/// <summary>
/// Gets or sets the search id.
/// </summary>
[FromQuery]
public int? SearchId { get; set; }

/// <summary>
/// Gets or sets the catalogue id, when searching within a particular catalogue.
/// </summary>
[FromQuery]
public int? CatalogueId { get; set; }

/// <summary>
/// Gets or sets the resource access level id.
/// </summary>
[FromQuery]
public int? ResourceAccessLevelId { get; set; }

/// <summary>
/// Gets or sets the provider ids.
/// </summary>
[FromQuery]
public IEnumerable<string> ProviderFilters { get; set; }
}
}
7 changes: 3 additions & 4 deletions LearningHub.Nhs.Shared/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using LearningHub.Nhs.Shared.Interfaces.Http;
using LearningHub.Nhs.Shared.Interfaces.Services;
using LearningHub.Nhs.Shared.Models.Search;
using LearningHub.Nhs.WebUI.Helpers;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
Expand Down Expand Up @@ -170,10 +169,10 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
{
var filter = filters.Where(x => x.DisplayName == filteritem).FirstOrDefault();

if (filter != null && UtilityHelper.FindwiseResourceMoodleTypeDict.ContainsKey(filter.DisplayName))
if (filter != null && MoodleHelper.FindwiseResourceMoodleTypeDict.ContainsKey(filter.DisplayName))
{
var resourceTypeEnum = UtilityHelper.FindwiseResourceMoodleTypeDict[filter.DisplayName];
var searchfilter = new SearchFilterModel() { DisplayName = UtilityHelper.GetPrettifiedResourceTypeNameMoodle(resourceTypeEnum), Count = filter.Count, Value = filteritem, Selected = searchRequest.Filters?.Contains(filter.DisplayName) ?? false };
var resourceTypeEnum = MoodleHelper.FindwiseResourceMoodleTypeDict[filter.DisplayName];
var searchfilter = new SearchFilterModel() { DisplayName = MoodleHelper.GetPrettifiedResourceTypeNameMoodle(resourceTypeEnum), Count = filter.Count, Value = filteritem, Selected = searchRequest.Filters?.Contains(filter.DisplayName) ?? false };
searchfilters.Add(searchfilter);
}
}
Expand Down
30 changes: 30 additions & 0 deletions LearningHub.Nhs.WebUI.BlazorClient/DI/DI.cs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All this is, is just a little helper to tidy up the repittion of registering different clients that only differ by the appsettings end point value. ... this may end up being different anyway if we look at how we httpclients across top level of solution

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using LearningHub.Nhs.Shared.Configuration;


namespace LearningHub.Nhs.WebUI.BlazorClient.DI
{
public static class DI
{
public static IHttpClientBuilder AddBffHttpClient<TInterface, TImplementation>(this IServiceCollection services, Func<PublicSettings, string> getApiUrl)
where TInterface : class
where TImplementation : class, TInterface
{
return services.AddHttpClient<TInterface, TImplementation>((serviceProvider, client) =>
{
var publicSettings = serviceProvider.GetRequiredService<IOptions<PublicSettings>>().Value;
var apiUrl = getApiUrl(publicSettings);
var apiUri = new Uri(apiUrl);
var apiHost = apiUri.Host;
string forwardSlash = "/";
// Using the Uri class for robust path joining
client.BaseAddress = new Uri($"{publicSettings.LearningHubApiBFFUrl}{apiHost}{forwardSlash}");
});
}
}
}
Loading
Loading