-
Notifications
You must be signed in to change notification settings - Fork 68
/
ModalCustomization.razor
177 lines (140 loc) · 4.86 KB
/
ModalCustomization.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@page "/admin/modalcustomization"
@attribute [Authorize(Roles = RolesAndPolicies.Role.Admin)]
@layout AdminLayout
@inject IJSRuntime JSRuntime
@inject ModalConfiguration Config
@inject NavigationManager NavigationManager
@inject ToastService ToastService
@rendermode InteractiveServer
<PageTitle>System Administration: Modal Customization</PageTitle>
<div class="row" style="min-height: 300px">
<div class="col-md-6">
<dl>
<dt><label for="Caption">Text on back of card:</label></dt>
<dd><textarea name="Caption" width="30" height="5" @bind="@Config.Caption" @bind:event="oninput" /></dd>
<dt><label for="FontColor">Font Color on the back of card:</label></dt>
<dd>
<input type="color" name="FontColor" @bind-value="@Config.FontColor" />
</dd>
<dt><label for="Font">Font on the back of card:</label></dt>
<dd>
<input name="Font" @bind-value="@Config.Font" />
</dd>
<dt><label for="FontIsBold">Font is Bold on the back of card:</label>
<input name="FontIsBold" type="checkbox" @bind-value="@Config.FontIsBold" />
</dt>
<dt><label for="BackColor">Background color of the back of card:</label></dt>
<dd>
<input type="color" name="BackColor" @bind-value="@Config.BackgroundColor" />
</dd>
<dt><label for="BackgroundImage">Background Image:</label>
@if (!string.IsNullOrWhiteSpace(Config.BackgroundImage))
{
<button @onclick="RemoveBackgroundImage">
@* Bootstrap icon trashcan *@
<i class="bi bi-trash"></i>
</button>
}
</dt>
<dd>
<InputFile OnChange="LoadBackgroundImage"></InputFile>
</dd>
<dt><label for="BackgroundSize">Background Image Size:</label></dt>
<dd>
<select name="BackgroundSize" @bind="@Config.BackgroundImageSize">
<option value="cover">Cover</option>
<option value="contain">Contain</option>
<option value="auto">Auto</option>
</select>
</dd>
@* Background image repeat *@
<dt><label for="BackgroundRepeat">Background Image Repeat:</label>
<input type="checkbox" name="BackgroundRepeat" @bind-value="@Config.BackgroundImageRepeat" />
</dt>
<dt><label for="BackgroundPosition">Background Image Position:</label></dt>
<dd>
<select name="BackgroundPosition" @bind="@Config.BackgroundImagePosition">
<option>Left Top</option>
<option>Left Center</option>
<option>Left Bottom</option>
<option>Right Top</option>
<option>Right Center</option>
<option>Right Bottom</option>
<option>Center Top</option>
<option>Center Center</option>
<option>Center Bottom</option>
</select>
</dd>
</dl>
<input type="submit" value="Save Changes" class="btn btn-primary" @onclick="SaveChanges" />
@* Cancel changes button *@
<input type="button" value="Cancel" class="btn btn-secondary" @onclick="CancelChanges" />
</div>
<div class="col-md-6">
<h3>Demo:</h3>
<div style="width: 50%; " class="modal-dialog modal-dialog-centered">
<div class="modal-inner" style="height: 150px!important;">
<div style=" position: relative;" class="modal-back modal-content"><div class="modal-back-content"></div></div>
</div>
</div>
</div>
</div>
<style>
@((MarkupString)Config.GetCssWithBackgroundImage(_BackgroundImage, _BackgroundImageMimeType))
</style>
@code {
private string _BackgroundImage = string.Empty;
private string _BackgroundImageMimeType = string.Empty;
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
protected override Task OnParametersSetAsync()
{
// TODO: This does not appear to be set at all times?
if (HttpContext is null)
return base.OnInitializedAsync();
var user = HttpContext.User;
if (!user.IsInRole("Admin"))
{
NavigationManager.NavigateTo("/");
}
return base.OnInitializedAsync();
}
async Task SaveChanges()
{
Config.BackgroundImage = _BackgroundImage;
Config.BackgroundImageMimeType = _BackgroundImageMimeType;
Console.WriteLine($"Caption: {Config.Caption}");
await Config.SaveConfiguration(ConfigureTagzAppFactory.Current);
ToastService.Add("Changes Saved", MessageSeverity.Success);
}
async Task LoadBackgroundImage(InputFileChangeEventArgs args)
{
if (!args.File.ContentType.StartsWith("image/"))
{
Console.WriteLine("Invalid file type");
return;
}
_BackgroundImageMimeType = args.File.ContentType;
var stream = args.File.OpenReadStream();
byte[] bytes;
using (var memoryStream = new MemoryStream())
{
await stream.CopyToAsync(memoryStream);
bytes = memoryStream.ToArray();
}
_BackgroundImage = Convert.ToBase64String(bytes);
}
async Task CancelChanges()
{
Config = await ModalConfiguration.LoadFromConfiguration(ConfigureTagzAppFactory.Current);
_BackgroundImage = Config.BackgroundImage;
_BackgroundImageMimeType = Config.BackgroundImageMimeType;
ToastService.Add("Cancelled Changes", MessageSeverity.Info);
}
async Task RemoveBackgroundImage()
{
Console.WriteLine("Removing background image");
_BackgroundImage = null;
_BackgroundImageMimeType = null;
}
}