diff options
Diffstat (limited to 'Pages')
| -rw-r--r-- | Pages/Component/TagSelectDialog.razor | 71 | ||||
| -rw-r--r-- | Pages/TagDefinitions.razor | 12 |
2 files changed, 80 insertions, 3 deletions
diff --git a/Pages/Component/TagSelectDialog.razor b/Pages/Component/TagSelectDialog.razor index e9f3295..2ba34e9 100644 --- a/Pages/Component/TagSelectDialog.razor +++ b/Pages/Component/TagSelectDialog.razor @@ -6,9 +6,11 @@ <link rel="stylesheet" href="@(nameof(HyperBooru)).styles.css"/> <Dialog Title=@(Title ?? "Select one or more tag(s)") @ref=dialog> - <input type="text" placeholder="Search"/> + <input type="text" placeholder="Search" @ref=queryInput @oninput=QueryInput @onkeypress=QueryKey value=@query autofocus/> <div class="tag-definitions"> @for(int i = 0; i < tagDefinitions.Count(); i++) { + if(!MatchesQuery(tagDefinitions[i].tagDefinition)) + continue; var local = i; var ns = tagDefinitions[i].tagDefinition.Namespace; var alias = tagDefinitions[i].tagDefinition.Alias; @@ -48,6 +50,7 @@ set { if(value) LoadTags(); + query = null; visible = dialog.Visible = value; } } @@ -60,6 +63,9 @@ private bool visible; + private string? query; + private ElementReference queryInput; + public void Show() => Visible = true; public void Hide() => Visible = false; @@ -68,6 +74,11 @@ LoadTags(); } + protected override void OnAfterRender(bool firstRender) { + if(Visible) + queryInput.FocusAsync(); + } + private void LoadTags() { db = dbFactory.CreateDbContext(); @@ -87,6 +98,64 @@ .ToArray(); } + private void QueryInput(ChangeEventArgs e) { + query = (string?) e.Value; + StateHasChanged(); + } + + private void QueryKey(KeyboardEventArgs e) { + if(e.Code != "Enter" && e.Code != "NumpadEnter") + return; + + if(string.IsNullOrEmpty(query)) { + Submit(); + return; + } + + int c = 0; + int? last = null; + for(int i = 0; i < tagDefinitions.Count(); i++) { + if(!MatchesQuery(tagDefinitions[i].tagDefinition)) + continue; + last = i; + c++; + } + + if(c == 1 && last is not null) + tagDefinitions[(int) last].selected = + !tagDefinitions[(int) last].selected; + + query = null; + StateHasChanged(); + } + + private bool MatchesQuery(TagDefinition tagDef) { + TagDefinition? singleTag = null; + + if(string.IsNullOrEmpty(query)) + return true; + + singleTag = tagDefinitions.FirstOrDefault( + e => string.Equals( + e.tagDefinition.Alias, + query, + StringComparison.OrdinalIgnoreCase)).tagDefinition; + + if(singleTag is not null) + return tagDef.Guid == singleTag.Guid; + + singleTag = tagDefinitions.FirstOrDefault( + e => string.Equals( + e.tagDefinition.Name, + query, + StringComparison.OrdinalIgnoreCase)).tagDefinition; + + if(singleTag is not null) + return tagDef.Guid == singleTag.Guid; + + return tagDef.Name.ToLower().Contains(query.ToLower()); + } + private async void Submit() { await OnSubmit.InvokeAsync( tagDefinitions diff --git a/Pages/TagDefinitions.razor b/Pages/TagDefinitions.razor index bd7394d..878b9a2 100644 --- a/Pages/TagDefinitions.razor +++ b/Pages/TagDefinitions.razor @@ -16,12 +16,14 @@ <TabPane Title="@(ns ?? "Default")"> <table id="tag-definitions" class="data-table"> <tr> + <th>Alias</th> <th>Name</th> <th>Implicit Tags</th> <th></th> </tr> @foreach(var tagDef in tagDefinitions.Where(td => td.Namespace == ns)) { <tr data-guid="@tagDef.Guid"> + <td>@tagDef.Alias</td> <td>@tagDef.Name</td> <td> <i> @@ -59,6 +61,8 @@ <input type="text" @bind=tagName required/> <label>Namespace</label> <input type="text" @bind=tagNamespace/> + <label>Alias</label> + <input type="text" @bind=tagAlias/> <div class="button-container"> <button class="secondary" @onclick=@(() => createTagDialog.Hide())>Cancel</button> <button type="submit">Create</button> @@ -72,6 +76,8 @@ <input type="text" @bind=tagName required/> <label>Namespace</label> <input type="text" @bind=tagNamespace/> + <label>Alias</label> + <input type="text" @bind=tagAlias/> <div class="button-container"> <button class="secondary" @onclick=@(() => editTagDialog.Hide())>Cancel</button> <button type="submit">Apply</button> @@ -98,6 +104,7 @@ private string tagName; private string? tagNamespace; + private string? tagAlias; private TagDefinition? toDelete; private TagDefinition? toEdit; @@ -130,7 +137,7 @@ if(string.IsNullOrEmpty(tagNamespace)) tagNamespace = null; - tagService.CreateTagDefinition(tagName, tagNamespace); + tagService.CreateTagDefinition(tagName, tagNamespace, tagAlias); createTagDialog.Hide(); StateHasChanged(); } @@ -139,6 +146,7 @@ this.toEdit = toEdit; tagName = toEdit.Name; tagNamespace = toEdit.Namespace; + tagAlias = toEdit.Alias; editTagDialog.Show(); } @@ -146,7 +154,7 @@ if(toEdit is null) return; - tagService.UpdateTagDefinition(toEdit, tagName, tagNamespace); + tagService.UpdateTagDefinition(toEdit, tagName, tagNamespace, tagAlias); StateHasChanged(); } |
