|
2 | 2 | @page "/HazardInfos/new" |
3 | 3 | @attribute [Authorize(Roles = "admin")] |
4 | 4 |
|
| 5 | +@using TinyMCE.Blazor |
5 | 6 | @inject IRepository repository |
6 | 7 | @inject IJSRuntime JS |
| 8 | +@inject Microsoft.Extensions.Configuration.IConfiguration configuration |
| 9 | + |
| 10 | +@{ |
| 11 | + var tinyMCEApiKey = configuration["TinyMCEApiKey"]; |
| 12 | +} |
7 | 13 |
|
8 | 14 | @if (Hazard == null) |
9 | 15 | { |
|
30 | 36 | <label for="mediaUrl">Media Url</label> |
31 | 37 | <input type="text" class="form-control" name="mediaUrl" @bind="@Hazard.MediaUrl"> |
32 | 38 | </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> |
34 | 62 | </form> |
35 | 63 | } |
36 | 64 |
|
37 | 65 | @code { |
38 | 66 |
|
| 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 | + |
39 | 79 | [Parameter] |
40 | 80 | public string Id { get; set; } |
41 | 81 |
|
|
44 | 84 |
|
45 | 85 | private HazardInfo Hazard { get; set; } |
46 | 86 |
|
| 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 | + |
47 | 100 |
|
48 | 101 | protected override async Task OnInitializedAsync() |
49 | 102 | { |
|
0 commit comments