Search now works more than once
Browser validation for search
This commit is contained in:
@@ -20,14 +20,16 @@ namespace LeafWeb.WebCms.Controllers
|
||||
private const int TimeSamples = 40;
|
||||
|
||||
public ActionResult Index(LeafDataQuery query)
|
||||
{
|
||||
{
|
||||
//query.lat = 32;
|
||||
|
||||
var resultItems =
|
||||
DataService.GetLeafInputsOrdered();
|
||||
|
||||
// search functionality
|
||||
if (!string.IsNullOrEmpty(query.Query))
|
||||
if (!string.IsNullOrEmpty(query.q))
|
||||
{
|
||||
foreach (var piece in query.Query.Split(' ').Select(p => p.Trim()))
|
||||
foreach (var piece in query.q.Split(' ').Select(p => p.Trim()))
|
||||
{
|
||||
resultItems =
|
||||
from li in resultItems
|
||||
@@ -46,17 +48,28 @@ namespace LeafWeb.WebCms.Controllers
|
||||
{
|
||||
Items = resultItems,
|
||||
ServerDescription = serviceDescription,
|
||||
Query = new LeafDataQuery
|
||||
{
|
||||
Query = query.Query
|
||||
},
|
||||
Q = query,
|
||||
TimeInProgressEstimater = timeInProgressEstimater
|
||||
};
|
||||
|
||||
return View(queueViewModel);
|
||||
}
|
||||
|
||||
private TimeInProgressEstimater TimeInProgressEstimater()
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Search(LeafDataQuery q)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return CurrentUmbracoPage();
|
||||
}
|
||||
//if (q == null)
|
||||
// return CurrentUmbracoPage();
|
||||
//var collection = q.GetNameValueCollection();
|
||||
return RedirectToCurrentUmbracoPage(q.GetNameValueCollection());
|
||||
}
|
||||
|
||||
private TimeInProgressEstimater TimeInProgressEstimater()
|
||||
{
|
||||
|
||||
// TODO: move this to a background process
|
||||
@@ -80,12 +93,6 @@ namespace LeafWeb.WebCms.Controllers
|
||||
return Content(string.Join("<br />", data));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Search(LeafDataQuery query)
|
||||
{
|
||||
var collection = new NameValueCollection() {{"Query.Query", query.Query}};
|
||||
return RedirectToCurrentUmbracoPage(collection);
|
||||
}
|
||||
|
||||
private static string ServiceDescription()
|
||||
{
|
||||
|
||||
@@ -1,35 +1,39 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AutoMapper;
|
||||
using LeafWeb.Core.DAL;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.WebCms.Controllers;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LeafWeb.WebCms.Models
|
||||
{
|
||||
public class LeafDataQuery
|
||||
{
|
||||
/// <summary>Query</summary>
|
||||
[Display(Name = "Search", Description = "General query")]
|
||||
public string Query { get; set; }
|
||||
public string q { get; set; }
|
||||
|
||||
[Display(Name = "Site ID", Description = "The site's name/Fluxnet ID, if known")]
|
||||
public string SiteId { get; set; }
|
||||
[RegularExpression(@".{3,}", ErrorMessage = "Specify at least three characters")]
|
||||
public string siteid { get; set; }
|
||||
|
||||
[Display(Name = "Species Name")]
|
||||
public string SpeciesName { get; set; }
|
||||
[RegularExpression(@".{3,}", ErrorMessage = "Specify at least three characters")]
|
||||
public string species { get; set; }
|
||||
|
||||
/// <summary>Site latitude, northern hemisphere positive</summary>
|
||||
[RegularExpression(@"\d{0,2}", ErrorMessage = "Site latitude, northern hemisphere positive")]
|
||||
public int Latitude { get; set; }
|
||||
[Display(Name = "Latitude")]
|
||||
[RegularExpression(@"^-?([0-9]|[1-8][0-9]|90)$", ErrorMessage = "Site latitude, northern hemisphere positive, -90 – 90")]
|
||||
public string lat { get; set; }
|
||||
|
||||
[Display(Name = "Range")]
|
||||
public string LatitudeRange { get; set; }
|
||||
[RegularExpression(@"^([0-9]|[1-8][0-9]|90)$", ErrorMessage = "± latitude degrees")]
|
||||
public string latr { get; set; }
|
||||
|
||||
/// <summary>Site longitude, east positive</summary>
|
||||
[RegularExpression(@"\d{0,2}", ErrorMessage = "Site longitude, east positive")]
|
||||
public string Longitude { get; set; }
|
||||
[Display(Name = "Longitude")]
|
||||
[RegularExpression(@"^-?([0-9]|[1-8][0-9]|9[0-9]|1[0-7][0-9]|180)$", ErrorMessage = "Site longitude, east positive, -180 – 180")]
|
||||
public string lon { get; set; }
|
||||
|
||||
[Display(Name = "Range")]
|
||||
public string LongitudeRange { get; set; }
|
||||
[RegularExpression(@"^([0-9]|[1-8][0-9]|9[0-9]|1[0-7][0-9]|180)$", ErrorMessage = "± longitude degrees")]
|
||||
public string lonr { get; set; }
|
||||
|
||||
static LeafDataQuery()
|
||||
{
|
||||
@@ -43,5 +47,25 @@ namespace LeafWeb.WebCms.Models
|
||||
{
|
||||
//PhotosynthesisType = new SelectListViewModel();
|
||||
}
|
||||
|
||||
public NameValueCollection GetNameValueCollection(string prefix="")
|
||||
{
|
||||
var nvs = new NameValueCollection();
|
||||
|
||||
prefix =
|
||||
string.IsNullOrEmpty(prefix)
|
||||
? ""
|
||||
: prefix + ".";
|
||||
|
||||
foreach (var pi in typeof(LeafDataQuery).GetProperties())
|
||||
{
|
||||
var value = pi.GetValue(this, null);
|
||||
if (value == null)
|
||||
continue;
|
||||
nvs.Add(prefix + pi.Name, value?.ToString());
|
||||
}
|
||||
|
||||
return nvs;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace LeafWeb.WebCms.Models
|
||||
public string ServerDescription { get; set; }
|
||||
public string ServerStatus { get; set; }
|
||||
public IEnumerable<LeafInput> Items { get; set; }
|
||||
public LeafDataQuery Query { get; set; }
|
||||
public LeafDataQuery Q { get; set; }
|
||||
public TimeInProgressEstimater TimeInProgressEstimater { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,16 @@
|
||||
@model QueueViewModel
|
||||
|
||||
@{
|
||||
Html.RequiresJs("~/scripts/jquery.validate.min.js", 2);
|
||||
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);
|
||||
Html.RequiresJs("~/scripts/Queue.js");
|
||||
|
||||
var grid = new WebGrid(Model.Items, rowsPerPage: 45);
|
||||
}
|
||||
|
||||
@using (Html.BeginUmbracoForm<QueueController>("Search", FormMethod.Post))
|
||||
@using (Html.BeginUmbracoForm("Search", "Queue", null, new {@action = "/leaf-data/manage-queue/"}))
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
@@ -21,7 +25,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="input-group">
|
||||
<input name="Query.Query" type="text" class="form-control" placeholder="Search for..." value="@Model.Query.Query">
|
||||
<input name="Q.q" type="text" class="form-control" placeholder="Search for..." value="@Model.Q.q">
|
||||
<span class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" type="submit">Search</button>
|
||||
<button class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" type="button"
|
||||
@@ -37,10 +41,10 @@
|
||||
<div class="col-lg-8 offset-lg-4 card card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
@Html.EditorFor(m => m.Query.SiteId)
|
||||
@Html.EditorFor(m => m.Q.siteid)
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
@Html.EditorFor(m => m.Query.SpeciesName)
|
||||
@Html.EditorFor(m => m.Q.species)
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
@@ -48,20 +52,20 @@
|
||||
<div class="col-md-6">
|
||||
<div class="row">
|
||||
<div class="col-sm-7">
|
||||
@Html.EditorFor(m => m.Query.Latitude, new {size = "small", append = "°"})
|
||||
@Html.EditorFor(m => m.Q.lat, new {size = "small", append = "°"})
|
||||
</div>
|
||||
<div class="col-sm-5">
|
||||
@Html.EditorFor(m => m.Query.LatitudeRange, new {size = "small", prepend = "±", append = "°"})
|
||||
@Html.EditorFor(m => m.Q.latr, new {size = "small", prepend = "±", append = "°"})
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-6 border-left">
|
||||
<div class="row">
|
||||
<div class="col-sm-7">
|
||||
@Html.EditorFor(m => m.Query.Longitude, new {size = "small", append = "°"})
|
||||
@Html.EditorFor(m => m.Q.lon, new {size = "small", append = "°"})
|
||||
</div>
|
||||
<div class="col-sm-5">
|
||||
@Html.EditorFor(m => m.Query.LongitudeRange, new {size = "small", prepend = "±", append = "°"})
|
||||
@Html.EditorFor(m => m.Q.lonr, new {size = "small", prepend = "±", append = "°"})
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user