Merge pull request #4566 from sbwalker/dev

fix Search theme control so that it checks if search is enabled for site, and include AllowInput parameter to control input textbox
This commit is contained in:
Shaun Walker
2024-08-26 10:41:39 -04:00
committed by GitHub

View File

@ -2,10 +2,13 @@
@using System.Net @using System.Net
@using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http
@inherits ThemeControlBase @inherits ThemeControlBase
@inject ISettingService SettingService
@inject IStringLocalizer<Search> Localizer @inject IStringLocalizer<Search> Localizer
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@if (_searchResultsPage != null) @if (_searchResultsPage != null)
{
@if (AllowInput)
{ {
<span class="app-search @CssClass"> <span class="app-search @CssClass">
<form method="post" class="app-form-inline" @formname="@($"SearchForm")" @onsubmit="@PerformSearch" data-enhance> <form method="post" class="app-form-inline" @formname="@($"SearchForm")" @onsubmit="@PerformSearch" data-enhance>
@ -21,8 +24,16 @@
</form> </form>
</span> </span>
} }
else
{
<form method="post" class="app-form-inline" @formname="@($"SearchForm")" @onsubmit="@PerformSearch" data-enhance>
<input type="hidden" name="@Constants.RequestVerificationToken" value="@SiteState.AntiForgeryToken" />
<button type="submit" class="btn btn-primary">
<span class="oi oi-magnifying-glass align-middle"></span>
</button>
</form>
}
}
@code { @code {
private Page _searchResultsPage; private Page _searchResultsPage;
@ -32,7 +43,10 @@
public string CssClass { get; set; } public string CssClass { get; set; }
[Parameter] [Parameter]
public string SearchResultPagePath { get; set; } = "search"; public bool AllowInput { get; set; } = true; // setting to false will display only the search icon button - not the textbox
[Parameter]
public string SearchResultPagePath { get; set; } = "search"; // setting to "" will disable search
[CascadingParameter] [CascadingParameter]
HttpContext HttpContext { get; set; } HttpContext HttpContext { get; set; }
@ -41,12 +55,15 @@
public string KeyWords { get => ""; set => _keywords = value; } public string KeyWords { get => ""; set => _keywords = value; }
protected override void OnInitialized() protected override void OnInitialized()
{
if (bool.Parse(SettingService.GetSetting(PageState.Site.Settings, "Search_Enabled", "True")))
{ {
if (!string.IsNullOrEmpty(SearchResultPagePath)) if (!string.IsNullOrEmpty(SearchResultPagePath))
{ {
_searchResultsPage = PageState.Pages.FirstOrDefault(i => i.Path == SearchResultPagePath); _searchResultsPage = PageState.Pages.FirstOrDefault(i => i.Path == SearchResultPagePath);
} }
} }
}
private void PerformSearch() private void PerformSearch()
{ {