From 476ae4bd11808e273197188a194d00c929852ef3 Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Tue, 10 Nov 2020 15:40:53 +0300 Subject: [PATCH 1/7] ExtensionPropertyLookupConfiguration added. --- .../ObjectExtending/IBasicObjectExtensionPropertyInfo.cs | 4 ++++ .../Modularity/ExtensionPropertyConfiguration.cs | 8 ++++++-- .../Modularity/ExtensionPropertyLookupConfiguration.cs | 9 +++++++++ .../Modularity/ModuleExtensionConfigurationHelper.cs | 1 + .../Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs | 4 ++++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyLookupConfiguration.cs diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/IBasicObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/IBasicObjectExtensionPropertyInfo.cs index de9bb35b01..23492d25ab 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/IBasicObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/IBasicObjectExtensionPropertyInfo.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using JetBrains.Annotations; using Volo.Abp.Localization; +using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending { @@ -34,5 +35,8 @@ namespace Volo.Abp.ObjectExtending /// [CanBeNull] public Func DefaultValueFactory { get; set; } + + [NotNull] + public ExtensionPropertyLookupConfiguration LookupConfiguration { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs index 0a19a82018..37eb29d69b 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs @@ -28,7 +28,7 @@ namespace Volo.Abp.ObjectExtending.Modularity [NotNull] public Dictionary Configuration { get; } - + /// /// Single point to enable/disable this property for the clients (UI and API). /// If this is false, the configuration made in the and the @@ -42,7 +42,7 @@ namespace Volo.Abp.ObjectExtending.Modularity [NotNull] public ExtensionPropertyUiConfiguration UI { get; } - + [NotNull] public ExtensionPropertyApiConfiguration Api { get; } @@ -59,6 +59,9 @@ namespace Volo.Abp.ObjectExtending.Modularity [CanBeNull] public Func DefaultValueFactory { get; set; } + [NotNull] + public ExtensionPropertyLookupConfiguration LookupConfiguration { get; set; } + public ExtensionPropertyConfiguration( [NotNull] EntityExtensionConfiguration entityExtensionConfiguration, [NotNull] Type type, @@ -78,6 +81,7 @@ namespace Volo.Abp.ObjectExtending.Modularity Attributes.AddRange(ExtensionPropertyHelper.GetDefaultAttributes(Type)); DefaultValue = TypeHelper.GetDefaultValue(Type); + LookupConfiguration = new ExtensionPropertyLookupConfiguration(); } public object GetDefaultValue() diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyLookupConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyLookupConfiguration.cs new file mode 100644 index 0000000000..7d92f8accd --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyLookupConfiguration.cs @@ -0,0 +1,9 @@ +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class ExtensionPropertyLookupConfiguration + { + public string ApiUrl { get; set; } + public string DisplayPropertyName { get; set; } = "text"; + public string ValuePropertyName { get; set; } = "id"; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs index f4a5b149d6..0c6d6b5a2d 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs @@ -155,6 +155,7 @@ namespace Volo.Abp.ObjectExtending.Modularity property.Validators.AddRange(propertyConfig.Validators); property.DefaultValue = propertyConfig.DefaultValue; property.DefaultValueFactory = propertyConfig.DefaultValueFactory; + property.LookupConfiguration = propertyConfig.LookupConfiguration; } ); } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs index b54d64477f..5b71b0b975 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using JetBrains.Annotations; using Volo.Abp.Localization; +using Volo.Abp.ObjectExtending.Modularity; using Volo.Abp.Reflection; namespace Volo.Abp.ObjectExtending @@ -57,6 +58,9 @@ namespace Volo.Abp.ObjectExtending [CanBeNull] public Func DefaultValueFactory { get; set; } + [NotNull] + public ExtensionPropertyLookupConfiguration LookupConfiguration { get; set; } + public ObjectExtensionPropertyInfo( [NotNull] ObjectExtensionInfo objectExtension, [NotNull] Type type, From 272333d684aeb555a80cfedcf02d6cb1498e21ef Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Tue, 10 Nov 2020 15:41:28 +0300 Subject: [PATCH 2/7] update select tag helper to support autocomplete scenarios. --- .../TagHelpers/Form/AbpSelectTagHelper.cs | 6 +++ .../Form/AbpSelectTagHelperService.cs | 18 +++++++- .../bootstrap/dom-event-handlers.js | 41 ++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs index 4df9733d83..e27235da91 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs @@ -21,6 +21,12 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form [HtmlAttributeName("required-symbol")] public bool DisplayRequiredSymbol { get; set; } = true; + public string AutocompleteApiUrl { get; set; } + + public string AutocompleteDisplayPropertyName { get; set; } + + public string AutocompleteValuePropertyName { get; set; } + public AbpSelectTagHelper(AbpSelectTagHelperService tagHelperService) : base(tagHelperService) { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs index a33b48d11b..c12904edb5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs @@ -78,20 +78,36 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form var selectTagHelper = new SelectTagHelper(_generator) { For = TagHelper.AspFor, - Items = GetSelectItems(context, output), ViewContext = TagHelper.ViewContext }; + if (TagHelper.AutocompleteApiUrl.IsNullOrEmpty()) + { + selectTagHelper.Items = GetSelectItems(context, output); + } + var selectTagHelperOutput = await selectTagHelper.ProcessAndGetOutputAsync(GetInputAttributes(context, output), context, "select", TagMode.StartTagAndEndTag); selectTagHelperOutput.Attributes.AddClass("form-control"); selectTagHelperOutput.Attributes.AddClass(GetSize(context, output)); AddDisabledAttribute(selectTagHelperOutput); AddInfoTextId(selectTagHelperOutput); + AddAutocompleteAttributes(selectTagHelperOutput); return selectTagHelperOutput; } + protected virtual void AddAutocompleteAttributes(TagHelperOutput output) + { + if (!TagHelper.AutocompleteApiUrl.IsNullOrEmpty()) + { + output.Attributes.AddClass("auto-complete-select"); + output.Attributes.Add("data-autocomplete-api-url", TagHelper.AutocompleteApiUrl); + output.Attributes.Add("data-autocomplete-display-property", TagHelper.AutocompleteDisplayPropertyName); + output.Attributes.Add("data-autocomplete-value-property", TagHelper.AutocompleteValuePropertyName); + } + } + protected virtual void AddDisabledAttribute(TagHelperOutput inputTagHelperOutput) { var disabledAttribute = TagHelper.AspFor.ModelExplorer.GetAttribute(); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js index 56869350d5..97e3906a24 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js @@ -71,6 +71,42 @@ $timeagos.timeago(); } + abp.dom.initializers.initializeAutocompleteSelects = function ($autocompleteSelects) { + if ($autocompleteSelects.length) { + $autocompleteSelects.each(function () { + var $select = $(this); + var url = $(this).data("autocompleteApiUrl"); + var displayName = $(this).data("autocompleteDisplayProperty"); + var displayValue = $(this).data("autocompleteValueProperty"); + $select.select2({ + ajax: { + url: url, + dataType: "json", + data: function (params) { + var query = { + search: params.term + }; + return query; + }, + processResults: function (data) { + var retVal = []; + data.forEach(function (item, index) { + retVal.push({ + id: item[displayValue], + text: item[displayName] + }) + }); + return { + results: retVal + }; + } + }, + width: '100%' + }); + }); + } + } + abp.libs = abp.libs = abp.libs || {}; abp.libs.bootstrapDatepicker = { packageName: "bootstrap-datepicker", @@ -91,7 +127,7 @@ locale: abp.localization.currentCulture.name }).toLocaleString(); }, - getOptions: function($input) { //$input may needed if developer wants to override this method + getOptions: function ($input) { //$input may needed if developer wants to override this method return { todayBtn: "linked", autoclose: true, @@ -121,6 +157,7 @@ abp.dom.initializers.initializeTimeAgos(args.$el.findWithSelf('.timeago')); abp.dom.initializers.initializeForms(args.$el.findWithSelf('form'), true); abp.dom.initializers.initializeScript(args.$el); + abp.dom.initializers.initializeAutocompleteSelects(args.$el.findWithSelf('.auto-complete-select')); }); abp.dom.onNodeRemoved(function (args) { @@ -139,7 +176,9 @@ abp.dom.initializers.initializeTimeAgos($('.timeago')); abp.dom.initializers.initializeDatepickers($(document)); abp.dom.initializers.initializeForms($('form')); + abp.dom.initializers.initializeAutocompleteSelects($('.auto-complete-select')); $('[data-auto-focus="true"]').first().findWithSelf('input,select').focus(); + }); })(jQuery); From 414d47bf1275f81062381bbc51650e60c4c08e7d Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Tue, 10 Nov 2020 15:45:41 +0300 Subject: [PATCH 3/7] add property. --- .../Pages/Identity/Roles/CreateModal.cshtml | 14 +++++++++++--- .../Pages/Identity/Roles/EditModal.cshtml | 18 +++++++++++++----- .../Pages/Identity/Users/CreateModal.cshtml | 8 ++++++++ .../Pages/Identity/Users/EditModal.cshtml | 8 ++++++++ .../Tenants/CreateModal.cshtml | 10 +++++++++- .../TenantManagement/Tenants/EditModal.cshtml | 8 ++++++++ 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml index 72ea9da317..169f96a28b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml @@ -17,11 +17,11 @@ - + - + - + @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { if (propertyInfo.Type.IsEnum) @@ -29,6 +29,14 @@ } + else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + { + + } else { - + - + @if (Model.Role.IsStatic) { @@ -28,11 +28,11 @@ { } - + - + - + @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { if (propertyInfo.Type.IsEnum) @@ -40,6 +40,14 @@ } + else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + { + + } else { } + else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + { + + } else { } + else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + { + + } else { - + @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { if (propertyInfo.Type.IsEnum) @@ -29,6 +29,14 @@ } + else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + { + + } else { } + else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + { + + } else { Date: Wed, 11 Nov 2020 11:12:28 +0300 Subject: [PATCH 4/7] update usages. --- .../Pages/Identity/Roles/CreateModal.cshtml | 7 +------ .../Pages/Identity/Roles/EditModal.cshtml | 7 +------ .../Pages/Identity/Users/CreateModal.cshtml | 7 +------ .../Pages/Identity/Users/EditModal.cshtml | 7 +------ .../Pages/TenantManagement/Tenants/CreateModal.cshtml | 7 +------ .../Pages/TenantManagement/Tenants/EditModal.cshtml | 7 +------ 6 files changed, 6 insertions(+), 36 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml index 169f96a28b..9c1af360d8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml @@ -24,12 +24,7 @@ @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - if (propertyInfo.Type.IsEnum) - { - - } - else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) { ()) { - if (propertyInfo.Type.IsEnum) - { - - } - else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) { ()) { - if (propertyInfo.Type.IsEnum) - { - - } - else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) { ()) { - if (propertyInfo.Type.IsEnum) - { - - } - else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) { ()) { - if (propertyInfo.Type.IsEnum) - { - - } - else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) { @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - if (propertyInfo.Type.IsEnum) - { - - } - else if (!propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) { Date: Wed, 11 Nov 2020 14:30:35 +0300 Subject: [PATCH 5/7] add result items property name and move lookup config to the UI. --- .../ObjectExtending/ExtensionPropertyUiDto.cs | 1 + .../ObjectExtending/ExtensionPropertyUiLookupDto.cs | 13 +++++++++++++ .../TagHelpers/Form/AbpSelectTagHelper.cs | 1 + .../TagHelpers/Form/AbpSelectTagHelperService.cs | 1 + .../bootstrap/dom-event-handlers.js | 10 +++++++++- .../CachedObjectExtensionsDtoService.cs | 9 ++++++++- .../IBasicObjectExtensionPropertyInfo.cs | 3 --- .../Modularity/ExtensionPropertyConfiguration.cs | 4 ---- .../ExtensionPropertyLookupConfiguration.cs | 3 ++- .../Modularity/ExtensionPropertyUiConfiguration.cs | 4 ++++ .../ModuleExtensionConfigurationHelper.cs | 2 +- .../ObjectExtending/ObjectExtensionPropertyInfo.cs | 3 ++- 12 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiLookupDto.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiDto.cs index 2fb841ec5a..caa5d67957 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiDto.cs @@ -8,5 +8,6 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending public ExtensionPropertyUiTableDto OnTable { get; set; } public ExtensionPropertyUiFormDto OnCreateForm { get; set; } public ExtensionPropertyUiFormDto OnEditForm { get; set; } + public ExtensionPropertyUiLookupDto Lookup { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiLookupDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiLookupDto.cs new file mode 100644 index 0000000000..d7e7237295 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiLookupDto.cs @@ -0,0 +1,13 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ExtensionPropertyUiLookupDto + { + public string Url { get; set; } + public string ResultListPropertyName { get; set; } + public string DisplayPropertyName { get; set; } + public string ValuePropertyName { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs index e27235da91..ba3197f04a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs @@ -22,6 +22,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form public bool DisplayRequiredSymbol { get; set; } = true; public string AutocompleteApiUrl { get; set; } + public string AutocompleteItemsPropertyName { get; set; } public string AutocompleteDisplayPropertyName { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs index c12904edb5..ffa6479470 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs @@ -103,6 +103,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { output.Attributes.AddClass("auto-complete-select"); output.Attributes.Add("data-autocomplete-api-url", TagHelper.AutocompleteApiUrl); + output.Attributes.Add("data-autocomplete-items-property", TagHelper.AutocompleteItemsPropertyName); output.Attributes.Add("data-autocomplete-display-property", TagHelper.AutocompleteDisplayPropertyName); output.Attributes.Add("data-autocomplete-value-property", TagHelper.AutocompleteValuePropertyName); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js index 97e3906a24..099a6a5105 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js @@ -78,6 +78,7 @@ var url = $(this).data("autocompleteApiUrl"); var displayName = $(this).data("autocompleteDisplayProperty"); var displayValue = $(this).data("autocompleteValueProperty"); + var itemsPropertyName = $(this).data("autocompleteItemsProperty"); $select.select2({ ajax: { url: url, @@ -90,7 +91,14 @@ }, processResults: function (data) { var retVal = []; - data.forEach(function (item, index) { + var items = []; + if (itemsPropertyName == "") { + items = data; + } + else { + items = data[itemsPropertyName]; + } + items.forEach(function (item, index) { retVal.push({ id: item[displayValue], text: item[displayName] diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index 76d73820b2..3c51398a8c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -49,7 +49,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending } FillEnums(objectExtensionsDto); - + return objectExtensionsDto; } @@ -140,6 +140,13 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending OnTable = new ExtensionPropertyUiTableDto { IsVisible = propertyConfig.UI.OnTable.IsVisible + }, + Lookup = new ExtensionPropertyUiLookupDto + { + Url = propertyConfig.UI.Lookup.Url, + ResultListPropertyName = propertyConfig.UI.Lookup.ResultListPropertyName, + DisplayPropertyName = propertyConfig.UI.Lookup.DisplayPropertyName, + ValuePropertyName = propertyConfig.UI.Lookup.ValuePropertyName } } }; diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/IBasicObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/IBasicObjectExtensionPropertyInfo.cs index 23492d25ab..ed4447ff51 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/IBasicObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/IBasicObjectExtensionPropertyInfo.cs @@ -35,8 +35,5 @@ namespace Volo.Abp.ObjectExtending /// [CanBeNull] public Func DefaultValueFactory { get; set; } - - [NotNull] - public ExtensionPropertyLookupConfiguration LookupConfiguration { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs index 37eb29d69b..3f366721aa 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs @@ -59,9 +59,6 @@ namespace Volo.Abp.ObjectExtending.Modularity [CanBeNull] public Func DefaultValueFactory { get; set; } - [NotNull] - public ExtensionPropertyLookupConfiguration LookupConfiguration { get; set; } - public ExtensionPropertyConfiguration( [NotNull] EntityExtensionConfiguration entityExtensionConfiguration, [NotNull] Type type, @@ -81,7 +78,6 @@ namespace Volo.Abp.ObjectExtending.Modularity Attributes.AddRange(ExtensionPropertyHelper.GetDefaultAttributes(Type)); DefaultValue = TypeHelper.GetDefaultValue(Type); - LookupConfiguration = new ExtensionPropertyLookupConfiguration(); } public object GetDefaultValue() diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyLookupConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyLookupConfiguration.cs index 7d92f8accd..e781fc8bab 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyLookupConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyLookupConfiguration.cs @@ -2,7 +2,8 @@ { public class ExtensionPropertyLookupConfiguration { - public string ApiUrl { get; set; } + public string Url { get; set; } + public string ResultListPropertyName { get; set; } = "items"; public string DisplayPropertyName { get; set; } = "text"; public string ValuePropertyName { get; set; } = "id"; } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiConfiguration.cs index aa581228bd..0b826a0b3d 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiConfiguration.cs @@ -13,11 +13,15 @@ namespace Volo.Abp.ObjectExtending.Modularity [NotNull] public ExtensionPropertyUiFormConfiguration OnEditForm { get; } + [NotNull] + public ExtensionPropertyLookupConfiguration Lookup { get; set; } + public ExtensionPropertyUiConfiguration() { OnTable = new ExtensionPropertyUiTableConfiguration(); OnCreateForm = new ExtensionPropertyUiFormConfiguration(); OnEditForm = new ExtensionPropertyUiFormConfiguration(); + Lookup = new ExtensionPropertyLookupConfiguration(); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs index 0c6d6b5a2d..4f7d1396af 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs @@ -155,7 +155,7 @@ namespace Volo.Abp.ObjectExtending.Modularity property.Validators.AddRange(propertyConfig.Validators); property.DefaultValue = propertyConfig.DefaultValue; property.DefaultValueFactory = propertyConfig.DefaultValueFactory; - property.LookupConfiguration = propertyConfig.LookupConfiguration; + property.Lookup = propertyConfig.UI.Lookup; } ); } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs index 5b71b0b975..b5da5e6eeb 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs @@ -59,7 +59,7 @@ namespace Volo.Abp.ObjectExtending public Func DefaultValueFactory { get; set; } [NotNull] - public ExtensionPropertyLookupConfiguration LookupConfiguration { get; set; } + public ExtensionPropertyLookupConfiguration Lookup { get; set; } public ObjectExtensionPropertyInfo( [NotNull] ObjectExtensionInfo objectExtension, @@ -76,6 +76,7 @@ namespace Volo.Abp.ObjectExtending Attributes.AddRange(ExtensionPropertyHelper.GetDefaultAttributes(Type)); DefaultValue = TypeHelper.GetDefaultValue(Type); + Lookup = new ExtensionPropertyLookupConfiguration(); } public object GetDefaultValue() From 41d74eb4ada9429dd6bb3d722c04675c0ccf9e0e Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Wed, 11 Nov 2020 14:31:17 +0300 Subject: [PATCH 6/7] update usages. --- .../Pages/Identity/Roles/CreateModal.cshtml | 9 +++++---- .../Pages/Identity/Roles/EditModal.cshtml | 9 +++++---- .../Pages/Identity/Users/CreateModal.cshtml | 9 +++++---- .../Pages/Identity/Users/EditModal.cshtml | 9 +++++---- .../Pages/TenantManagement/Tenants/CreateModal.cshtml | 9 +++++---- .../Pages/TenantManagement/Tenants/EditModal.cshtml | 9 +++++---- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml index 9c1af360d8..07419700e7 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml @@ -24,13 +24,14 @@ @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) { + autocomplete-api-url="@propertyInfo.Lookup.Url" + autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName" + autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName" + autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"> } else { diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml index 56b7c356da..ca45472a02 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml @@ -35,13 +35,14 @@ @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) { + autocomplete-api-url="@propertyInfo.Lookup.Url" + autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName" + autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName" + autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"> } else { diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml index 61bd05a603..52ca75aa5d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml @@ -29,13 +29,14 @@ @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) { + autocomplete-api-url="@propertyInfo.Lookup.Url" + autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName" + autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName" + autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"> } else { diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml index a4c0c7081c..29126ff24b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml @@ -31,13 +31,14 @@ @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) { + autocomplete-api-url="@propertyInfo.Lookup.Url" + autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName" + autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName" + autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"> } else { diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml index 067c98410a..df05a35038 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml @@ -24,13 +24,14 @@ @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) { + autocomplete-api-url="@propertyInfo.Lookup.Url" + autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName" + autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName" + autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"> } else { diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/EditModal.cshtml b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/EditModal.cshtml index 51be8c8079..d35307956c 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/EditModal.cshtml +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/EditModal.cshtml @@ -20,13 +20,14 @@ @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - if (propertyInfo.Type.IsEnum || !propertyInfo.LookupConfiguration.ApiUrl.IsNullOrEmpty()) + if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) { + autocomplete-api-url="@propertyInfo.Lookup.Url" + autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName" + autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName" + autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"> } else { From aa07fb94d601edd6ee106479546936f7f5a6f9e7 Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Wed, 11 Nov 2020 14:44:28 +0300 Subject: [PATCH 7/7] code style fix. --- .../TagHelpers/Form/AbpSelectTagHelper.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs index ba3197f04a..9b5b7a209a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs @@ -22,6 +22,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form public bool DisplayRequiredSymbol { get; set; } = true; public string AutocompleteApiUrl { get; set; } + public string AutocompleteItemsPropertyName { get; set; } public string AutocompleteDisplayPropertyName { get; set; }