Skip to content

Commit

Permalink
Merge pull request #31 from blackWins/fix-local-cache-filter-bug
Browse files Browse the repository at this point in the history
Fixed: Local cache filter parameter error
  • Loading branch information
gdlcf88 authored May 30, 2024
2 parents 371709a + 44b59c6 commit 4e94fa4
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected virtual string GetScriptCode(TagHelperContext context, EasySelectorAtt

var dropdownParent = easySelectorAttribute.RunScriptOnWindowLoad ? "" : $"dropdownParent: $('#{tagId}').parent().parent(),";

var transport = easySelectorAttribute.EnableCache ? $",transport:function(params,success,failure){{if(!params.data.filter&&params.data.skipCount<{tagId.ToCamelCase()}cacheList.length){{return success({{totalCount:{tagId.ToCamelCase()}cacheList.length,{easySelectorAttribute.ItemListPropertyName}:{tagId.ToCamelCase()}cacheList}});}}if(params.data.filter&&{tagId.ToCamelCase()}cacheList.length&&params.data.skipCount<params.data.maxResultCount){{let matchList={tagId.ToCamelCase()}cacheList.filter(function(item){{return!params.data.filter||stringMatch(params.data.filter,item.name??item.userName);}});if(matchList.length>params.data.skipCount)return success({{totalCount:params.data.maxResultCount*2,{easySelectorAttribute.ItemListPropertyName}:matchList}});}}if(params.data.skipCount != 0 && {tagId.ToCamelCase()}cacheList.length > params.data.skipCount - params.data.maxResultCount){{params.data.skipCount -= params.data.maxResultCount;}}var $request=$.ajax(params);$request.then((res)=>{{res.{easySelectorAttribute.ItemListPropertyName} = res.{easySelectorAttribute.ItemListPropertyName}.filter(v => {{ return {tagId.ToCamelCase()}cacheList.every(e => e.{easySelectorAttribute.KeyPropertyName} != v.{easySelectorAttribute.KeyPropertyName}); }});{tagId.ToCamelCase()}cacheList = [...{tagId.ToCamelCase()}cacheList, ...res.{easySelectorAttribute.ItemListPropertyName}];success(res);}});$request.fail(failure);return $request;}}" : "";
var transport = easySelectorAttribute.EnableCache ? $",transport:function(params,success,failure){{if(!params.data.{easySelectorAttribute.FilterParamName}&&params.data.skipCount<{tagId.ToCamelCase()}cacheList.length){{return success({{totalCount:{tagId.ToCamelCase()}cacheList.length,{easySelectorAttribute.ItemListPropertyName}:{tagId.ToCamelCase()}cacheList}});}}if(params.data.{easySelectorAttribute.FilterParamName}&&{tagId.ToCamelCase()}cacheList.length&&params.data.skipCount<params.data.maxResultCount){{let matchList={tagId.ToCamelCase()}cacheList.filter(function(item){{return!params.data.{easySelectorAttribute.FilterParamName}||stringMatch(params.data.{easySelectorAttribute.FilterParamName},item.name??item.userName);}});if(matchList.length>params.data.skipCount)return success({{totalCount:params.data.maxResultCount*2,{easySelectorAttribute.ItemListPropertyName}:matchList}});}}if(params.data.skipCount != 0 && {tagId.ToCamelCase()}cacheList.length > params.data.skipCount - params.data.maxResultCount){{params.data.skipCount -= params.data.maxResultCount;}}var $request=$.ajax(params);$request.then((res)=>{{res.{easySelectorAttribute.ItemListPropertyName} = res.{easySelectorAttribute.ItemListPropertyName}.filter(v => {{ return {tagId.ToCamelCase()}cacheList.every(e => e.{easySelectorAttribute.KeyPropertyName} != v.{easySelectorAttribute.KeyPropertyName}); }});{tagId.ToCamelCase()}cacheList = [...{tagId.ToCamelCase()}cacheList, ...res.{easySelectorAttribute.ItemListPropertyName}];success(res);}});$request.fail(failure);return $request;}}" : "";

var baseUrl = configuration?.BaseUrl;
var innerCode = $"$(function () {{ let {tagId.ToCamelCase()}cacheList = [];let currentValues = {_jsonSerializer.Serialize(currentValues)}; function stringMatch(term,candidate){{return candidate&&candidate.toLowerCase().indexOf(term.toLowerCase())>=0}}; function matchCustom(params,data){{if($.trim(params.term)===\"\"){{return data}}if(typeof data.text===\"undefined\"){{return null}}if(stringMatch(params.term,data.text)){{return data}}if(stringMatch(params.term,state.id)){{return data}}return null}}; let select2Item = function (state) {{ return $('<span>' + state.text{subTextContent} + '</span>'); }}; let select2Option = {{ allowClear: true,minimumInputLength:{easySelectorAttribute.MinimumInputLength}, width: \"100%\", matcher: matchCustom, templateResult: select2Item, templateSelection: select2Item,{dropdownParent} ajax: {{ url: '{baseUrl}{easySelectorAttribute.GetListedDataSourceUrl}', dataType: \"json\", delay: {easySelectorAttribute.Delay}, data: function (params) {{ params.page = params.page || 1; return {{ {easySelectorAttribute.FilterParamName}: params.term, skipCount: (params.page - 1) * {easySelectorAttribute.MaxResultCount}, maxResultCount: {easySelectorAttribute.MaxResultCount}, }} }}{transport}, processResults: function (data, params) {{ params.page = params.page || 1; return {{ results: data.{easySelectorAttribute.ItemListPropertyName}.map(function (item) {{ return {{ id: item.{easySelectorAttribute.KeyPropertyName}, text: item.{easySelectorAttribute.TextPropertyName} ?? item.{easySelectorAttribute.AlternativeTextPropertyName} }} }}), pagination: {{ more: (params.page * {easySelectorAttribute.MaxResultCount}) < data.totalCount }} }}; }}, cache: true }}, placeholder: {{ id: '', text: '{placeHolder}' }} }}; $(\"#{tagId}\").select2(select2Option); currentValues && currentValues.values.forEach(function(e) {{ if (!$(\"#{tagId}\").find('option:contains(' + e + ')').length && (e != \"00000000-0000-0000-0000-000000000000\" && e != \"\" && e != \"0\")) abp.ajax({{ type: 'GET', url: '{baseUrl}{easySelectorAttribute.GetSingleDataSourceUrl}'.replace('{{id}}', e), success: function (result) {{ $(\"#{tagId}\").append($('<option value=\"' + e + '\">').text(result.{easySelectorAttribute.TextPropertyName} ?? result.{easySelectorAttribute.AlternativeTextPropertyName})); $(\"#{tagId}\").val(currentValues.values).trigger('change'); }}}}); }}); }});";
Expand Down

0 comments on commit 4e94fa4

Please sign in to comment.