Add search query

This commit is contained in:
2020-07-16 22:37:24 -04:00
parent 15c38fb650
commit 1e7fa1bb1d
10 changed files with 229 additions and 153 deletions
+32 -9
View File
@@ -3,22 +3,45 @@ using System.Linq;
using System.Web.Mvc;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Utility;
using LeafWeb.WebCms.Models;
using LeafWeb.WebCms.Utility;
using Umbraco.Web.Mvc;
namespace LeafWeb.WebCms.Controllers
{
public class ResultsController : BaseController
{
[MemberAuthorize(AllowGroup = "Authenticated")]
public ActionResult Search()
{
var viewModel =
from li in DataService.GetLeafInputsOrdered()
select li;
return View(viewModel);
}
//[MemberAuthorize(AllowGroup = "Authenticated")]
public ActionResult Index(LeafDataQuery query)
{
var resultItems =
DataService.GetLeafInputsOrdered();
public ActionResult Recent()
resultItems = QueryFilter.Search(resultItems, query);
var searchViewModel = new SearchViewModel
{
Items = resultItems,
Q = query
};
return View(searchViewModel);
}
//[MemberAuthorize(AllowGroup = "Authenticated")]
[HttpPost]
public ActionResult Search(LeafDataQuery query)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
return RedirectToCurrentUmbracoPage(query.GetNameValueCollection());
}
public ActionResult Recent()
{
var dateThreshold = DateTime.Today.Subtract(TimeSpan.FromDays(90));
var viewModel =
-1
View File
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Utility;
+11
View File
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using LeafWeb.Core.Entities;
namespace LeafWeb.WebCms.Models
{
public class SearchViewModel
{
public IEnumerable<LeafInput> Items { get; set; }
public LeafDataQuery Q { get; set; }
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
Html.RenderAction("Search", "Results");
Html.RenderAction("Index", "Results");
}
+12 -105
View File
@@ -22,7 +22,11 @@
<i class="fa fa-file-o"></i> 100: <strong>@Model.TimeInProgressEstimater.EstimateTimeInProgress(100).ToRoundedReadableString()</strong>*@
</div>
<div class="col-12 col-sm-9">
@Html.Partial("_LeafDataQuery", Model.Q)
@Html.Partial("_LeafDataQuery", Model.Q,
new ViewDataDictionary{
{"actionName", "Search"},
{"controllerName", "Queue"},
{"htmlFormAction", "/admin/manage-queue/"}})
</div>
</div>
@@ -42,87 +46,27 @@
</div>
<div class="row justify-content-end">
<div class="col-sm">@grid.PagerList()</div>
<div class="col-sm col-lg-5 pl-4 pt-3 pt-sm-0" >
<div class="col-sm col-lg-5 pl-4 pt-3 pt-sm-0">
<span class="pr-2">Download Results</span>
@DownloadResults()
</div>
</div>
</div>
}
else
{
<p>No results.</p>
}
@helper Actions(LeafInput leafInput)
{
@Html.Partial("_LeafInputActions", leafInput, new ViewDataDictionary {{"admin", true}})
}
@helper Status(LeafInput leafInput)
{
@Html.Partial("DisplayTemplates/_LeafInputStatus", leafInput)
}
@helper Actions(LeafInput item)
{
<div class="btn-group text-nowrap" role="group">
<div class="btn-group" role="group">
<button id="actions(@item.Id)" type="button" class="btn btn-outline-secondary btn-sm dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Actions">
<span class="d-none d-sm-inline">Actions</span>
</button>
<div class="dropdown-menu" aria-labelledby="actions(@item.Id)">
@DetailsLink(item)
@ChartLink(item)
@if (item.IsPending)
{
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">Priority</h6>
<button class="dropdown-item @DisableItem(item.PendingPriority == Priority.High)">@PriorityForm(item, Priority.High)</button>
<button class="dropdown-item @DisableItem(item.PendingPriority == Priority.Normal)">@PriorityForm(item, Priority.Normal)</button>
<button class="dropdown-item @DisableItem(item.PendingPriority == Priority.Low)">@PriorityForm(item, Priority.Low)</button>
}
@if (item.IsCancellable)
{
<div class="dropdown-divider"></div>
@CancelLink(item)
}
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">Download</h6>
@DownloadInput(item)
@DownloadOutputToUser(item)
<div class="dropdown-divider"></div>
@DeleteLink(item)
</div>
</div>
</div>
}
@helper DetailsLink(dynamic item)
{
var cssClass = CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
@Html.Partial("DisplayTemplates/_DetailsLink", (int)item.Id, cssClass)
}
@helper ChartLink(dynamic item)
{
var cssClass = CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
if (!item.HasLeafChart)
{
cssClass.SetCssDisabled();
}
@Html.Partial("DisplayTemplates/_ChartLink", (int)item.Id, cssClass)
}
@helper DownloadInput(dynamic item)
{
<a href="@Url.Action("DownloadInput", "Queue", new {id = item.Id})" class="dropdown-item">
<span class="fa fa-download"></span> Input
</a>
}
@helper DownloadOutputToUser(dynamic item)
{
<a href="@Url.Action("DownloadOutputToUser", "Queue", new {id = item.Id})" class="dropdown-item @DisableItem(!item.HasOutputFiles)">
<span class="fa fa-download"></span> ToUser
</a>
}
@helper Statistics(LeafInput leafInput)
{
var summary = new List<string> { "Added Time: " + leafInput.Added };
@@ -162,43 +106,6 @@ else
}
</span>
}
@helper DeleteLink(LeafInput item)
{
var cssClass
= CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
if (!item.IsDeletable)
{
cssClass.SetCssDisabled();
}
@Html.Partial("DisplayTemplates/_DeleteForm", Tuple.Create(item.Id, item.Identifier), cssClass)
}
@helper CancelLink(LeafInput item)
{
var cssClass
= CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
if (!item.IsCancellable)
{
cssClass.SetCssDisabled();
}
@Html.Partial("DisplayTemplates/_CancelForm", Tuple.Create(item.Id, item.Identifier), cssClass)
}
@helper PriorityForm(LeafInput item, Priority priority)
{
var cssClass
= CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
@Html.Partial("DisplayTemplates/_PriorityForm", Tuple.Create(item.Id, item.PendingPriority, priority), cssClass)
}
@helper DisableItem(bool disabled)
{
if (disabled)
{<text>disabled</text>}
}
@helper DownloadResults()
{
<div class="btn-group" role="group" aria-label="Download">
+44
View File
@@ -0,0 +1,44 @@
@using LeafWeb.Core.Entities
@using LeafWeb.WebCms.Utility
@model SearchViewModel
@{
var grid = new WebGrid(Model.Items, rowsPerPage: 45);
}
<div class="row align-items-end">
<div class="col-3 order-last order-sm-first font-italic font-weight-light ">
<strong>@Model.Items.Count()</strong> results
</div>
<div class="col-12 col-sm-9">
@Html.Partial("_LeafDataQuery", Model.Q,
new ViewDataDictionary{
{"actionName", "Search"},
{"controllerName", "Results"},
{"htmlFormAction", "/leaf-data/search/"}})
</div>
</div>
<div class="table-responsive">
@grid.Table(columns:
grid.Columns(
grid.Column("Identifier", "Identifier"),
grid.Column("SiteId", "Site Id"),
//grid.Column("Name", "Submitted By"),
grid.Column("CurrentStatus", "Status", item => Status(item.Value)),
grid.Column("", format: item => Actions(item.Value), canSort: false)
),
htmlAttributes: new { @class = "table table-sm table-striped table-bordered table-hover" }
)
@grid.PagerList()
</div>
@helper Actions(LeafInput leafInput)
{
@Html.Partial("_LeafInputActions", leafInput)
}
@helper Status(LeafInput leafInput)
{
@Html.Partial("DisplayTemplates/_LeafInputStatus", leafInput)
}
-35
View File
@@ -1,35 +0,0 @@
@using LeafWeb.Core.Entities
@using LeafWeb.WebCms.Utility
@model IQueryable<LeafInput>
@{
var grid = new WebGrid(Model, rowsPerPage: 45);
}
dfdf
<div class="table-responsive">
@grid.Table(columns:
grid.Columns(
grid.Column("Identifier", "Identifier"),
grid.Column("SiteId", "Site Id"),
//grid.Column("Name", "Submitted By"),
grid.Column("CurrentStatus", "Status", item => Status(item.Value)),
grid.Column("", "", item => ChartLink(item.Value))
),
htmlAttributes: new { @class = "table table-sm table-striped table-bordered table-hover" }
)
@grid.PagerList()
</div>
@helper ChartLink(LeafInput leafInput)
{
var cssClass = CssClassUtil.CreateCssClassDataDictionary("btn", " btn-outline-secondary", "btn-sm");
if (!leafInput.HasLeafChart)
{
cssClass.SetCssDisabled();
}
@Html.Partial("DisplayTemplates/_ChartButton", leafInput.Id, cssClass)
}
@helper Status(LeafInput leafInput)
{
@Html.Partial("DisplayTemplates/_LeafInputStatus", leafInput)
}
+18 -1
View File
@@ -5,8 +5,25 @@
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js", 2);
Html.RequiresJs("~/scripts/jquery.validate.custom.js", 2);
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.js", 2);
string actionName = string.Empty;// = "Search";
string controllerName = string.Empty;// = "Queue";
string htmlFormAction = string.Empty;// = "/admin/manage-queue/";
if (ViewData.ContainsKey("actionName"))
{
actionName = (string)ViewData["actionName"];
}
if (ViewData.ContainsKey("controllerName"))
{
controllerName = (string)ViewData["controllerName"];
}
if (ViewData.ContainsKey("htmlFormAction"))
{
htmlFormAction = (string)ViewData["htmlFormAction"];
}
}
@using (Html.BeginUmbracoForm("Search", "Queue", null, new {action = "/leaf-data/manage-queue/"}))
@using (Html.BeginUmbracoForm(actionName, controllerName, null, new {action = htmlFormAction}))
{
<div class="input-group pl-5">
<input name="q" type="text" class="form-control" placeholder="Search for..." value="@Model.q">
@@ -0,0 +1,108 @@
@using LeafWeb.Core.Entities
@using LeafWeb.WebCms.Utility
@model LeafInput
@{
var admin = ViewData.ContainsKey("admin");
}
<div class="btn-group text-nowrap" role="group">
<div class="btn-group" role="group">
<button id="actions(@Model.Id)" type="button" class="btn btn-outline-secondary btn-sm dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Actions">
<span class="d-none d-sm-inline">Actions</span>
</button>
<div class="dropdown-menu" aria-labelledby="actions(@Model.Id)">
@DetailsLink(Model)
@ChartLink(Model)
@if (admin && Model.IsPending)
{
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">Priority</h6>
<button class="dropdown-item @DisableItem(Model.PendingPriority == Priority.High)">@PriorityForm(Model, Priority.High)</button>
<button class="dropdown-item @DisableItem(Model.PendingPriority == Priority.Normal)">@PriorityForm(Model, Priority.Normal)</button>
<button class="dropdown-item @DisableItem(Model.PendingPriority == Priority.Low)">@PriorityForm(Model, Priority.Low)</button>
}
@if (admin && Model.IsCancellable)
{
<div class="dropdown-divider"></div>
@CancelLink(Model)
}
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">Download</h6>
@DownloadInput(Model)
@DownloadOutputToUser(Model)
@if (admin)
{
<div class="dropdown-divider"></div>
@DeleteLink(Model)
}
</div>
</div>
</div>
@helper DetailsLink(dynamic item)
{
var cssClass = CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
@Html.Partial("DisplayTemplates/_DetailsLink", (int)item.Id, cssClass)
}
@helper ChartLink(dynamic item)
{
var cssClass = CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
if (!item.HasLeafChart)
{
cssClass.SetCssDisabled();
}
@Html.Partial("DisplayTemplates/_ChartLink", (int)item.Id, cssClass)
}
@helper DownloadInput(dynamic item)
{
<a href="@Url.Action("DownloadInput", "Queue", new {id = item.Id})" class="dropdown-item">
<span class="fa fa-download"></span> Input
</a>
}
@helper DownloadOutputToUser(dynamic item)
{
<a href="@Url.Action("DownloadOutputToUser", "Queue", new {id = item.Id})" class="dropdown-item @DisableItem(!item.HasOutputFiles)">
<span class="fa fa-download"></span> ToUser
</a>
}
@helper DeleteLink(LeafInput item)
{
var cssClass
= CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
if (!item.IsDeletable)
{
cssClass.SetCssDisabled();
}
@Html.Partial("DisplayTemplates/_DeleteForm", Tuple.Create(item.Id, item.Identifier), cssClass)
}
@helper CancelLink(LeafInput item)
{
var cssClass
= CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
if (!item.IsCancellable)
{
cssClass.SetCssDisabled();
}
@Html.Partial("DisplayTemplates/_CancelForm", Tuple.Create(item.Id, item.Identifier), cssClass)
}
@helper PriorityForm(LeafInput item, Priority priority)
{
var cssClass
= CssClassUtil.CreateCssClassDataDictionary("dropdown-item");
@Html.Partial("DisplayTemplates/_PriorityForm", Tuple.Create(item.Id, item.PendingPriority, priority), cssClass)
}
@helper DisableItem(bool disabled)
{
if (disabled)
{<text>disabled</text>}
}
+3 -1
View File
@@ -996,7 +996,7 @@
<Content Include="Views\MacroPartials\LeafInputCreate.cshtml" />
<None Include="Backload\Web.Backload.config" />
<Content Include="Views\Results\DownloadNotFound.cshtml" />
<Content Include="Views\Results\Search.cshtml" />
<Content Include="Views\Results\Index.cshtml" />
<Content Include="Views\MacroPartials\Results.cshtml" />
<Content Include="Views\Chart\DataError.cshtml" />
<Content Include="Views\Chart\Index.cshtml" />
@@ -1071,6 +1071,7 @@
<Content Include="Views\Shared\_LeafDataQuery.cshtml" />
<Content Include="Views\Results\Recent.cshtml" />
<Content Include="Views\MacroPartials\Search.cshtml" />
<Content Include="Views\Shared\_LeafInputActions.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
@@ -1120,6 +1121,7 @@
<Compile Include="Models\LeafInputDetails.cs" />
<Compile Include="Models\LeafInputCreate.cs" />
<Compile Include="Models\LeafInputStatusViewModel.cs" />
<Compile Include="Models\SearchViewModel.cs" />
<Compile Include="Models\QueueViewModel.cs" />
<Compile Include="Models\SelectListViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />