diff --git a/.github/workflows/admin.yaml b/.github/workflows/admin.yaml index 0e1017f..28c9fae 100644 --- a/.github/workflows/admin.yaml +++ b/.github/workflows/admin.yaml @@ -4,12 +4,14 @@ on: push: paths: - 'admin/**' + - '2wr-app/public/images/**' - 'TwoWeeksReady.Common/**' - '.github/workflows/admin.yaml' branches: [ master ] pull_request: paths: - 'admin/**' + - '2wr-app/public/images/**' - '.github/workflows/admin.yaml' branches: [ master ] workflow_dispatch: diff --git a/.gitignore b/.gitignore index 0703826..cf346a0 100644 --- a/.gitignore +++ b/.gitignore @@ -353,3 +353,4 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ /lambda/*.zip +admin/TwoWeeksReady.Admin/client-images.txt diff --git a/admin/TwoWeeksReady.Admin/Data/ClientImage.cs b/admin/TwoWeeksReady.Admin/Data/ClientImage.cs new file mode 100644 index 0000000..202c613 --- /dev/null +++ b/admin/TwoWeeksReady.Admin/Data/ClientImage.cs @@ -0,0 +1,8 @@ +namespace TwoWeeksReady.Admin.Data +{ + public class ClientImage + { + public string RelativePath { get; set; } + public string AbsolutePath { get; set; } + } +} diff --git a/admin/TwoWeeksReady.Admin/Data/ClientImageService.cs b/admin/TwoWeeksReady.Admin/Data/ClientImageService.cs new file mode 100644 index 0000000..7bcca0e --- /dev/null +++ b/admin/TwoWeeksReady.Admin/Data/ClientImageService.cs @@ -0,0 +1,46 @@ +using Microsoft.Extensions.Configuration; +using System.IO; +using System.Linq; + +namespace TwoWeeksReady.Admin.Data +{ + /// + /// Provides a list of image that are available within the 2wr client app. + /// These are use in Hazard Info and in Base Kits + /// + public class ClientImageService + { + public readonly IConfiguration _configuration; + public readonly ClientImage[] clientImages; + + public ClientImageService(IConfiguration configuration) + { + _configuration = configuration; + + var imagePaths = File.ReadAllLines("./client-images.txt"); + var appUrl = _configuration["2wrAppUrl"].TrimEnd('/'); + + clientImages = imagePaths + .Select(i => i.Replace("\\", "/")) + .Select(i => new ClientImage + { + AbsolutePath = ToAbsolutePath(i), + RelativePath = i + }).ToArray(); + } + + + public ClientImage[] Images => clientImages; + + public string ToAbsolutePath(string relativeImagePath) + { + var appUrl = _configuration["2wrAppUrl"].TrimEnd('/'); + if (string.IsNullOrEmpty(relativeImagePath)) + { + return appUrl; + } + + return $"{appUrl}/{relativeImagePath.TrimStart('/')}"; + } + } +} diff --git a/admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor b/admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor index cd6ce55..6a1078d 100644 --- a/admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor +++ b/admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor @@ -3,9 +3,13 @@ @attribute [Authorize(Roles = "admin")] @using TinyMCE.Blazor +@using System.IO; +@using System.Linq; + @inject IRepository repository @inject IJSRuntime JS @inject Microsoft.Extensions.Configuration.IConfiguration configuration +@inject ClientImageService clientImages @{ var tinyMCEApiKey = configuration["TinyMCEApiKey"]; @@ -19,7 +23,7 @@ else {

Details

-
+
@@ -30,11 +34,25 @@ else
- + + + @foreach(var image in clientImages.Images) + { + + } + + +
- + + @foreach(var image in clientImages.Images) + { + + } + +
@@ -59,21 +77,15 @@ else
- +
} @code { public Dictionary EditorConfig = new Dictionary -{ + { { "plugins", "image" }, { "toolbar", "image" }, - {"image_list", new [] - { - // TODO: Figure out a strategy for loading a list of images from assets availabe within the app - new { title = "Image 1", value = "http://localhost:8080/images/hazards/earthquake.png"} - } } - }; [Parameter] @@ -103,13 +115,12 @@ else if (string.IsNullOrEmpty(Id)) { Hazard = new HazardInfo(); - } else { Hazard = await repository.GetHazardInfoById(Id); } - + EditorConfig["image_list"] = clientImages.Images.Select(i => new { title = i.RelativePath, value = i.AbsolutePath }).ToArray(); } diff --git a/admin/TwoWeeksReady.Admin/Startup.cs b/admin/TwoWeeksReady.Admin/Startup.cs index 615d905..4e96986 100644 --- a/admin/TwoWeeksReady.Admin/Startup.cs +++ b/admin/TwoWeeksReady.Admin/Startup.cs @@ -115,6 +115,7 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); //services.AddScoped(); services.AddScoped(); + services.AddSingleton(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj b/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj index f0ae042..f25e619 100644 --- a/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj +++ b/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj @@ -1,17 +1,41 @@  - - net5.0 - 4c82d094-3afe-4274-922b-9c0d8bdda7c5 - + + net5.0 + 4c82d094-3afe-4274-922b-9c0d8bdda7c5 + - - - + + + Always + + - - - - + + + - + + + + + + + + + + + + + + + + + + %(ClientImages.Identity) + $([MSBuild]::Add($(ClientImage.IndexOf(`2wr-app`)), 14)) + + + + + \ No newline at end of file diff --git a/admin/TwoWeeksReady.Admin/appsettings.json b/admin/TwoWeeksReady.Admin/appsettings.json index 0106276..8eb5547 100644 --- a/admin/TwoWeeksReady.Admin/appsettings.json +++ b/admin/TwoWeeksReady.Admin/appsettings.json @@ -9,6 +9,7 @@ "AllowedHosts": "*", "TinyMCEApiKey": "your-api-key", "ApiUrl": "http://localhost:7071/api/", + "2wrAppUrl": "http://localhost:8080/", "Auth0": { "Domain": "YOUR_AUTH0_DOMAIN", "ClientId": "YOUR_CLIENT_ID",