From 28377cfce847309907162702a8512c2e77a511e2 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Sat, 18 Jul 2020 21:39:18 -0400 Subject: [PATCH] Add object for results details --- WebCms.Tests/Models/LeafInputDetailsTests.cs | 2 +- WebCms/App_Start/AutoMapperConfig.cs | 2 +- WebCms/Controllers/LeafWebPageIds.cs | 4 +- WebCms/Controllers/QueueController.cs | 2 +- WebCms/Controllers/ResultsController.cs | 19 +++++- WebCms/Models/LeafInputDetails.cs | 26 ++++---- WebCms/Models/LeafInputDetails_Admin.cs | 23 +++++++ WebCms/Views/Queue/Details.cshtml | 6 +- WebCms/Views/Results/Details.cshtml | 61 +++++++++++++++++++ ...sLink.cshtml => _Details_AdminLink.cshtml} | 2 +- .../_Details_ResultsLink.cshtml | 9 +++ WebCms/Views/Shared/_LeafDataQuery.cshtml | 6 +- WebCms/Views/Shared/_LeafInputActions.cshtml | 20 +++++- WebCms/WebCms.csproj | 7 ++- 14 files changed, 156 insertions(+), 33 deletions(-) create mode 100644 WebCms/Models/LeafInputDetails_Admin.cs create mode 100644 WebCms/Views/Results/Details.cshtml rename WebCms/Views/Shared/DisplayTemplates/{_DetailsLink.cshtml => _Details_AdminLink.cshtml} (91%) create mode 100644 WebCms/Views/Shared/DisplayTemplates/_Details_ResultsLink.cshtml diff --git a/WebCms.Tests/Models/LeafInputDetailsTests.cs b/WebCms.Tests/Models/LeafInputDetailsTests.cs index e6567f1..970d1d5 100644 --- a/WebCms.Tests/Models/LeafInputDetailsTests.cs +++ b/WebCms.Tests/Models/LeafInputDetailsTests.cs @@ -137,7 +137,7 @@ namespace LeafWeb.WebCms.Tests.Models public void CanConstructFromLeafInputFile() { var leafInput = GetLeafInput; - var viewModel = new LeafInputDetails(leafInput); + var viewModel = new LeafInputDetails_Admin(leafInput); //Assert.That(viewModel.CurrentStatus, Is.EqualTo(leafInput.CurrentStatus.ToString())); Assert.That(viewModel.StatusHistory, Has.Count.EqualTo(5)); diff --git a/WebCms/App_Start/AutoMapperConfig.cs b/WebCms/App_Start/AutoMapperConfig.cs index 42c4cb8..369e302 100644 --- a/WebCms/App_Start/AutoMapperConfig.cs +++ b/WebCms/App_Start/AutoMapperConfig.cs @@ -21,7 +21,7 @@ namespace LeafWeb.WebCms.App_Start Mapper.CreateMap().ConvertUsing(file => file?.FileContents.Contents.GetString()); Mapper.CreateMap().ConvertUsing(st => st.ToString()); Mapper.CreateMap().ConvertUsing(st => new LeafInputStatus()); - Mapper.CreateMap() + Mapper.CreateMap() .ForMember(dest => dest.LeafInputId, opt => opt.MapFrom(src => src.Id)) .ForMember(dest => dest.HasLeafChart, opt => opt.ResolveUsing(src => src.OutputFiles.Any(o => o.IsLeafChartFile))); diff --git a/WebCms/Controllers/LeafWebPageIds.cs b/WebCms/Controllers/LeafWebPageIds.cs index a9032fa..ed35226 100644 --- a/WebCms/Controllers/LeafWebPageIds.cs +++ b/WebCms/Controllers/LeafWebPageIds.cs @@ -5,7 +5,9 @@ namespace LeafWeb.WebCms.Controllers { public const int ManageQueue = 1107; public const int Chart = 1100; - public const int Details = 1111; + // ReSharper disable once InconsistentNaming + public const int Details_Admin = 1111; + public const int Details_Results = 0; public const int PasswordResetRequest = 1164; } diff --git a/WebCms/Controllers/QueueController.cs b/WebCms/Controllers/QueueController.cs index 36a78ea..7fe5d95 100644 --- a/WebCms/Controllers/QueueController.cs +++ b/WebCms/Controllers/QueueController.cs @@ -103,7 +103,7 @@ namespace LeafWeb.WebCms.Controllers RedirectToUmbracoPage(LeafWebPageIds.ManageQueue); } - var viewModel = new LeafInputDetails(leafInput); + var viewModel = new LeafInputDetails_Admin(leafInput); return View(viewModel); } diff --git a/WebCms/Controllers/ResultsController.cs b/WebCms/Controllers/ResultsController.cs index f051886..8af7ada 100644 --- a/WebCms/Controllers/ResultsController.cs +++ b/WebCms/Controllers/ResultsController.cs @@ -11,7 +11,7 @@ namespace LeafWeb.WebCms.Controllers { public class ResultsController : BaseController { - //[MemberAuthorize(AllowGroup = "Authenticated")] + [MemberAuthorize(AllowGroup = "Authenticated")] public ActionResult Index(LeafDataQuery query) { var resultItems = @@ -29,7 +29,7 @@ namespace LeafWeb.WebCms.Controllers } - //[MemberAuthorize(AllowGroup = "Authenticated")] + [MemberAuthorize(AllowGroup = "Authenticated")] [HttpPost] public ActionResult Search(LeafDataQuery query) { @@ -41,6 +41,21 @@ namespace LeafWeb.WebCms.Controllers return RedirectToCurrentUmbracoPage(query.GetNameValueCollection()); } + public ActionResult Details(int id) + { + var leafInput = DataService.GetLeafInput(id); + + if (leafInput == null) + { + SetStatusMessage($"LeafInput '${id}' not found, may have been deleted?"); + RedirectToUmbracoPage(LeafWebPageIds.ManageQueue); + } + + var viewModel = new LeafInputDetails_Admin(leafInput); + return View(viewModel); + } + + public ActionResult Recent() { var dateThreshold = DateTime.Today.Subtract(TimeSpan.FromDays(90)); diff --git a/WebCms/Models/LeafInputDetails.cs b/WebCms/Models/LeafInputDetails.cs index 8b6dc16..a616984 100644 --- a/WebCms/Models/LeafInputDetails.cs +++ b/WebCms/Models/LeafInputDetails.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; using System.Web.Mvc; using AutoMapper; using LeafWeb.Core.Entities; -using LeafWeb.Core.Utility; namespace LeafWeb.WebCms.Models { @@ -14,24 +12,24 @@ namespace LeafWeb.WebCms.Models [HiddenInput(DisplayValue = false)] public int LeafInputId { get; set; } - [Display(Name = "Identifier")] + [Display(Name = "Identifier", Order = 0)] [Required(ErrorMessage = "A unique identifier is required")] public string Identifier { get; set; } - [Display(Name = "Site Id")] + [Display(Name = "Site Id", Order = 0)] [Required(ErrorMessage = "The site's name is required")] public string SiteId { get; set; } - [Display(Name = "Photosyn. Pathway")] + [Display(Name = "Photosyn. Pathway", Order = 0)] [Required(ErrorMessage = "A Photosynthetic pathway must be chosen")] public string PhotosynthesisType { get; set; } - [Display(Name = "Name")] + [Display(Name = "Name", Order = 0)] [Required(ErrorMessage = "Name required")] [RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Please provide full name")] public string Name { get; set; } - [Display(Name = "Email address")] + [Display(Name = "Email address", Order = 0)] [Required(ErrorMessage = "An email address is required")] [DataType(DataType.EmailAddress)] [RegularExpression(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}", ErrorMessage = "Must be an email address")] @@ -39,19 +37,17 @@ namespace LeafWeb.WebCms.Models [DataType(DataType.Date)] [Required] + [Display(Order = 0)] public DateTime Added { get; set; } - [Display(Name = "Piscal Error")] + [Display(Name = "Piscal Error", Order = 0)] [UIHint("PreReadMore")] public string OutputErrorMessage { get; set; } - [Display(Name = "Piscal Warning")] + [Display(Name = "Piscal Warning", Order = 0)] [UIHint("PreReadMore")] public string OutputWarningMessage { get; set; } - [Display(Name = "Time In Progress")] - public TimeSpan TimeInProgress { get; set; } - [HiddenInput(DisplayValue = false)] public bool HasLeafChart { get; set; } @@ -71,12 +67,12 @@ namespace LeafWeb.WebCms.Models public bool IsCancellable { get; set; } [UIHint("LeafInputDataViewModels")] + [Display(Order = 0)] public List LeafInputData { get; set; } - [UIHint("LeafInputStatusViewModels")] - public List StatusHistory { get; set; } + public LeafInputDetails(){} - public LeafInputDetails(LeafInput leafInput) + public LeafInputDetails(LeafInput leafInput) { Mapper.Map(leafInput, this); } diff --git a/WebCms/Models/LeafInputDetails_Admin.cs b/WebCms/Models/LeafInputDetails_Admin.cs new file mode 100644 index 0000000..a924032 --- /dev/null +++ b/WebCms/Models/LeafInputDetails_Admin.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using AutoMapper; +using LeafWeb.Core.Entities; + +namespace LeafWeb.WebCms.Models +{ + public class LeafInputDetails_Admin : LeafInputDetails + { + [Display(Name = "Time In Progress", Order = 2)] + public TimeSpan TimeInProgress { get; set; } + + [UIHint("LeafInputStatusViewModels")] + [Display(Order = 2)] + public List StatusHistory { get; set; } + + public LeafInputDetails_Admin(LeafInput leafInput) + { + Mapper.Map(leafInput, this); + } + } +} \ No newline at end of file diff --git a/WebCms/Views/Queue/Details.cshtml b/WebCms/Views/Queue/Details.cshtml index 61c4778..828bf02 100644 --- a/WebCms/Views/Queue/Details.cshtml +++ b/WebCms/Views/Queue/Details.cshtml @@ -1,6 +1,6 @@ @using LeafWeb.WebCms.Controllers @using LeafWeb.WebCms.Utility -@model LeafInputDetails +@model LeafInputDetails_Admin
@@ -78,7 +78,7 @@ @Html.Partial("DisplayTemplates/_ChartLink", (int)item.LeafInputId, cssClass) } -@helper DeleteLink(LeafInputDetails item) +@helper DeleteLink(LeafInputDetails_Admin item) { var cssClass = CssClassUtil.CreateCssClassDataDictionary("btn", "btn-outline-secondary"); @@ -90,7 +90,7 @@ @Html.Partial("DisplayTemplates/_DeleteForm", Tuple.Create(item.LeafInputId, item.Identifier), cssClass) } -@helper CancelLink(LeafInputDetails item) +@helper CancelLink(LeafInputDetails_Admin item) { var cssClass = CssClassUtil.CreateCssClassDataDictionary("btn", "btn-outline-secondary"); diff --git a/WebCms/Views/Results/Details.cshtml b/WebCms/Views/Results/Details.cshtml new file mode 100644 index 0000000..e7b1b46 --- /dev/null +++ b/WebCms/Views/Results/Details.cshtml @@ -0,0 +1,61 @@ +@using LeafWeb.WebCms.Utility +@model LeafInputDetails_Admin + +
+ + @ChartLink(Model) + + + + @if (Model.IsCancellable) + { +
+ @CancelLink(Model) +
+ } + +
+
+
+ @Html.DisplayForModel() +
+
+ +@helper ChartLink(dynamic item) +{ + var cssClass + = CssClassUtil.CreateCssClassDataDictionary("btn", "btn-outline-secondary"); + + if (!item.HasLeafChart) + { + cssClass.SetCssDisabled(); + } + @Html.Partial("DisplayTemplates/_ChartLink", (int)item.LeafInputId, cssClass) +} + + +@helper CancelLink(LeafInputDetails_Admin item) +{ + var cssClass + = CssClassUtil.CreateCssClassDataDictionary("btn", "btn-outline-secondary"); + if (!item.IsCancellable) + { + cssClass.SetCssDisabled(); + } + @Html.Partial("DisplayTemplates/_CancelForm", Tuple.Create(item.LeafInputId, item.Identifier), cssClass) +} \ No newline at end of file diff --git a/WebCms/Views/Shared/DisplayTemplates/_DetailsLink.cshtml b/WebCms/Views/Shared/DisplayTemplates/_Details_AdminLink.cshtml similarity index 91% rename from WebCms/Views/Shared/DisplayTemplates/_DetailsLink.cshtml rename to WebCms/Views/Shared/DisplayTemplates/_Details_AdminLink.cshtml index 171deda..fcc028f 100644 --- a/WebCms/Views/Shared/DisplayTemplates/_DetailsLink.cshtml +++ b/WebCms/Views/Shared/DisplayTemplates/_Details_AdminLink.cshtml @@ -1,7 +1,7 @@ @using LeafWeb.WebCms.Controllers @model int @{ - var url = UmbracoContext.Current.UrlProvider.GetUrl(LeafWebPageIds.Details); + var url = UmbracoContext.Current.UrlProvider.GetUrl(LeafWebPageIds.Details_Admin); } diff --git a/WebCms/Views/Shared/DisplayTemplates/_Details_ResultsLink.cshtml b/WebCms/Views/Shared/DisplayTemplates/_Details_ResultsLink.cshtml new file mode 100644 index 0000000..4e54f8d --- /dev/null +++ b/WebCms/Views/Shared/DisplayTemplates/_Details_ResultsLink.cshtml @@ -0,0 +1,9 @@ +@using LeafWeb.WebCms.Controllers +@model int +@{ + var url = UmbracoContext.Current.UrlProvider.GetUrl(LeafWebPageIds.Details_Results); +} + + + Details + diff --git a/WebCms/Views/Shared/_LeafDataQuery.cshtml b/WebCms/Views/Shared/_LeafDataQuery.cshtml index 418af03..584b2c2 100644 --- a/WebCms/Views/Shared/_LeafDataQuery.cshtml +++ b/WebCms/Views/Shared/_LeafDataQuery.cshtml @@ -6,9 +6,9 @@ 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/"; + var actionName = string.Empty; + var controllerName = string.Empty; + var htmlFormAction = string.Empty; if (ViewData.ContainsKey("actionName")) { diff --git a/WebCms/Views/Shared/_LeafInputActions.cshtml b/WebCms/Views/Shared/_LeafInputActions.cshtml index 1276aaa..023c234 100644 --- a/WebCms/Views/Shared/_LeafInputActions.cshtml +++ b/WebCms/Views/Shared/_LeafInputActions.cshtml @@ -12,7 +12,14 @@ Actions
-@helper DetailsLink(dynamic item) +@helper Details_AdminLink(dynamic item) { var cssClass = CssClassUtil.CreateCssClassDataDictionary("dropdown-item"); - @Html.Partial("DisplayTemplates/_DetailsLink", (int)item.Id, cssClass) + @Html.Partial("DisplayTemplates/_Details_AdminLink", (int)item.Id, cssClass) +} + +@helper Details_ResultsLink(dynamic item) +{ + var cssClass = CssClassUtil.CreateCssClassDataDictionary("dropdown-item"); + + @Html.Partial("DisplayTemplates/_Details_ResultsLink", (int)item.Id, cssClass) } @helper ChartLink(dynamic item) diff --git a/WebCms/WebCms.csproj b/WebCms/WebCms.csproj index b1e6530..6f4d4f3 100644 --- a/WebCms/WebCms.csproj +++ b/WebCms/WebCms.csproj @@ -1024,7 +1024,7 @@ - + @@ -1072,6 +1072,8 @@ + + Web.config @@ -1115,10 +1117,11 @@ + - +