From 1e7fa1bb1d4e3b2068ada89f1f1b80c1a992542e Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Thu, 16 Jul 2020 22:37:24 -0400 Subject: [PATCH] Add search query --- WebCms/Controllers/ResultsController.cs | 41 +++++-- WebCms/Models/QueueViewModel.cs | 1 - WebCms/Models/SearchViewModel.cs | 11 ++ WebCms/Views/MacroPartials/Search.cshtml | 2 +- WebCms/Views/Queue/Index.cshtml | 117 ++----------------- WebCms/Views/Results/Index.cshtml | 44 +++++++ WebCms/Views/Results/Search.cshtml | 35 ------ WebCms/Views/Shared/_LeafDataQuery.cshtml | 19 ++- WebCms/Views/Shared/_LeafInputActions.cshtml | 108 +++++++++++++++++ WebCms/WebCms.csproj | 4 +- 10 files changed, 229 insertions(+), 153 deletions(-) create mode 100644 WebCms/Models/SearchViewModel.cs create mode 100644 WebCms/Views/Results/Index.cshtml delete mode 100644 WebCms/Views/Results/Search.cshtml create mode 100644 WebCms/Views/Shared/_LeafInputActions.cshtml diff --git a/WebCms/Controllers/ResultsController.cs b/WebCms/Controllers/ResultsController.cs index d02d9d3..f051886 100644 --- a/WebCms/Controllers/ResultsController.cs +++ b/WebCms/Controllers/ResultsController.cs @@ -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 = diff --git a/WebCms/Models/QueueViewModel.cs b/WebCms/Models/QueueViewModel.cs index 8e5040c..0628af4 100644 --- a/WebCms/Models/QueueViewModel.cs +++ b/WebCms/Models/QueueViewModel.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using LeafWeb.Core.Entities; using LeafWeb.Core.Utility; diff --git a/WebCms/Models/SearchViewModel.cs b/WebCms/Models/SearchViewModel.cs new file mode 100644 index 0000000..62ec9bb --- /dev/null +++ b/WebCms/Models/SearchViewModel.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using LeafWeb.Core.Entities; + +namespace LeafWeb.WebCms.Models +{ + public class SearchViewModel + { + public IEnumerable Items { get; set; } + public LeafDataQuery Q { get; set; } + } +} \ No newline at end of file diff --git a/WebCms/Views/MacroPartials/Search.cshtml b/WebCms/Views/MacroPartials/Search.cshtml index 97fbf3d..4aa016b 100644 --- a/WebCms/Views/MacroPartials/Search.cshtml +++ b/WebCms/Views/MacroPartials/Search.cshtml @@ -1,5 +1,5 @@ @inherits Umbraco.Web.Macros.PartialViewMacroPage @{ - Html.RenderAction("Search", "Results"); + Html.RenderAction("Index", "Results"); } \ No newline at end of file diff --git a/WebCms/Views/Queue/Index.cshtml b/WebCms/Views/Queue/Index.cshtml index 85a6715..6cff067 100644 --- a/WebCms/Views/Queue/Index.cshtml +++ b/WebCms/Views/Queue/Index.cshtml @@ -22,7 +22,11 @@ 100: @Model.TimeInProgressEstimater.EstimateTimeInProgress(100).ToRoundedReadableString()*@
- @Html.Partial("_LeafDataQuery", Model.Q) + @Html.Partial("_LeafDataQuery", Model.Q, + new ViewDataDictionary{ + {"actionName", "Search"}, + {"controllerName", "Queue"}, + {"htmlFormAction", "/admin/manage-queue/"}})
@@ -42,87 +46,27 @@
@grid.PagerList()
-
+
Download Results @DownloadResults()
-
+
} else {

No results.

} +@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) -{ -
-
- - -
-
-} - -@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) -{ - - Input - -} -@helper DownloadOutputToUser(dynamic item) -{ - - ToUser - -} @helper Statistics(LeafInput leafInput) { var summary = new List { "Added Time: " + leafInput.Added }; @@ -162,43 +106,6 @@ else } } -@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) - {disabled} -} - - @helper DownloadResults() {
diff --git a/WebCms/Views/Results/Index.cshtml b/WebCms/Views/Results/Index.cshtml new file mode 100644 index 0000000..4e41099 --- /dev/null +++ b/WebCms/Views/Results/Index.cshtml @@ -0,0 +1,44 @@ +@using LeafWeb.Core.Entities +@using LeafWeb.WebCms.Utility +@model SearchViewModel +@{ + var grid = new WebGrid(Model.Items, rowsPerPage: 45); +} + +
+
+ @Model.Items.Count() results +
+
+ @Html.Partial("_LeafDataQuery", Model.Q, + new ViewDataDictionary{ + {"actionName", "Search"}, + {"controllerName", "Results"}, + {"htmlFormAction", "/leaf-data/search/"}}) +
+
+ +
+ @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() +
+ + +@helper Actions(LeafInput leafInput) +{ + @Html.Partial("_LeafInputActions", leafInput) +} + +@helper Status(LeafInput leafInput) +{ + @Html.Partial("DisplayTemplates/_LeafInputStatus", leafInput) +} diff --git a/WebCms/Views/Results/Search.cshtml b/WebCms/Views/Results/Search.cshtml deleted file mode 100644 index 23509dc..0000000 --- a/WebCms/Views/Results/Search.cshtml +++ /dev/null @@ -1,35 +0,0 @@ -@using LeafWeb.Core.Entities -@using LeafWeb.WebCms.Utility -@model IQueryable -@{ - var grid = new WebGrid(Model, rowsPerPage: 45); -} -dfdf -
- @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() -
- -@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) -} diff --git a/WebCms/Views/Shared/_LeafDataQuery.cshtml b/WebCms/Views/Shared/_LeafDataQuery.cshtml index e7887a7..418af03 100644 --- a/WebCms/Views/Shared/_LeafDataQuery.cshtml +++ b/WebCms/Views/Shared/_LeafDataQuery.cshtml @@ -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})) {
diff --git a/WebCms/Views/Shared/_LeafInputActions.cshtml b/WebCms/Views/Shared/_LeafInputActions.cshtml new file mode 100644 index 0000000..1276aaa --- /dev/null +++ b/WebCms/Views/Shared/_LeafInputActions.cshtml @@ -0,0 +1,108 @@ +@using LeafWeb.Core.Entities +@using LeafWeb.WebCms.Utility +@model LeafInput +@{ + var admin = ViewData.ContainsKey("admin"); +} + +
+
+ + +
+
+ +@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) +{ + + Input + +} +@helper DownloadOutputToUser(dynamic item) +{ + + ToUser + +} +@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) + {disabled} +} + diff --git a/WebCms/WebCms.csproj b/WebCms/WebCms.csproj index 6c6afc0..b1e6530 100644 --- a/WebCms/WebCms.csproj +++ b/WebCms/WebCms.csproj @@ -996,7 +996,7 @@ - + @@ -1071,6 +1071,7 @@ + Web.config @@ -1120,6 +1121,7 @@ +