From acb74202f5391272c2e1823dfe04a044c7f7a9a7 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Tue, 5 Sep 2023 01:01:24 +1000 Subject: Tag names and aliases are now verified to be unique --- Pages/Component/AboutDialog.razor | 1 + Pages/Component/Dialog.razor | 4 +- Pages/Component/TagEditDialog.razor | 96 +++++++++++++++++++++++++++++++++ Pages/Component/TagEditDialog.razor.css | 11 ++++ Pages/Component/TagSelectDialog.razor | 9 ++-- Pages/TagDefinitions.razor | 89 ++++++------------------------ Pages/TagDefinitions.razor.css | 3 -- 7 files changed, 133 insertions(+), 80 deletions(-) create mode 100644 Pages/Component/TagEditDialog.razor create mode 100644 Pages/Component/TagEditDialog.razor.css delete mode 100644 Pages/TagDefinitions.razor.css (limited to 'Pages') diff --git a/Pages/Component/AboutDialog.razor b/Pages/Component/AboutDialog.razor index 9823761..9ffbad4 100644 --- a/Pages/Component/AboutDialog.razor +++ b/Pages/Component/AboutDialog.razor @@ -1,6 +1,7 @@ @using System.Reflection @using Microsoft.AspNetCore.Hosting @inject IHostingEnvironment hostingEnvironment +@implements IDialog

@Title

diff --git a/Pages/Component/Dialog.razor b/Pages/Component/Dialog.razor index ded2d2d..f479368 100644 --- a/Pages/Component/Dialog.razor +++ b/Pages/Component/Dialog.razor @@ -1,4 +1,6 @@ -
+@implements IDialog + +
@if(Title is not null) {

@Title


diff --git a/Pages/Component/TagEditDialog.razor b/Pages/Component/TagEditDialog.razor new file mode 100644 index 0000000..2e443d4 --- /dev/null +++ b/Pages/Component/TagEditDialog.razor @@ -0,0 +1,96 @@ +@inject IDbContextFactory dbFactory; +@inject ITagService tagService +@implements IDialog + + + + + + + + + + + + + + +@code { + [Parameter] + public TagDefinition? TagDefinition { get; set; } + + [Parameter] + public EventHandler OnTagUpdate { get; set; } + + public bool Visible { + get => visible; + set { + if(value) + Load(); + visible = dialog.Visible = value; + } + } + + private string Title => + TagDefinition is null ? "Create a new tag definition" : "Edit tag definition"; + + private Dialog dialog; + + private string? tagName; + private string? tagNamespace; + private string? tagAlias; + + private bool nameExists = false; + private bool aliasExists = false; + + private bool visible = false; + + public void Show() => Visible = true; + public void Hide() => Visible = false; + + public void Show(TagDefinition? toEdit) { + TagDefinition = toEdit; + Visible = true; + } + + public void Show(string? @namespace) { + TagDefinition = null; + Visible = true; + tagNamespace = @namespace; + } + + private void Load() { + tagName = TagDefinition?.Name; + tagNamespace = TagDefinition?.Namespace; + tagAlias = TagDefinition?.Alias; + nameExists = false; + aliasExists = false; + } + + private void Submit() { + try { + if(TagDefinition is null) { + tagService.CreateTagDefinition(tagName, tagNamespace, tagAlias); + } else { + tagService.UpdateTagDefinition(TagDefinition, tagName, tagNamespace, tagAlias); + } + } catch(TagDuplicateException e) { + nameExists = e.NameExists; + aliasExists = e.AliasExists; + return; + } + + OnTagUpdate.Invoke(this, new EventArgs()); + Hide(); + } +} diff --git a/Pages/Component/TagEditDialog.razor.css b/Pages/Component/TagEditDialog.razor.css new file mode 100644 index 0000000..02781c0 --- /dev/null +++ b/Pages/Component/TagEditDialog.razor.css @@ -0,0 +1,11 @@ +p.error { + color: var(--col-error-pri); + display: inline; + font-size: 8pt; + margin-left: 5px; + vertical-align: middle; +} + +input { + width: 100%; +} diff --git a/Pages/Component/TagSelectDialog.razor b/Pages/Component/TagSelectDialog.razor index 916a070..88e1471 100644 --- a/Pages/Component/TagSelectDialog.razor +++ b/Pages/Component/TagSelectDialog.razor @@ -2,6 +2,7 @@ @inject ITagService tagService @inject IUserService userService @implements IDisposable +@implements IDialog @@ -36,11 +37,11 @@
@code { - [Parameter] - public string? Title { get; set; } + [Parameter] + public string? Title { get; set; } - [Parameter] - public EventCallback OnSubmit { get; set; } + [Parameter] + public EventCallback OnSubmit { get; set; } public TagDefinition[] SelectedTags { get; set; } = Array.Empty(); diff --git a/Pages/TagDefinitions.razor b/Pages/TagDefinitions.razor index 75bcba0..95253b7 100644 --- a/Pages/TagDefinitions.razor +++ b/Pages/TagDefinitions.razor @@ -8,7 +8,7 @@
- + @@ -45,7 +45,7 @@ - PromptToEdit(tagDef))>Edit + tagEditDialog.Show(tagDef))>Edit PromptToDelete(tagDef))> Delete @@ -66,36 +66,6 @@
- -
- - - - - - - - - - -
-
- - -
- - - - - - - - - - -
-
- @@ -103,23 +73,19 @@ + + @code { private TabContainer tabContainer; - private Dialog createTagDialog; private Dialog deleteTagDialog; - private Dialog editTagDialog; + private TagEditDialog tagEditDialog; private TagSelectDialog implicitTagDialog; - private string tagName; - private string? tagNamespace; - private string? tagAlias; - private TagDefinition? toDelete; - private TagDefinition? toEdit; private TagDefinition? toEditImplicit; private TagDefinition[] tagDefinitions; @@ -157,39 +123,6 @@ .ToArray(); } - private void PromptToCreate() { - var curTitle = tabContainer.ActivePane?.Title; - tagNamespace = curTitle == "Default" ? null : curTitle; - createTagDialog.Show(); - } - - private void CreateTagDefinition() { - if(string.IsNullOrEmpty(tagNamespace)) - tagNamespace = null; - - tagService.CreateTagDefinition(tagName, tagNamespace, tagAlias); - createTagDialog.Hide(); - LoadTags(); - StateHasChanged(); - } - - private void PromptToEdit(TagDefinition toEdit) { - this.toEdit = toEdit; - tagName = toEdit.Name; - tagNamespace = toEdit.Namespace; - tagAlias = toEdit.Alias; - editTagDialog.Show(); - } - - private void EditTagDefinition() { - if(toEdit is null) - return; - - tagService.UpdateTagDefinition(toEdit, tagName, tagNamespace, tagAlias); - LoadTags(); - StateHasChanged(); - } - private void PromptToDelete(TagDefinition toDelete) { this.toDelete = toDelete; deleteTagDialog.Show(); @@ -205,6 +138,18 @@ StateHasChanged(); } + private void PromptTagCreate() { + string? @namespace = tabContainer.ActivePane?.Title; + if(@namespace == "Default") + @namespace = null; + tagEditDialog.Show(@namespace); + } + + private void TagUpdated(object? sender, EventArgs e) { + LoadTags(); + StateHasChanged(); + } + private void PromptImplicitTags(TagDefinition toEditImplicit) { this.toEditImplicit = toEditImplicit; implicitTagDialog.SelectedTags = diff --git a/Pages/TagDefinitions.razor.css b/Pages/TagDefinitions.razor.css deleted file mode 100644 index b66d491..0000000 --- a/Pages/TagDefinitions.razor.css +++ /dev/null @@ -1,3 +0,0 @@ -form > input { - width: 100%; -} \ No newline at end of file -- cgit v1.3