|
1 | 1 | @inject CrudSnackbarService SnackbarService |
2 | 2 | @inject CurrentUserService CurrentUserService |
3 | 3 |
|
4 | | -<MudDialog> |
| 4 | +<MudDialog Style="min-width: 600px;"> |
5 | 5 | <TitleContent> |
6 | 6 | <MudText Typo="Typo.h4">New Subject</MudText> |
7 | 7 | </TitleContent> |
8 | 8 | <DialogContent> |
9 | 9 | <MudForm @ref="form" Model="@value" @bind-IsValid="@success" @bind-Errors="@errors"> |
10 | | - <MudTextField T="string" Label="Name" For="@(() => value.Name)" @bind-Value="value.Name" Required="true"></MudTextField> |
11 | | - <MudTextField T="string" Label="Neptun Code" @bind-Value="value.NeptunCode" Required="true" Validation="@(new Func<string, IEnumerable<string>>(NeptunCodeValidator))"></MudTextField> |
12 | | - <MudTextField T="string" Label="Github Org" For="@(() => value.GitHubOrgName)" @bind-Value="value.GitHubOrgName" Required="true"></MudTextField> |
13 | | - <div class="d-flex align-center"> |
14 | | - <MudTextField T="string" Label="API Key" For="@(() => value.CiApiKey)" @bind-Value="value.CiApiKey" Required="true" Class="flex-grow-1 me-2"></MudTextField> |
15 | | - <MudIconButton Icon="@Icons.Material.Filled.Refresh" OnClick="GenerateApiKey" Size="Size.Small"/> |
16 | | - </div> |
| 10 | + <MudTextField T="string" |
| 11 | + Label="Name" |
| 12 | + For="@(() => value.Name)" |
| 13 | + @bind-Value="value.Name" |
| 14 | + Required="true"/> |
| 15 | + |
| 16 | + <MudTextField T="string" |
| 17 | + Label="Neptun Code" |
| 18 | + @bind-Value="value.NeptunCode" |
| 19 | + Required="true" |
| 20 | + Validation="@(new Func<string, IEnumerable<string>>(NeptunCodeValidator))"/> |
| 21 | + |
| 22 | + <MudTextField T="string" |
| 23 | + Label="Github Org" |
| 24 | + For="@(() => value.GitHubOrgName)" |
| 25 | + @bind-Value="value.GitHubOrgName" |
| 26 | + Required="true"/> |
| 27 | + |
| 28 | + @if (showApiKeyWarning) |
| 29 | + { |
| 30 | + <MudAlert Severity="Severity.Warning" Class="my-2"> |
| 31 | + This API key will be shown only once. Make sure to save it! |
| 32 | + </MudAlert> |
| 33 | + } |
| 34 | + |
| 35 | + <MudPaper Elevation="0" Class="d-flex flex-column gap-2"> |
| 36 | + <div class="d-flex align-center gap-2"> |
| 37 | + <MudTextField T="string" |
| 38 | + Label="API Key" |
| 39 | + For="@(() => value.CiApiKey)" |
| 40 | + @bind-Value="value.CiApiKey" |
| 41 | + Required="true" |
| 42 | + ReadOnly="true" |
| 43 | + Variant="Variant.Outlined" |
| 44 | + Class="flex-grow-1"/> |
| 45 | + |
| 46 | + <MudTooltip Text="Generate new API key"> |
| 47 | + <MudIconButton Icon="@Icons.Material.Filled.Refresh" |
| 48 | + OnClick="GenerateApiKey" |
| 49 | + Color="Color.Primary" |
| 50 | + Size="Size.Medium"/> |
| 51 | + </MudTooltip> |
| 52 | + |
| 53 | + <MudTooltip Text="Copy to clipboard"> |
| 54 | + <MudIconButton Icon="@Icons.Material.Filled.ContentCopy" |
| 55 | + OnClick="CopyToClipboard" |
| 56 | + Color="Color.Secondary" |
| 57 | + Size="Size.Medium"/> |
| 58 | + </MudTooltip> |
| 59 | + </div> |
| 60 | + </MudPaper> |
17 | 61 | </MudForm> |
18 | 62 | </DialogContent> |
19 | 63 | <DialogActions> |
|
24 | 68 |
|
25 | 69 | @code { |
26 | 70 | [CascadingParameter] MudDialogInstance MudDialog { get; set; } |
| 71 | + [Inject] private IJSRuntime JS { get; set; } |
27 | 72 |
|
28 | 73 | private MudForm form; |
29 | 74 | private bool success; |
30 | 75 | private string[] errors; |
| 76 | + private bool showApiKeyWarning = false; |
31 | 77 |
|
32 | 78 | private void Submit() => MudDialog.Close(DialogResult.Ok(value)); |
33 | 79 | private void Cancel() => MudDialog.Cancel(); |
34 | 80 |
|
35 | 81 | private void GenerateApiKey() |
36 | 82 | { |
| 83 | + showApiKeyWarning = true; |
37 | 84 | value.CiApiKey = Guid.NewGuid().ToString(); |
38 | | - SnackbarService.ShowMessage("Current user: " + CurrentUserService.User.Name); |
| 85 | + } |
| 86 | + |
| 87 | + private async Task CopyToClipboard() |
| 88 | + { |
| 89 | + if (!string.IsNullOrEmpty(value.CiApiKey)) |
| 90 | + { |
| 91 | + await JS.InvokeVoidAsync("navigator.clipboard.writeText", value.CiApiKey); |
| 92 | + SnackbarService.ShowSuccess("API key copied to clipboard!"); |
| 93 | + } |
39 | 94 | } |
40 | 95 |
|
41 | 96 | private async void OnSubmitClicked() |
|
0 commit comments