|
3 | 3 | @attribute [Authorize(Roles = "admin")] |
4 | 4 |
|
5 | 5 | @using TinyMCE.Blazor |
| 6 | +@using System.IO; |
| 7 | +@using System.Linq; |
| 8 | + |
6 | 9 | @inject IRepository repository |
7 | 10 | @inject IJSRuntime JS |
8 | 11 | @inject Microsoft.Extensions.Configuration.IConfiguration configuration |
| 12 | +@inject ClientImageService clientImages |
9 | 13 |
|
10 | 14 | @{ |
11 | 15 | var tinyMCEApiKey = configuration["TinyMCEApiKey"]; |
|
19 | 23 | { |
20 | 24 |
|
21 | 25 | <h3>Details</h3> |
22 | | - <form> |
| 26 | + <EditForm Model="@Hazard"> |
23 | 27 | <div class="form-group"> |
24 | 28 | <label for="name">Hazard Name</label> |
25 | 29 | <input type="text" class="form-control" name="name" @bind="@Hazard.Name"> |
|
30 | 34 | </div> |
31 | 35 | <div class="form-group"> |
32 | 36 | <label for="iconUrl">Icon Url</label> |
33 | | - <input type="text" class="form-control" name="iconUrl" @bind="@Hazard.IconUrl"> |
| 37 | + |
| 38 | + <InputSelect id="iconUrl" class="form-control" @bind-Value="Hazard.IconUrl"> |
| 39 | + @foreach(var image in clientImages.Images) |
| 40 | + { |
| 41 | + <option value="@image">@image</option> |
| 42 | + } |
| 43 | + </InputSelect> |
| 44 | + <img src="@clientImages.ToAbsolutePath(Hazard.IconUrl)"/> |
| 45 | + |
34 | 46 | </div> |
35 | 47 | <div class="form-group"> |
36 | 48 | <label for="mediaUrl">Media Url</label> |
37 | | - <input type="text" class="form-control" name="mediaUrl" @bind="@Hazard.MediaUrl"> |
| 49 | + <InputSelect id="mediaUrl" class="form-control" @bind-Value="Hazard.MediaUrl"> |
| 50 | + @foreach(var image in clientImages.Images) |
| 51 | + { |
| 52 | + <option value="@image">@image</option> |
| 53 | + } |
| 54 | + </InputSelect> |
| 55 | + <img src="@clientImages.ToAbsolutePath(Hazard.MediaUrl)"/> |
38 | 56 | </div> |
39 | 57 |
|
40 | 58 | <div class="form-group"> |
|
59 | 77 | </div> |
60 | 78 |
|
61 | 79 | <button type="button" class="btn btn-primary" @onclick="@Save">Submit</button> |
62 | | - </form> |
| 80 | + </EditForm> |
63 | 81 | } |
64 | 82 |
|
65 | 83 | @code { |
66 | 84 |
|
67 | 85 | public Dictionary<string, object> EditorConfig = new Dictionary<string, object> |
68 | | -{ |
| 86 | + { |
69 | 87 | { "plugins", "image" }, |
70 | 88 | { "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 | 89 | }; |
78 | 90 |
|
79 | 91 | [Parameter] |
@@ -103,13 +115,12 @@ else |
103 | 115 | if (string.IsNullOrEmpty(Id)) |
104 | 116 | { |
105 | 117 | Hazard = new HazardInfo(); |
106 | | - |
107 | 118 | } |
108 | 119 | else |
109 | 120 | { |
110 | 121 | Hazard = await repository.GetHazardInfoById(Id); |
111 | 122 | } |
112 | | - |
| 123 | + EditorConfig["image_list"] = clientImages.Images.Select(i => new { title = i.RelativePath, value = i.AbsolutePath }).ToArray(); |
113 | 124 | } |
114 | 125 |
|
115 | 126 |
|
|
0 commit comments