diff --git a/.github/workflows/admin.yaml b/.github/workflows/admin.yaml index 389eb98..0e1017f 100644 --- a/.github/workflows/admin.yaml +++ b/.github/workflows/admin.yaml @@ -4,6 +4,7 @@ on: push: paths: - 'admin/**' + - 'TwoWeeksReady.Common/**' - '.github/workflows/admin.yaml' branches: [ master ] pull_request: diff --git a/.github/workflows/api.yaml b/.github/workflows/api.yaml index af42913..2d69bd8 100644 --- a/.github/workflows/api.yaml +++ b/.github/workflows/api.yaml @@ -4,6 +4,7 @@ on: push: paths: - 'api/**' + - 'TwoWeeksReady.Common/**' - '.github/workflows/api.yaml' branches: [ master ] pull_request: diff --git a/admin/TwoWeeksReady.Admin/Data/FunctionsRepository.cs b/admin/TwoWeeksReady.Admin/Data/FunctionsRepository.cs index af72b1d..3507f5c 100644 --- a/admin/TwoWeeksReady.Admin/Data/FunctionsRepository.cs +++ b/admin/TwoWeeksReady.Admin/Data/FunctionsRepository.cs @@ -47,14 +47,7 @@ public Task GetHazardHuntById(string id) public async Task GetHazardInfoById(string id) { - try - { - return await _httpClient.GetFromJsonAsync($"hazardinfo-by-id/{id}"); - } catch (Exception ex) - { - return new HazardInfo(); - } - + return await _httpClient.GetFromJsonAsync($"hazardinfo-by-id/{id}"); } public Task SaveBaseKitItem(BaseKitItem kit) @@ -67,9 +60,30 @@ public Task SaveHazardHunt(HazardHunt hazardHunt) throw new NotImplementedException(); } - public Task SaveHazardInfo(HazardInfo hazardInfo) + public async Task SaveHazardInfo(HazardInfo hazardInfo) { - throw new NotImplementedException(); + var response = await _httpClient.PutAsJsonAsync("hazardinfo-update", hazardInfo); + if (response.IsSuccessStatusCode) + { + return await response.Content.ReadFromJsonAsync(); + } + else + { + throw new Exception("Error saving hazard info"); + } + } + + public async Task CreateHazardInfo(HazardInfo hazardInfo) + { + var response = await _httpClient.PostAsJsonAsync("hazardinfo-create", hazardInfo); + if (response.IsSuccessStatusCode) + { + return await response.Content.ReadFromJsonAsync(); + } + else + { + throw new Exception("Error saving hazard info"); + } } } } diff --git a/admin/TwoWeeksReady.Admin/Data/IRepository.cs b/admin/TwoWeeksReady.Admin/Data/IRepository.cs index 10975aa..210f445 100644 --- a/admin/TwoWeeksReady.Admin/Data/IRepository.cs +++ b/admin/TwoWeeksReady.Admin/Data/IRepository.cs @@ -23,7 +23,9 @@ public interface IRepository Task GetHazardInfoById(string id); - Task SaveHazardInfo(HazardInfo hazardInfo); + Task SaveHazardInfo(HazardInfo hazardInfo); + + Task CreateHazardInfo(HazardInfo hazardInfo); } } diff --git a/admin/TwoWeeksReady.Admin/Data/StubRepository.cs b/admin/TwoWeeksReady.Admin/Data/StubRepository.cs index 8853357..ecd131e 100644 --- a/admin/TwoWeeksReady.Admin/Data/StubRepository.cs +++ b/admin/TwoWeeksReady.Admin/Data/StubRepository.cs @@ -103,6 +103,13 @@ public Task SaveHazardInfo(HazardInfo hazardInfo) { return Task.FromResult(hazardInfo); } + + public Task CreateHazardInfo(HazardInfo hazardInfo) + { + return Task.FromResult(hazardInfo); + } + + } } diff --git a/admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor b/admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor index 6c35d59..cd6ce55 100644 --- a/admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor +++ b/admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor @@ -1,8 +1,15 @@ @page "/HazardInfos/{id}" +@page "/HazardInfos/new" @attribute [Authorize(Roles = "admin")] +@using TinyMCE.Blazor @inject IRepository repository @inject IJSRuntime JS +@inject Microsoft.Extensions.Configuration.IConfiguration configuration + +@{ + var tinyMCEApiKey = configuration["TinyMCEApiKey"]; +} @if (Hazard == null) { @@ -10,18 +17,65 @@ } else { +

Details

- - -
- - - Save +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ + +
+ + +
+ + +
+ + +
} @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] public string Id { get; set; } @@ -30,17 +84,47 @@ else private HazardInfo Hazard { get; set; } + private string ExternalLinks + { + get + { + return string.Join(Environment.NewLine, Hazard?.ExternalLinks ?? new string[0]); + } + set + { + var links = value.Split(new string[] { "\n", Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)); + Hazard.ExternalLinks = links.ToArray(); + } + } + protected override async Task OnInitializedAsync() { - Hazard = await repository.GetHazardInfoById(Id); + if (string.IsNullOrEmpty(Id)) + { + Hazard = new HazardInfo(); + + } + else + { + Hazard = await repository.GetHazardInfoById(Id); + } + } public async Task Save() { - await repository.SaveHazardInfo(Hazard); - await OnSave.InvokeAsync(Hazard); + if (string.IsNullOrEmpty(Hazard.Id)) + { + Hazard = await repository.CreateHazardInfo(Hazard); + } + else + { + Hazard = await repository.SaveHazardInfo(Hazard); + } + + //await OnSave.InvokeAsync(Hazard); await JS.InvokeVoidAsync("alert", new object[] { "Hazard Info Saved" }); diff --git a/admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor b/admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor index 99058b9..938e39e 100644 --- a/admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor +++ b/admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor @@ -1,17 +1,15 @@ @page "/HazardInfos/" @attribute [Authorize(Roles = "admin")] @inject IRepository Repository -

Administer Hazard Info for Two Weeks Ready

- -

Current Hazards Defined:

+

Administer Hazard Info

@if (_HazardInfos != null && _HazardInfos.Any()) { - +
- + @@ -21,7 +19,7 @@ @@ -29,11 +27,16 @@
NameName
- @hazard.Name + @hazard.Name
+ Add New Hazard } +else if (_HazardInfos == null) +{ +

Loading....

+} else { -

No Hazards defined.

+

No hazard infos defined

} @code { diff --git a/admin/TwoWeeksReady.Admin/Pages/_Host.cshtml b/admin/TwoWeeksReady.Admin/Pages/_Host.cshtml index 0835b62..39752eb 100644 --- a/admin/TwoWeeksReady.Admin/Pages/_Host.cshtml +++ b/admin/TwoWeeksReady.Admin/Pages/_Host.cshtml @@ -21,7 +21,7 @@ - @{ + @{ var token = new TokenProvider { AccessToken = await HttpContext.GetTokenAsync("access_token") @@ -43,5 +43,6 @@ + diff --git a/admin/TwoWeeksReady.Admin/Startup.cs b/admin/TwoWeeksReady.Admin/Startup.cs index fcab282..615d905 100644 --- a/admin/TwoWeeksReady.Admin/Startup.cs +++ b/admin/TwoWeeksReady.Admin/Startup.cs @@ -60,7 +60,6 @@ public void ConfigureServices(IServiceCollection services) options.Scope.Clear(); options.Scope.Add("openid"); options.Scope.Add("profile"); - options.Scope.Add("roles"); options.CallbackPath = new PathString("/callback"); options.ClaimsIssuer = "Auth0"; diff --git a/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj b/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj index c11916e..f0ae042 100644 --- a/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj +++ b/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -11,6 +11,7 @@ + diff --git a/admin/TwoWeeksReady.Admin/appsettings.Development.json b/admin/TwoWeeksReady.Admin/appsettings.Development.json index 4d9cb9b..fe79527 100644 --- a/admin/TwoWeeksReady.Admin/appsettings.Development.json +++ b/admin/TwoWeeksReady.Admin/appsettings.Development.json @@ -7,10 +7,5 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "AllowedHosts": "*", - "Auth0": { - "Domain": "YOUR_AUTH0_DOMAIN", - "ClientId": "YOUR_CLIENT_ID", - "ClientSecret": "YOUR_CLIENT_SECRET" - } + "AllowedHosts": "*" } diff --git a/admin/TwoWeeksReady.Admin/appsettings.json b/admin/TwoWeeksReady.Admin/appsettings.json index af88b20..0106276 100644 --- a/admin/TwoWeeksReady.Admin/appsettings.json +++ b/admin/TwoWeeksReady.Admin/appsettings.json @@ -7,6 +7,7 @@ } }, "AllowedHosts": "*", + "TinyMCEApiKey": "your-api-key", "ApiUrl": "http://localhost:7071/api/", "Auth0": { "Domain": "YOUR_AUTH0_DOMAIN",