From fe4ee2416ae118111b15ad4fd5bed28862d0ea63 Mon Sep 17 00:00:00 2001 From: toonech <53052638+toonech@users.noreply.github.com> Date: Sun, 12 Jun 2022 14:37:51 -0400 Subject: [PATCH 1/6] Add AutoComplete enum and extension --- GridShared/Columns/InputAutocomplete.cs | 151 ++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 GridShared/Columns/InputAutocomplete.cs diff --git a/GridShared/Columns/InputAutocomplete.cs b/GridShared/Columns/InputAutocomplete.cs new file mode 100644 index 00000000..48df1304 --- /dev/null +++ b/GridShared/Columns/InputAutocomplete.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GridShared.Columns +{ + /// + /// + /// Values are mostly from Mozilla developer docs. + /// + /// + /// + /// + public enum AutocompleteTerm + { + /// + /// Uses the default autocomplete as if it was never set. + /// + None, + /// + /// Uses the FieldName to set the term. + /// + /// + FieldName, + /// + /// Uses the value from the CustomAutocomplete member. + /// + /// + Custom, + /// + /// Uses a random GUID to prevent matching. + /// + Defeat, + FullName, + HonorificPrefix, + GivenName, + AdditionalName, + FamilyName, + HonorificSuffix, + NickName, + Email, + UserName, + NewPassword, + CurrentPassword, + OneTimeCode, + OrgTitle, + Org, + StreetAddress, + AddressLine1, + AddressLine2, + AddressLine3, + AddressLevel1, + AddressLevel2, + AddressLevel3, + AddressLevel4, + Country, + CountryName, + PostalCode, + CCName, + CCGivenName, + CCAdditionalName, + CCFamilyName, + CCNumber, + CCExp, + CCExpMonth, + CCExpYear, + CCCsc, + CCType, + TransactionCurrency, + TransactionAmount, + Language, + BDay, + BDayDay, + BDayMonth, + BDayYear, + Sex, + Tel, + TelCountryCode, + TelNational, + TelAreaCode, + TelLocal, + TelExtension, + Impp, + Url, + Photo + } + + public static class InputAutocompleteExtensions + { + public static Func ToAutocompleteFunc(this IColumn column) => + column.AutoCompleteTaxonomy switch + { + AutocompleteTerm.None => () => null, + AutocompleteTerm.FieldName => () => column.FieldName, + AutocompleteTerm.Defeat => () => Guid.NewGuid().ToString(), + AutocompleteTerm.FullName => () => "name", + AutocompleteTerm.HonorificPrefix => () => "honorific-prefix", + AutocompleteTerm.GivenName => () => "given-name", + AutocompleteTerm.AdditionalName => () => "additional-name", + AutocompleteTerm.FamilyName => () => "family-name", + AutocompleteTerm.HonorificSuffix => () => "honorific-suffix", + AutocompleteTerm.NickName => () => "nickname", + AutocompleteTerm.Email => () => "email", + AutocompleteTerm.UserName => () => "username", + AutocompleteTerm.NewPassword => () => "new-password", + AutocompleteTerm.CurrentPassword => () => "current-password", + AutocompleteTerm.OneTimeCode => () => "one-time-code", + AutocompleteTerm.OrgTitle => () => "organization-title", + AutocompleteTerm.Org => () => "organization", + AutocompleteTerm.StreetAddress => () => "street-address", + AutocompleteTerm.AddressLine1 => () => "address-line1", + AutocompleteTerm.AddressLine2 => () => "address-line2", + AutocompleteTerm.AddressLine3 => () => "address-line3", + AutocompleteTerm.AddressLevel1 => () => "address-level1", + AutocompleteTerm.AddressLevel2 => () => "address-level2", + AutocompleteTerm.AddressLevel3 => () => "address-level3", + AutocompleteTerm.AddressLevel4 => () => "address-level4", + AutocompleteTerm.Country => () => "country", + AutocompleteTerm.CountryName => () => "country-name", + AutocompleteTerm.PostalCode => () => "postal-code", + AutocompleteTerm.CCName => () => "cc-name", + AutocompleteTerm.CCGivenName => () => "cc-given-name", + AutocompleteTerm.CCAdditionalName => () => "cc-additional-name", + AutocompleteTerm.CCFamilyName => () => "cc-family-name", + AutocompleteTerm.CCNumber => () => "cc-number", + AutocompleteTerm.CCExp => () => "cc-exp", + AutocompleteTerm.CCExpMonth => () => "cc-exp-month", + AutocompleteTerm.CCExpYear => () => "cc-exp-year", + AutocompleteTerm.CCCsc => () => "cc-csc", + AutocompleteTerm.CCType => () => "cc-type", + AutocompleteTerm.TransactionCurrency => () => "transaction-currency", + AutocompleteTerm.TransactionAmount => () => "transaction-amount", + AutocompleteTerm.Language => () => "language", + AutocompleteTerm.BDay => () => "bday", + AutocompleteTerm.BDayDay => () => "bday-day", + AutocompleteTerm.BDayMonth => () => "bday-month", + AutocompleteTerm.BDayYear => () => "bday-year", + AutocompleteTerm.Sex => () => "sex", + AutocompleteTerm.Tel => () => "tel", + AutocompleteTerm.TelCountryCode => () => "tel-country-code", + AutocompleteTerm.TelNational => () => "tel-national", + AutocompleteTerm.TelAreaCode => () => "tel-area-code", + AutocompleteTerm.TelLocal => () => "tel-local", + AutocompleteTerm.TelExtension => () => "tel-extension", + AutocompleteTerm.Impp => () => "impp", + AutocompleteTerm.Url => () => "url", + AutocompleteTerm.Photo => () => "photo", + _ => () => "on" + }; + } +} From 891a56542159c0083e306952b5a9fc9e76deb985 Mon Sep 17 00:00:00 2001 From: toonech <53052638+toonech@users.noreply.github.com> Date: Sun, 12 Jun 2022 14:49:49 -0400 Subject: [PATCH 2/6] Wire up Autocomplete --- GridBlazor/Columns/DefaultColumnBuilder.cs | 6 +++++ GridBlazor/Columns/GridColumnBase.cs | 24 +++++++++++++++++++ GridCore/Columns/DefaultColumnCoreBuilder.cs | 6 +++++ GridCore/Columns/GridCoreColumnBase.cs | 23 ++++++++++++++++++ GridShared/Columns/IGridColumn.cs | 21 ++++++++++++++++ .../DataAnnotations/GridColumnAttribute.cs | 17 ++++++++++++- 6 files changed, 96 insertions(+), 1 deletion(-) diff --git a/GridBlazor/Columns/DefaultColumnBuilder.cs b/GridBlazor/Columns/DefaultColumnBuilder.cs index ab8f5174..e77a4cbe 100644 --- a/GridBlazor/Columns/DefaultColumnBuilder.cs +++ b/GridBlazor/Columns/DefaultColumnBuilder.cs @@ -113,6 +113,12 @@ private void ApplyColumnAnnotationSettings(IGridColumn column, GridColumnAttr if (initialDirection.HasValue) column.SortInitialDirection(initialDirection.Value); + AutocompleteTerm? autocompleteTaxonomy = options.GetAutocompleteTaxonomy(); + if (autocompleteTaxonomy.HasValue) + { + column.SetAutoCompleteTaxonomy(autocompleteTaxonomy.Value); + } + if (!string.IsNullOrEmpty(options.FilterWidgetType)) column.SetFilterWidgetType(options.FilterWidgetType); diff --git a/GridBlazor/Columns/GridColumnBase.cs b/GridBlazor/Columns/GridColumnBase.cs index 23ff7271..e2f2e6bb 100644 --- a/GridBlazor/Columns/GridColumnBase.cs +++ b/GridBlazor/Columns/GridColumnBase.cs @@ -133,6 +133,10 @@ public abstract class GridColumnBase : GridStyledColumn, IGridColumn, IExp public string TooltipValue { get; set; } + public AutocompleteTerm AutoCompleteTaxonomy { get; set; } + + public Func CustomAutoComplete { get; set; } = () => ""; + public IGridColumn Titled(string title) { Title = title; @@ -526,6 +530,26 @@ public IGridColumn SetCrudHidden(bool create, bool read, bool update, bool de return this; } + /// + public IGridColumn SetAutoCompleteTaxonomy(AutocompleteTerm taxonomy) + { + AutoCompleteTaxonomy = taxonomy; + if (taxonomy == AutocompleteTerm.Custom) + { + throw new ArgumentException("Must supply custom argument when using custom autocomplete"); + } + CustomAutoComplete = this.ToAutocompleteFunc(); + return this; + } + + /// + public IGridColumn SetAutoCompleteTaxonomy(Func custom) + { + AutoCompleteTaxonomy = AutocompleteTerm.Custom; + CustomAutoComplete = custom; + return this; + } + public IGridColumn SetAfterChangeValue(Func afterChangeValue) { AfterChangeValue = afterChangeValue; diff --git a/GridCore/Columns/DefaultColumnCoreBuilder.cs b/GridCore/Columns/DefaultColumnCoreBuilder.cs index d7b924fa..e277a395 100644 --- a/GridCore/Columns/DefaultColumnCoreBuilder.cs +++ b/GridCore/Columns/DefaultColumnCoreBuilder.cs @@ -113,6 +113,12 @@ private void ApplyColumnAnnotationSettings(IGridColumn column, GridColumnAttr if (initialDirection.HasValue) column.SortInitialDirection(initialDirection.Value); + AutocompleteTerm? autocompleteTaxonomy = options.GetAutocompleteTaxonomy(); + if (autocompleteTaxonomy.HasValue) + { + column.SetAutoCompleteTaxonomy(autocompleteTaxonomy.Value); + } + if (!string.IsNullOrEmpty(options.FilterWidgetType)) column.SetFilterWidgetType(options.FilterWidgetType); diff --git a/GridCore/Columns/GridCoreColumnBase.cs b/GridCore/Columns/GridCoreColumnBase.cs index 85ca9acb..7aec51a7 100644 --- a/GridCore/Columns/GridCoreColumnBase.cs +++ b/GridCore/Columns/GridCoreColumnBase.cs @@ -138,6 +138,9 @@ public GridSortDirection? InitialDirection public string TooltipValue { get; set; } + public AutocompleteTerm AutoCompleteTaxonomy { get; set; } + public Func CustomAutoComplete { get; set; } = () => ""; + public IGridColumn Titled(string title) { Title = title; @@ -540,6 +543,26 @@ public IGridColumn SetCrudHidden(bool all) return SetCrudHidden(all, all, all, all); } + /// + public IGridColumn SetAutoCompleteTaxonomy(AutocompleteTerm taxonomy) + { + AutoCompleteTaxonomy = taxonomy; + if (taxonomy == AutocompleteTerm.Custom) + { + throw new ArgumentException("Must supply custom argument when using custom autocomplete"); + } + CustomAutoComplete = this.ToAutocompleteFunc(); + return this; + } + + /// + public IGridColumn SetAutoCompleteTaxonomy(Func custom) + { + AutoCompleteTaxonomy = AutocompleteTerm.Custom; + CustomAutoComplete = custom; + return this; + } + public IGridColumn SetAfterChangeValue(Func afterChangeValue) { AfterChangeValue = afterChangeValue; diff --git a/GridShared/Columns/IGridColumn.cs b/GridShared/Columns/IGridColumn.cs index bae3f476..3340eb36 100644 --- a/GridShared/Columns/IGridColumn.cs +++ b/GridShared/Columns/IGridColumn.cs @@ -351,6 +351,23 @@ IGridColumn RenderCrudComponentAs IGridColumn SetCrudHidden(bool all); + /// + /// Sets the taxonomy for the input AutoComplete attribute, if supported + /// + /// + /// Any value from except AutocompleteTerm.Custom + /// + /// + /// Thrown when is set to AutocompleteTerm.Custom + /// + IGridColumn SetAutoCompleteTaxonomy(AutocompleteTerm taxonomy); + + /// + /// Sets the custom taxonomy for the input AutoComplete attribute, if supported + /// + /// Function that returns a string to be used to populate the autocomplete attribute + IGridColumn SetAutoCompleteTaxonomy(Func custom); + /// /// Sets a function to be executed after the column value is changed (CRUD) /// @@ -516,6 +533,10 @@ public interface IColumn bool SanitizeEnabled { get; } + Func CustomAutoComplete { get; set; } + + AutocompleteTerm AutoCompleteTaxonomy { get; set; } + /// /// Gets value of the gridColumn by instance /// diff --git a/GridShared/DataAnnotations/GridColumnAttribute.cs b/GridShared/DataAnnotations/GridColumnAttribute.cs index d441b5c8..af8b43de 100644 --- a/GridShared/DataAnnotations/GridColumnAttribute.cs +++ b/GridShared/DataAnnotations/GridColumnAttribute.cs @@ -1,4 +1,5 @@ -using GridShared.Sorting; +using GridShared.Columns; +using GridShared.Sorting; using System; namespace GridShared.DataAnnotations @@ -11,6 +12,8 @@ public class GridColumnAttribute : GridHiddenColumnAttribute { private GridSortDirection? _initialDirection; + private AutocompleteTerm? _autocompleteTaxonomy; + public GridColumnAttribute() { EncodeEnabled = true; @@ -55,9 +58,21 @@ public GridSortDirection SortInitialDirection set { _initialDirection = value; } } + public AutocompleteTerm AutocompleteTaxonomy + { + get { return _autocompleteTaxonomy.HasValue ? _autocompleteTaxonomy.Value : AutocompleteTerm.None; } + set { _autocompleteTaxonomy = value; } + } + public GridSortDirection? GetInitialSortDirection() { return _initialDirection; } + + public AutocompleteTerm? GetAutocompleteTaxonomy() + { + return _autocompleteTaxonomy; + } + } } \ No newline at end of file From d2fddf202e43aca6f68bea2d39d38576b233c008 Mon Sep 17 00:00:00 2001 From: toonech <53052638+toonech@users.noreply.github.com> Date: Sun, 12 Jun 2022 15:02:24 -0400 Subject: [PATCH 3/6] Add autocomplete to Grid Create and Update components --- GridBlazor/Pages/GridCreateComponent.razor | 30 +++++++++++----------- GridBlazor/Pages/GridUpdateComponent.razor | 28 ++++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/GridBlazor/Pages/GridCreateComponent.razor b/GridBlazor/Pages/GridCreateComponent.razor index ffab73a4..f5f681a4 100644 --- a/GridBlazor/Pages/GridCreateComponent.razor +++ b/GridBlazor/Pages/GridCreateComponent.razor @@ -55,7 +55,7 @@ else { var selectedValue = column.GetFormatedValue(value); - @foreach (var selectItem in ((IGridColumn)column).SelectItems) { @@ -84,7 +84,7 @@ else { var selectedValue = column.GetFormatedValue(value); - @{ var selectItems = SelectItems.Get(column.Name); @@ -188,7 +188,7 @@ InputFiles.Add(column.FieldName, reference); }
- + @@ -209,44 +209,44 @@ { if (GridComponent.IsWeekSupported) { - + } else { - + } } else if (typeAttr == "month") { if (GridComponent.IsMonthSupported) { - + } else { - + } } else if (typeAttr == "datetime-local") { if (GridComponent.IsDateTimeLocalSupported) { - + } else { - + } } else { - + } } else if (type == typeof(System.TimeSpan)) { string typeAttr = ((IGridColumn)column).InputType == InputType.None ? "time" : ((IGridColumn)column).InputType.ToTypeAttr(); - + } else if (type == typeof(bool)) { @@ -256,14 +256,14 @@ { } else { - + } } else @@ -285,11 +285,11 @@ } else if (((IGridColumn)column).InputType == InputType.Number) { - + } else { - + } @ColumnErrors.Get(column.FieldName) diff --git a/GridBlazor/Pages/GridUpdateComponent.razor b/GridBlazor/Pages/GridUpdateComponent.razor index 22cc73e5..879d775d 100644 --- a/GridBlazor/Pages/GridUpdateComponent.razor +++ b/GridBlazor/Pages/GridUpdateComponent.razor @@ -59,7 +59,7 @@ else { var selectedValue = column.GetFormatedValue(value); - @foreach (var selectItem in ((IGridColumn)column).SelectItems) { @@ -88,7 +88,7 @@ else { var selectedValue = column.GetFormatedValue(value); - @{ var selectItems = SelectItems.Get(column.Name); @@ -165,7 +165,7 @@ { if (type == typeof(string) && ((IGridColumn)column).InputType == InputType.TextArea) { -