-
Notifications
You must be signed in to change notification settings - Fork 1
Develop/feature/td 5888 make lh able to host blazor #1314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
bcdff4b
ce07ada
8167a97
edd96ee
f06621f
e8943a6
5505e8d
1217fba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| } | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| { | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.DataAnnotations; | ||
| using Microsoft.AspNetCore.Mvc;//qqqq | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" />. | ||
|
|
@@ -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; } | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}"); | ||
| }); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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