-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
76 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletions
21
src/Server.UI/Components/Autocompletes/LanguageAutocomplete.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
using System.Globalization; | ||
using CleanArchitecture.Blazor.Infrastructure.Constants.Localization; | ||
|
||
namespace CleanArchitecture.Blazor.Server.UI.Components.Autocompletes; | ||
|
||
public class LanguageAutocomplete<T> : MudAutocomplete<string> | ||
{ | ||
private List<CultureInfo> Languages { get; set; }= CultureInfo.GetCultures(CultureTypes.SpecificCultures).ToList(); | ||
|
||
private List<LanguageCode> Languages { get; set; }= LocalizationConstants.SupportedLanguages.ToList(); | ||
public LanguageAutocomplete() | ||
{ | ||
SearchFunc = SearchFunc_; | ||
Clearable = true; | ||
Dense = true; | ||
ResetValueOnEmptyText = true; | ||
ToStringFunc = x => | ||
{ | ||
var language = Languages.FirstOrDefault(lang => lang.Name.Equals(x)); | ||
return language != null ? $"{language.DisplayName} ({language.Name})" : x; | ||
var language = Languages.FirstOrDefault(lang =>lang.Code.Equals(x, StringComparison.OrdinalIgnoreCase)); | ||
return language != null ? $"{language.DisplayName}" : x; | ||
}; | ||
} | ||
|
||
private Task<IEnumerable<string>> SearchFunc_(string value, CancellationToken cancellation = default) | ||
{ | ||
// 如果输入为空,返回完整的语言列表;否则进行模糊搜索 | ||
return string.IsNullOrEmpty(value) | ||
? Task.FromResult(Languages.Select(lang => lang.Name).AsEnumerable()) | ||
? Task.FromResult(Languages.Select(lang => lang.Code).AsEnumerable()) | ||
: Task.FromResult(Languages | ||
.Where(lang => Contains(lang, value)) | ||
.Select(lang => lang.Name)); | ||
.Select(lang => lang.Code)); | ||
} | ||
|
||
private static bool Contains(CultureInfo language, string value) | ||
private static bool Contains(LanguageCode language, string value) | ||
{ | ||
return language.DisplayName.Contains(value, StringComparison.InvariantCultureIgnoreCase) || | ||
language.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase); | ||
return language.Code.Contains(value, StringComparison.InvariantCultureIgnoreCase) || | ||
language.DisplayName.Contains(value, StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.