add search to package manager components
This commit is contained in:
		| @ -7,6 +7,7 @@ | ||||
| @inject ILanguageService LanguageService | ||||
| @inject IPackageService PackageService | ||||
| @inject IStringLocalizer<Add> Localizer | ||||
| @inject IStringLocalizer<SharedResources> SharedLocalizer | ||||
|  | ||||
| @if (_supportedCultures == null) | ||||
| { | ||||
| @ -22,33 +23,33 @@ else | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|             <table class="table table-borderless"> | ||||
|                 <tr> | ||||
|                     <td> | ||||
|                         <Label For="name" HelpText="Name Of The Language" ResourceKey="Name">Name:</Label> | ||||
|                     </td> | ||||
|                     <td> | ||||
|                         <select id="_code" class="form-control" @bind="@_code"> | ||||
|                             @foreach (var culture in _availableCultures) | ||||
|                             { | ||||
|                                 <option value="@culture.Name">@culture.DisplayName</option> | ||||
|                             } | ||||
|                         </select> | ||||
|                     </td> | ||||
|                 </tr> | ||||
|                 <tr> | ||||
|                     <td> | ||||
|                         <Label For="default" HelpText="Indicates Whether Or Not This Language Is The Default For The Site" ResourceKey="IsDefault">Default?</Label> | ||||
|                     </td> | ||||
|                     <td> | ||||
|                         <select id="default" class="form-control" @bind="@_isDefault"> | ||||
|                             <option value="True">@Localizer["Yes"]</option> | ||||
|                             <option value="False">@Localizer["No"]</option> | ||||
|                         </select> | ||||
|                     </td> | ||||
|                 </tr> | ||||
|             </table> | ||||
|             <button type="button" class="btn btn-success" @onclick="SaveLanguage">@Localizer["Save"]</button> | ||||
|                 <table class="table table-borderless"> | ||||
|                     <tr> | ||||
|                         <td> | ||||
|                             <Label For="name" HelpText="Name Of The Language" ResourceKey="Name">Name:</Label> | ||||
|                         </td> | ||||
|                         <td> | ||||
|                             <select id="_code" class="form-control" @bind="@_code"> | ||||
|                                 @foreach (var culture in _availableCultures) | ||||
|                                 { | ||||
|                                     <option value="@culture.Name">@culture.DisplayName</option> | ||||
|                                 } | ||||
|                             </select> | ||||
|                         </td> | ||||
|                     </tr> | ||||
|                     <tr> | ||||
|                         <td> | ||||
|                             <Label For="default" HelpText="Indicates Whether Or Not This Language Is The Default For The Site" ResourceKey="IsDefault">Default?</Label> | ||||
|                         </td> | ||||
|                         <td> | ||||
|                             <select id="default" class="form-control" @bind="@_isDefault"> | ||||
|                                 <option value="True">@Localizer["Yes"]</option> | ||||
|                                 <option value="False">@Localizer["No"]</option> | ||||
|                             </select> | ||||
|                         </td> | ||||
|                     </tr> | ||||
|                 </table> | ||||
|                 <button type="button" class="btn btn-success" @onclick="SaveLanguage">@Localizer["Save"]</button> | ||||
|             } | ||||
|             <NavLink class="btn btn-secondary" href="@NavigateUrl()">@Localizer["Cancel"]</NavLink> | ||||
|         </TabPanel> | ||||
| @ -56,12 +57,25 @@ else | ||||
|             @if (_packages != null && _packages.Count > 0) | ||||
|             { | ||||
|                 <ModuleMessage Type="MessageType.Info" Message="Download one or more translations from the list below. Once you are ready click Install to complete the installation."></ModuleMessage> | ||||
|  | ||||
|                 <table class="table table-borderless" style=" margin: auto; width: 50% !important;"> | ||||
|                     <tr> | ||||
|                         <td> | ||||
|                             <input id="search" class="form-control" placeholder="@SharedLocalizer["Search.Hint"]" @bind="@_search" /> | ||||
|                         </td> | ||||
|                         <td> | ||||
|                             <button type="button" class="btn btn-primary" @onclick="Search">@SharedLocalizer["Search"]</button>  | ||||
|                             <button type="button" class="btn btn-secondary" @onclick="Reset">@SharedLocalizer["Reset"]</button> | ||||
|                         </td> | ||||
|                     </tr> | ||||
|                 </table> | ||||
|  | ||||
|                 <Pager Items="@_packages"> | ||||
|                     <Row> | ||||
|                         <td> | ||||
|                             <h3 style="display: inline;"><a href="@context.ProductUrl" target="_new">@context.Name</a></h3>  by:  <strong><a href="@context.OwnerUrl" target="new">@context.Owner</a></strong><br /> | ||||
|                             <strong>@context.Downloads.ToString("###,###,##0")</strong> downloads  |   released: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>  |  version: <strong>@context.Version</strong><br /> | ||||
|                             @(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description) | ||||
|                             @(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description)<br /> | ||||
|                             <strong>@(String.Format("{0:n0}", context.Downloads))</strong> @SharedLocalizer["Search.Downloads"]  |   @SharedLocalizer["Search.Released"]: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>  |  @SharedLocalizer["Search.Version"]: <strong>@context.Version</strong> | ||||
|                         </td> | ||||
|                         <td style="vertical-align: middle;"> | ||||
|                             <button type="button" class="btn btn-primary" @onclick=@(async () => await DownloadLanguage(context.PackageId, context.Version))>@Localizer["Download"]</button> | ||||
| @ -100,6 +114,7 @@ else | ||||
|     private IEnumerable<Culture> _supportedCultures; | ||||
|     private IEnumerable<Culture> _availableCultures; | ||||
|     private List<Package> _packages; | ||||
|     private string _search = ""; | ||||
|  | ||||
|     public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; | ||||
|  | ||||
| @ -111,7 +126,7 @@ else | ||||
|         _supportedCultures = await LocalizationService.GetCulturesAsync(); | ||||
|         _availableCultures = _supportedCultures | ||||
|             .Where(c => !c.Name.Equals(Constants.DefaultCulture) && !languagesCodes.Contains(c.Name)); | ||||
|         _packages = await PackageService.GetPackagesAsync("translation"); | ||||
|         await LoadTranslations(); | ||||
|  | ||||
|         if (_supportedCultures.Count() == 1) | ||||
|         { | ||||
| @ -123,6 +138,36 @@ else | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task LoadTranslations() | ||||
|     { | ||||
|         _packages = await PackageService.GetPackagesAsync("translation", _search); | ||||
|     } | ||||
|  | ||||
|     private async Task Search() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await LoadTranslations(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error On Search"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task Reset() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _search = ""; | ||||
|             await LoadTranslations(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error On Reset"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task SaveLanguage() | ||||
|     { | ||||
|         var language = new Language | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| @inject IModuleDefinitionService ModuleDefinitionService | ||||
| @inject IPackageService PackageService | ||||
| @inject IStringLocalizer<Add> Localizer | ||||
| @inject IStringLocalizer<SharedResources> SharedLocalizer | ||||
|  | ||||
| @if (_packages != null) | ||||
| { | ||||
| @ -13,12 +14,25 @@ | ||||
|         { | ||||
|             <TabPanel Name="Download" ResourceKey="Download"> | ||||
|                 <ModuleMessage Type="MessageType.Info" Message="Download one or more modules from the list below. Once you are ready click Install to complete the installation."></ModuleMessage> | ||||
|  | ||||
|                 <table class="table table-borderless" style=" margin: auto; width: 50% !important;"> | ||||
|                     <tr> | ||||
|                         <td> | ||||
|                             <input id="search" class="form-control" placeholder="@SharedLocalizer["Search.Hint"]" @bind="@_search" /> | ||||
|                         </td> | ||||
|                         <td> | ||||
|                             <button type="button" class="btn btn-primary" @onclick="Search">@SharedLocalizer["Search"]</button>  | ||||
|                             <button type="button" class="btn btn-secondary" @onclick="Reset">@SharedLocalizer["Reset"]</button> | ||||
|                         </td> | ||||
|                     </tr> | ||||
|                 </table> | ||||
|  | ||||
|                 <Pager Items="@_packages"> | ||||
|                     <Row> | ||||
|                         <td> | ||||
|                             <h3 style="display: inline;"><a href="@context.ProductUrl" target="_new">@context.Name</a></h3>  by:  <strong><a href="@context.OwnerUrl" target="new">@context.Owner</a></strong><br /> | ||||
|                             <strong>@context.Downloads.ToString("###,###,##0")</strong> downloads  |   released: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>  |  version: <strong>@context.Version</strong><br /> | ||||
|                             @(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description) | ||||
|                             @(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description)<br /> | ||||
|                             <strong>@(String.Format("{0:n0}", context.Downloads))</strong> @SharedLocalizer["Search.Downloads"]  |   @SharedLocalizer["Search.Released"]: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>  |  @SharedLocalizer["Search.Version"]: <strong>@context.Version</strong> | ||||
|                         </td> | ||||
|                         <td style="vertical-align: middle;"> | ||||
|                             <button type="button" class="btn btn-primary" @onclick=@(async () => await DownloadModule(context.PackageId, context.Version))>@Localizer["Download"]</button> | ||||
| @ -47,6 +61,7 @@ | ||||
|  | ||||
| @code { | ||||
|     private List<Package> _packages; | ||||
|     private string _search = ""; | ||||
|  | ||||
|     public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; | ||||
|  | ||||
| @ -54,16 +69,7 @@ | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             var moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId); | ||||
|             _packages = await PackageService.GetPackagesAsync("module"); | ||||
|  | ||||
|             foreach (Package package in _packages.ToArray()) | ||||
|             { | ||||
|                 if (moduledefinitions.Exists(item => item.PackageName == package.PackageId)) | ||||
|                 { | ||||
|                     _packages.Remove(package); | ||||
|                 } | ||||
|             } | ||||
|             await LoadModuleDefinitions(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @ -72,6 +78,45 @@ | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task LoadModuleDefinitions() | ||||
|     { | ||||
|         var moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId); | ||||
|         _packages = await PackageService.GetPackagesAsync("module", _search); | ||||
|  | ||||
|         foreach (Package package in _packages.ToArray()) | ||||
|         { | ||||
|             if (moduledefinitions.Exists(item => item.PackageName == package.PackageId)) | ||||
|             { | ||||
|                 _packages.Remove(package); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task Search() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await LoadModuleDefinitions(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error On Search"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task Reset() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _search = ""; | ||||
|             await LoadModuleDefinitions(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error On Reset"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task InstallModules() | ||||
|     { | ||||
|         try | ||||
|  | ||||
| @ -13,7 +13,7 @@ else | ||||
| { | ||||
|     <ActionLink Action="Add" Text="Install Module" ResourceKey="InstallModule" /> | ||||
|     @((MarkupString)" ") | ||||
|     <ActionLink Action="Create" Text="Create Module" ResourceKey="CreateModule" /> | ||||
|     <ActionLink Action="Create" Text="Create Module" ResourceKey="CreateModule" Class="btn btn-secondary" /> | ||||
|  | ||||
|     <Pager Items="@_moduleDefinitions"> | ||||
|         <Header> | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| @inject IThemeService ThemeService | ||||
| @inject IPackageService PackageService | ||||
| @inject IStringLocalizer<Add> Localizer | ||||
| @inject IStringLocalizer<SharedResources> SharedLocalizer | ||||
|  | ||||
| @if (_packages != null) | ||||
| { | ||||
| @ -13,12 +14,25 @@ | ||||
|         { | ||||
|             <TabPanel Name="Download" ResourceKey="Download"> | ||||
|                 <ModuleMessage Type="MessageType.Info" Message="Download one or more themes from the list below. Once you are ready click Install to complete the installation."></ModuleMessage> | ||||
|  | ||||
|                 <table class="table table-borderless" style=" margin: auto; width: 50% !important;"> | ||||
|                     <tr> | ||||
|                         <td> | ||||
|                             <input id="search" class="form-control" placeholder="@SharedLocalizer["Search.Hint"]" @bind="@_search" /> | ||||
|                         </td> | ||||
|                         <td> | ||||
|                             <button type="button" class="btn btn-primary" @onclick="Search">@SharedLocalizer["Search"]</button>  | ||||
|                             <button type="button" class="btn btn-secondary" @onclick="Reset">@SharedLocalizer["Reset"]</button> | ||||
|                         </td> | ||||
|                     </tr> | ||||
|                 </table> | ||||
|  | ||||
|                 <Pager Items="@_packages"> | ||||
|                     <Row> | ||||
|                         <td> | ||||
|                             <h3 style="display: inline;"><a href="@context.ProductUrl" target="_new">@context.Name</a></h3>  by:  <strong><a href="@context.OwnerUrl" target="new">@context.Owner</a></strong><br /> | ||||
|                             <strong>@context.Downloads.ToString("###,###,##0")</strong> downloads  |   released: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>  |  version: <strong>@context.Version</strong><br /> | ||||
|                             @(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description) | ||||
|                             <h3 style="display: inline;"><a href="@context.ProductUrl" target="_new">@context.Name</a></h3>  @SharedLocalizer["Search.By"]:  <strong><a href="@context.OwnerUrl" target="new">@context.Owner</a></strong><br /> | ||||
|                             @(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description)<br /> | ||||
|                             <strong>@(String.Format("{0:n0}", context.Downloads))</strong> @SharedLocalizer["Search.Downloads"]  |   @SharedLocalizer["Search.Released"]: <strong>@context.ReleaseDate.ToString("MMM dd, yyyy")</strong>  |  @SharedLocalizer["Search.Version"]: <strong>@context.Version</strong> | ||||
|                         </td> | ||||
|                         <td style="vertical-align: middle;"> | ||||
|                             <button type="button" class="btn btn-primary" @onclick=@(async () => await DownloadTheme(context.PackageId, context.Version))>@Localizer["Download"]</button> | ||||
| @ -47,6 +61,7 @@ | ||||
|  | ||||
| @code { | ||||
|     private List<Package> _packages; | ||||
|     private string _search = ""; | ||||
|  | ||||
|     public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; | ||||
|  | ||||
| @ -54,16 +69,7 @@ | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             var themes = await ThemeService.GetThemesAsync(); | ||||
|             _packages = await PackageService.GetPackagesAsync("theme"); | ||||
|  | ||||
|             foreach (Package package in _packages.ToArray()) | ||||
|             { | ||||
|                 if (themes.Exists(item => item.PackageName == package.PackageId)) | ||||
|                 { | ||||
|                     _packages.Remove(package); | ||||
|                 } | ||||
|             } | ||||
|             await LoadThemes(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @ -72,6 +78,45 @@ | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task LoadThemes() | ||||
|     { | ||||
|         var themes = await ThemeService.GetThemesAsync(); | ||||
|         _packages = await PackageService.GetPackagesAsync("theme", _search); | ||||
|  | ||||
|         foreach (Package package in _packages.ToArray()) | ||||
|         { | ||||
|             if (themes.Exists(item => item.PackageName == package.PackageId)) | ||||
|             { | ||||
|                 _packages.Remove(package); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task Search() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await LoadThemes(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error On Search"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task Reset() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _search = ""; | ||||
|             await LoadThemes(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error On Reset"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task InstallThemes() | ||||
|     { | ||||
|         try | ||||
|  | ||||
| @ -14,7 +14,7 @@ else | ||||
| { | ||||
|     <ActionLink Action="Add" Text="Install Theme" /> | ||||
|     @((MarkupString)" ") | ||||
|     <ActionLink Action="Create" Text="Create Theme" ResourceKey="CreateTheme" /> | ||||
|     <ActionLink Action="Create" Text="Create Theme" ResourceKey="CreateTheme" Class="btn btn-secondary" /> | ||||
|  | ||||
|     <Pager Items="@_themes"> | ||||
|         <Header> | ||||
|  | ||||
| @ -210,4 +210,25 @@ | ||||
|   <data name="Upload" xml:space="preserve"> | ||||
|     <value>Upload</value> | ||||
|   </data> | ||||
|   <data name="Reset" xml:space="preserve"> | ||||
|     <value>Reset</value> | ||||
|   </data> | ||||
|   <data name="Search" xml:space="preserve"> | ||||
|     <value>Search</value> | ||||
|   </data> | ||||
|   <data name="Search.Hint" xml:space="preserve"> | ||||
|     <value>Enter Search Term</value> | ||||
|   </data> | ||||
|   <data name="Search.By" xml:space="preserve"> | ||||
|     <value>by</value> | ||||
|   </data> | ||||
|   <data name="Search.Downloads" xml:space="preserve"> | ||||
|     <value>downloads</value> | ||||
|   </data> | ||||
|   <data name="Search.Released" xml:space="preserve"> | ||||
|     <value>release date</value> | ||||
|   </data> | ||||
|   <data name="Search.Version" xml:space="preserve"> | ||||
|     <value>version</value> | ||||
|   </data> | ||||
| </root> | ||||
| @ -27,8 +27,7 @@ namespace Oqtane.Services | ||||
|  | ||||
|         public async Task<List<Package>> GetPackagesAsync(string type, string search) | ||||
|         { | ||||
|             List<Package> packages = await GetJsonAsync<List<Package>>($"{Apiurl}?type={type}&search={WebUtility.UrlEncode(search)}"); | ||||
|             return packages.OrderByDescending(item => item.Downloads).ToList(); // order by popularity | ||||
|             return await GetJsonAsync<List<Package>>($"{Apiurl}?type={type}&search={WebUtility.UrlEncode(search)}"); | ||||
|         } | ||||
|  | ||||
|         public async Task DownloadPackageAsync(string packageId, string version, string folder) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker