Skip to content

Commit 4ff428b

Browse files
committed
Ability to edit full details of hazard info
1 parent 2d413e8 commit 4ff428b

6 files changed

Lines changed: 61 additions & 10 deletions

File tree

admin/TwoWeeksReady.Admin/Pages/HazardInfos/Details.razor

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
@page "/HazardInfos/new"
33
@attribute [Authorize(Roles = "admin")]
44

5+
@using TinyMCE.Blazor
56
@inject IRepository repository
67
@inject IJSRuntime JS
8+
@inject Microsoft.Extensions.Configuration.IConfiguration configuration
9+
10+
@{
11+
var tinyMCEApiKey = configuration["TinyMCEApiKey"];
12+
}
713

814
@if (Hazard == null)
915
{
@@ -30,12 +36,46 @@ else
3036
<label for="mediaUrl">Media Url</label>
3137
<input type="text" class="form-control" name="mediaUrl" @bind="@Hazard.MediaUrl">
3238
</div>
33-
<button type="submit" class="btn btn-primary" @onclick="@Save">Submit</button>
39+
40+
<div class="form-group">
41+
<label for="beforeSafetyDetails">Before Safety Details</label>
42+
<Editor Id="beforeSafetyDetails" Conf="@EditorConfig" ApiKey="@tinyMCEApiKey" @bind-Value="@Hazard.BeforeSafetyDetails" />
43+
</div>
44+
45+
<div class="form-group">
46+
<label for="duringSafetyDetails">DuringSafety Details</label>
47+
<Editor Id="duringSafetyDetails" Conf="@EditorConfig" ApiKey="@tinyMCEApiKey" @bind-Value="@Hazard.DuringSafetyDetails" />
48+
</div>
49+
50+
<div class="form-group">
51+
<label for="afterSafetyDetails">Before Safety Details</label>
52+
<Editor Id="afterSafetyDetails" Conf="@EditorConfig" ApiKey="@tinyMCEApiKey" @bind-Value="@Hazard.AfterSafetyDetails" />
53+
</div>
54+
55+
56+
<div class="form-group">
57+
<label for="externalLinks">External Links (One link per line)</label>
58+
<textarea rows="6" class="form-control" name="externalLinks" @bind="@ExternalLinks"></textarea>
59+
</div>
60+
61+
<button type="button" class="btn btn-primary" @onclick="@Save">Submit</button>
3462
</form>
3563
}
3664

3765
@code {
3866

67+
public Dictionary<string, object> EditorConfig = new Dictionary<string, object>
68+
{
69+
{ "plugins", "image" },
70+
{ "toolbar", "image" },
71+
{"image_list", new []
72+
{
73+
// TODO: Figure out a strategy for loading a list of images from assets availabe within the app
74+
new { title = "Image 1", value = "http://localhost:8080/images/hazards/earthquake.png"}
75+
} }
76+
77+
};
78+
3979
[Parameter]
4080
public string Id { get; set; }
4181

@@ -44,6 +84,19 @@ else
4484

4585
private HazardInfo Hazard { get; set; }
4686

87+
private string ExternalLinks
88+
{
89+
get
90+
{
91+
return string.Join(Environment.NewLine, Hazard?.ExternalLinks ?? new string[0]);
92+
}
93+
set
94+
{
95+
var links = value.Split(new string[] { "\n", Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s));
96+
Hazard.ExternalLinks = links.ToArray();
97+
}
98+
}
99+
47100

48101
protected override async Task OnInitializedAsync()
49102
{

admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</table>
3030

3131
}
32-
else if (_HazardInfos != null)
32+
else if (_HazardInfos == null)
3333
{
3434
<p>Loading....</p>
3535
}

admin/TwoWeeksReady.Admin/Pages/_Host.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</head>
2222

2323
<body>
24-
@{
24+
@{
2525
var token = new TokenProvider
2626
{
2727
AccessToken = await HttpContext.GetTokenAsync("access_token")
@@ -43,5 +43,6 @@
4343
</div>
4444

4545
<script src="_framework/blazor.server.js"></script>
46+
<script src="_content/TinyMCE.Blazor/tinymce-blazor.js"></script>
4647
</body>
4748
</html>

admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
@@ -11,6 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.6" />
14+
<PackageReference Include="TinyMCE.Blazor" Version="0.0.8" />
1415
</ItemGroup>
1516

1617
</Project>

admin/TwoWeeksReady.Admin/appsettings.Development.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,5 @@
77
"Microsoft.Hosting.Lifetime": "Information"
88
}
99
},
10-
"AllowedHosts": "*",
11-
"Auth0": {
12-
"Domain": "YOUR_AUTH0_DOMAIN",
13-
"ClientId": "YOUR_CLIENT_ID",
14-
"ClientSecret": "YOUR_CLIENT_SECRET"
15-
}
10+
"AllowedHosts": "*"
1611
}

admin/TwoWeeksReady.Admin/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
}
88
},
99
"AllowedHosts": "*",
10+
"TinyMCEApiKey": "your-api-key",
1011
"ApiUrl": "http://localhost:7071/api/",
1112
"Auth0": {
1213
"Domain": "YOUR_AUTH0_DOMAIN",

0 commit comments

Comments
 (0)