From 2b5de1c4cd9bf30cab72925f9ea92322a2b6a05f Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Sun, 28 Jun 2020 17:37:06 -0400 Subject: [PATCH] Replace WebGridBootstrapPager Improve Leaf details page --- References/WebGridBootstrapPager.dll | Bin 6656 -> 0 bytes WebCms/Models/LeafDataQuery.cs | 11 ++ WebCms/Models/LeafInputDataSiteViewModel.cs | 10 +- WebCms/Utility/CssClassUtil.cs | 4 +- WebCms/Utility/WebGridExtensions.cs | 137 ++++++------------ WebCms/Views/Queue/Details.cshtml | 6 +- WebCms/Views/Queue/Index.cshtml | 10 +- WebCms/Views/Results/Index.cshtml | 4 +- .../LeafInputDataSiteViewModels.cshtml | 20 ++- .../DisplayTemplates/_CancelForm.cshtml | 2 +- .../DisplayTemplates/_DeleteForm.cshtml | 2 +- WebCms/Views/Web.config | 1 - WebCms/WebCms.csproj | 5 +- 13 files changed, 93 insertions(+), 119 deletions(-) delete mode 100644 References/WebGridBootstrapPager.dll diff --git a/References/WebGridBootstrapPager.dll b/References/WebGridBootstrapPager.dll deleted file mode 100644 index 5eda6a64f1661667a05b4a55d13f1465c26162df..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6656 zcmeHLYit}>6+W}O-d(>oUOUdyhH>mvDZv{%c1+#6t)EF;*^aZjv4I*Tv%A;pNoIGJ znOVmUB6U?NRJEX%N2RE!ptcffMWjRo5h@{Cgb)Y?s6^?%Hb_N;UxmL25x#S0U*2^i zg@35Iv-8b8k9+R9=bpLu&dz@EdGZpG5BKfcMAz};GAi-TumN%C({G08TK$c#>&ncH zuK0>>t2xU|TUtg#Ga-LUkd(*@os#o!`K~mA1NY-45#sD7+G`+vx}FvM#yQ?f|Gg z)^A;EZ_wP1X4W4-TJHf&xYS_%jmeKnq@sXq1h~>!CKpTOOH5t`9N2-ju-;(>JhJBl zJHfEwP{U`&V~>q1g~;+etqw-|A_IK`{lg$Q_P`V()qRoZk9clJK6b|(OV6fl*7z`h zR6!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1~o`H`R=AR?L*TY+7ofxXG$HEv;we5~148x*>34<+$NAMy;jQRsH4b zs(QGu{|M3j3iS*P4-fYx#pikxM+OqTgJMwY)lx&rUafym$r=4$8gQW*(EHMLbJuz8j)No!9n>y zDAx+#qU`GLxvp}pwiLfvUCHSQ)0#AlSxwKnMo^HJ2e@N&rSP-U3}p};Ed9!If8^FBL`9da4_B$po9Dh{azt_^v47nKTh z#kU>4D)7mH7Vop^EiC;59V-}h@fxHA$ADggu7WQU6Z>%nee-_KAL#S2Wn#zBvEB=C zR9eI{LC0htDSZ8mLvBiK?pMP;KMzbp%YruBa@|CP#WVeMb-x0~hC7D{Ri7@3geWvyj86%X>b_nc2)!@rA77It>5%2@5>-e)jD| zp`CluGD`7cPkA=}Hy>wY?A>fg;S|6piSnrL#wO9AjQM6;)se4``vbDg81li!7&6Ep h0};YM8C5e@-44UOS3YSGP~HEGZ}Q>vUirjD;J + !( + string.IsNullOrEmpty(siteid) + && string.IsNullOrEmpty(species) + && string.IsNullOrEmpty(lat) + && string.IsNullOrEmpty(latr) + && string.IsNullOrEmpty(lon) + && string.IsNullOrEmpty(lonr) + ); } } \ No newline at end of file diff --git a/WebCms/Models/LeafInputDataSiteViewModel.cs b/WebCms/Models/LeafInputDataSiteViewModel.cs index 507da2b..a47d21f 100644 --- a/WebCms/Models/LeafInputDataSiteViewModel.cs +++ b/WebCms/Models/LeafInputDataSiteViewModel.cs @@ -1,7 +1,6 @@ using System.ComponentModel.DataAnnotations; using AutoMapper; using LeafWeb.Core.Entities; -using LeafWeb.Core.Utility; namespace LeafWeb.WebCms.Models { @@ -9,15 +8,16 @@ namespace LeafWeb.WebCms.Models { /// Site identifier /// do not leave blank between letters - [ParseInfo(1)] [Display(Name = "Site Id")] public string SiteId { get; set; } /// Site latitude, northern hemisphere positive + [Display(Name = "Latitude (°)")] [DisplayFormat(DataFormatString = "{0} °")] public double? Latitude { get; set; } /// Site longitude, east positive + [Display(Name = "Longitude (°)")] [DisplayFormat(DataFormatString = "{0} °")] public double? Longitude { get; set; } @@ -25,9 +25,11 @@ namespace LeafWeb.WebCms.Models [DisplayFormat(DataFormatString = "{0} m")] public double? Elevation { get; set; } +/* /// the year when the A/Ci data is taken [DisplayFormat(DataFormatString = "{0} year")] - public int? SampleYear { get; set; } + public string SampleYear { get; set; } + /// the day of year (since 1 Jan) when the A/Ci data is taken [ParseInfo(6, units: "day")] @@ -85,7 +87,7 @@ namespace LeafWeb.WebCms.Models /// dry leaf phosphorus content of the sample [ParseInfo(19, units: "%")] public double? LfPhosphContent { get; set; } - +*/ static LeafInputDataSiteViewModel() { Mapper.CreateMap(); diff --git a/WebCms/Utility/CssClassUtil.cs b/WebCms/Utility/CssClassUtil.cs index 9d437fd..bf10e3d 100644 --- a/WebCms/Utility/CssClassUtil.cs +++ b/WebCms/Utility/CssClassUtil.cs @@ -22,12 +22,12 @@ namespace LeafWeb.WebCms.Utility } } - public static void SetButtonDisabled(this ViewDataDictionary vdd) + public static void SetCssDisabled(this ViewDataDictionary vdd) { vdd.AddCssClass("disabled"); } - public static bool IsButtonDisabled(this ViewDataDictionary vdd) + public static bool IsCssDisabled(this ViewDataDictionary vdd) { return vdd.ContainsKey(KeyName) && ((string[]) vdd[KeyName]).Contains("disabled"); } diff --git a/WebCms/Utility/WebGridExtensions.cs b/WebCms/Utility/WebGridExtensions.cs index 4312429..f011f0f 100644 --- a/WebCms/Utility/WebGridExtensions.cs +++ b/WebCms/Utility/WebGridExtensions.cs @@ -12,16 +12,22 @@ namespace LeafWeb.WebCms.Utility public static HelperResult PagerList( this WebGrid webGrid, WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric, - string firstText = null, - string previousText = null, - string nextText = null, - string lastText = null, + string firstText = "First", + string previousText = "Prev", + string nextText = "Next", + string lastText = "Last", int numericLinksCount = 5, string paginationStyle = null) { - return PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, paginationStyle, explicitlyCalled: true); + return PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, + paginationStyle, true); } + /* bootstrap pagination classes */ + private const string ulClass = "pagination"; + private const string liClass = "page-item"; + private const string aClass = "page-link"; + private static HelperResult PagerList( WebGrid webGrid, WebGridPagerModes mode, @@ -33,150 +39,110 @@ namespace LeafWeb.WebCms.Utility string paginationStyle, bool explicitlyCalled) { - - int currentPage = webGrid.PageIndex; - int totalPages = webGrid.PageCount; - int lastPage = totalPages - 1; + var currentPage = webGrid.PageIndex; + var totalPages = webGrid.PageCount; + var lastPage = totalPages - 1; var ul = new TagBuilder("ul"); + ul.AddCssClass(ulClass); ul.AddCssClass(paginationStyle); var li = new List(); - if(webGrid.TotalRowCount <= webGrid.PageCount) - { - return new HelperResult(writer => - { - writer.Write(string.Empty); - }); - } + if (webGrid.TotalRowCount <= webGrid.PageCount) + return new HelperResult(writer => writer.Write(string.Empty)); - if(ModeEnabled(mode, WebGridPagerModes.FirstLast)) + if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && totalPages > 1) { - if(String.IsNullOrEmpty(firstText)) - { - firstText = "First"; - } - var part = new TagBuilder("li") { InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(0), firstText) }; + part.AddCssClass(liClass); - if(currentPage == 0) - { - part.MergeAttribute("class", "disabled"); - } + if (currentPage == 0) part.AddCssClass("disabled"); li.Add(part); - } - if(ModeEnabled(mode, WebGridPagerModes.NextPrevious)) + if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && totalPages > 1) { - if(String.IsNullOrEmpty(previousText)) - { - previousText = "Prev"; - } - - int page = currentPage == 0 ? 0 : currentPage - 1; + var page = currentPage == 0 ? 0 : currentPage - 1; var part = new TagBuilder("li") { InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), previousText) }; + part.AddCssClass(liClass); - if(currentPage == 0) - { - part.MergeAttribute("class", "disabled"); - } + if (currentPage == 0) part.AddCssClass("disabled"); li.Add(part); - } - - if(ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1)) + if (ModeEnabled(mode, WebGridPagerModes.Numeric) && totalPages > 1) { - int last = currentPage + (numericLinksCount / 2); - int first = last - numericLinksCount + 1; - if(last > lastPage) + var last = currentPage + numericLinksCount / 2; + var first = last - numericLinksCount + 1; + if (last > lastPage) { first -= last - lastPage; last = lastPage; } - if(first < 0) + + if (first < 0) { last = Math.Min(last + (0 - first), lastPage); first = 0; } - for(int i = first; i <= last; i++) - { + for (var i = first; i <= last; i++) + { var pageText = (i + 1).ToString(CultureInfo.InvariantCulture); var part = new TagBuilder("li") { InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(i), pageText) }; + part.AddCssClass(liClass); - if(i == currentPage) - { - part.MergeAttribute("class", "active"); - } + if (i == currentPage) part.AddCssClass("active"); li.Add(part); - } } - if(ModeEnabled(mode, WebGridPagerModes.NextPrevious)) + if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && totalPages > 1) { - if(String.IsNullOrEmpty(nextText)) - { - nextText = "Next"; - } - - int page = currentPage == lastPage ? lastPage : currentPage + 1; + var page = currentPage == lastPage ? lastPage : currentPage + 1; var part = new TagBuilder("li") { InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), nextText) }; + part.AddCssClass(liClass); - if(currentPage == lastPage) - { - part.MergeAttribute("class", "disabled"); - } + if (currentPage == lastPage) part.AddCssClass("disabled"); li.Add(part); - } - if(ModeEnabled(mode, WebGridPagerModes.FirstLast)) + if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && totalPages > 1) { - if(String.IsNullOrEmpty(lastText)) - { - lastText = "Last"; - } - var part = new TagBuilder("li") { InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(lastPage), lastText) }; - if(currentPage == lastPage) - { - part.MergeAttribute("class", "disabled"); - } + if (currentPage == lastPage) + part.AddCssClass("disabled"); li.Add(part); - } ul.InnerHtml = string.Join("", li); var html = ""; - if(explicitlyCalled && webGrid.IsAjaxEnabled) + if (explicitlyCalled && webGrid.IsAjaxEnabled) { var span = new TagBuilder("span"); span.MergeAttribute("data-swhgajax", "true"); @@ -185,36 +151,29 @@ namespace LeafWeb.WebCms.Utility span.InnerHtml = ul.ToString(); html = span.ToString(); - } else { html = ul.ToString(); } - return new HelperResult(writer => - { - writer.Write(html); - }); + return new HelperResult(writer => writer.Write(html)); } - private static String GridLink(WebGrid webGrid, string url, string text) + private static string GridLink(WebGrid webGrid, string url, string text) { - TagBuilder builder = new TagBuilder("a"); + var builder = new TagBuilder("a"); builder.SetInnerText(text); builder.MergeAttribute("href", url); - if(webGrid.IsAjaxEnabled) - { + builder.AddCssClass(aClass); + if (webGrid.IsAjaxEnabled) builder.MergeAttribute("data-swhglnk", "true"); - } return builder.ToString(TagRenderMode.Normal); } - private static bool ModeEnabled(WebGridPagerModes mode, WebGridPagerModes modeCheck) { return (mode & modeCheck) == modeCheck; } - } -} +} \ No newline at end of file diff --git a/WebCms/Views/Queue/Details.cshtml b/WebCms/Views/Queue/Details.cshtml index d6bafde..61c4778 100644 --- a/WebCms/Views/Queue/Details.cshtml +++ b/WebCms/Views/Queue/Details.cshtml @@ -73,7 +73,7 @@ if (!item.HasLeafChart) { - cssClass.SetButtonDisabled(); + cssClass.SetCssDisabled(); } @Html.Partial("DisplayTemplates/_ChartLink", (int)item.LeafInputId, cssClass) } @@ -84,7 +84,7 @@ = CssClassUtil.CreateCssClassDataDictionary("btn", "btn-outline-secondary"); if (!item.IsDeletable) { - cssClass.SetButtonDisabled(); + cssClass.SetCssDisabled(); } @Html.Partial("DisplayTemplates/_DeleteForm", Tuple.Create(item.LeafInputId, item.Identifier), cssClass) @@ -96,7 +96,7 @@ = CssClassUtil.CreateCssClassDataDictionary("btn", "btn-outline-secondary"); if (!item.IsCancellable) { - cssClass.SetButtonDisabled(); + cssClass.SetCssDisabled(); } @Html.Partial("DisplayTemplates/_CancelForm", Tuple.Create(item.LeafInputId, item.Identifier), cssClass) } \ No newline at end of file diff --git a/WebCms/Views/Queue/Index.cshtml b/WebCms/Views/Queue/Index.cshtml index e0a1cdc..0f5f158 100644 --- a/WebCms/Views/Queue/Index.cshtml +++ b/WebCms/Views/Queue/Index.cshtml @@ -37,7 +37,7 @@ -
+
@@ -89,7 +89,7 @@ grid.Column("", format: item => Actions(item.Value), canSort: false)), htmlAttributes: new { @class = "table table-sm table-striped table-bordered table-hover" } ) - @grid.BootstrapPager() + @grid.PagerList()
} else @@ -150,7 +150,7 @@ else if (!item.HasLeafChart) { - cssClass.SetButtonDisabled(); + cssClass.SetCssDisabled(); } @Html.Partial("DisplayTemplates/_ChartLink", (int)item.Id, cssClass) } @@ -212,7 +212,7 @@ else = CssClassUtil.CreateCssClassDataDictionary("dropdown-item"); if (!item.IsDeletable) { - cssClass.SetButtonDisabled(); + cssClass.SetCssDisabled(); } @Html.Partial("DisplayTemplates/_DeleteForm", Tuple.Create(item.Id, item.Identifier), cssClass) } @@ -223,7 +223,7 @@ else = CssClassUtil.CreateCssClassDataDictionary("dropdown-item"); if (!item.IsCancellable) { - cssClass.SetButtonDisabled(); + cssClass.SetCssDisabled(); } @Html.Partial("DisplayTemplates/_CancelForm", Tuple.Create(item.Id, item.Identifier), cssClass) } diff --git a/WebCms/Views/Results/Index.cshtml b/WebCms/Views/Results/Index.cshtml index 5d04d93..2d86737 100644 --- a/WebCms/Views/Results/Index.cshtml +++ b/WebCms/Views/Results/Index.cshtml @@ -16,15 +16,15 @@ ), htmlAttributes: new { @class = "table table-sm table-striped table-bordered table-hover" } ) + @grid.PagerList()
-@grid.BootstrapPager() @helper ChartLink(LeafInput leafInput) { var cssClass = CssClassUtil.CreateCssClassDataDictionary("btn", " btn-outline-secondary", "btn-sm"); if (!leafInput.HasLeafChart) { - cssClass.SetButtonDisabled(); + cssClass.SetCssDisabled(); } @Html.Partial("DisplayTemplates/_ChartButton", leafInput.Id, cssClass) } diff --git a/WebCms/Views/Shared/DisplayTemplates/LeafInputDataSiteViewModels.cshtml b/WebCms/Views/Shared/DisplayTemplates/LeafInputDataSiteViewModels.cshtml index 3a854d6..7426d82 100644 --- a/WebCms/Views/Shared/DisplayTemplates/LeafInputDataSiteViewModels.cshtml +++ b/WebCms/Views/Shared/DisplayTemplates/LeafInputDataSiteViewModels.cshtml @@ -1,17 +1,23 @@ -@model IEnumerable +@using System.Collections.ObjectModel +@model IEnumerable @{ //Layout = "~/Views/Shared/DisplayTemplates/_FieldLayout.cshtml"; - Rend("Site Id", string.Join(", ", Model.Select(m => m.SiteId).Distinct())); - Rend("Latitude", string.Join(", ", Model.Select(m => m.Latitude).Distinct())); } -@helper Rend(string label, string value) +@Rend("Site Id", Model.Select(m => m.SiteId)) +@Rend("Latitude [°]", Model.Select(m => m.Latitude?.ToString())) +@Rend("Longitude [°]", Model.Select(m => m.Longitude?.ToString())) +@Rend("Elevation [m]", Model.Select(m => m.Elevation?.ToString())) + + +@helper Rend(string label, IEnumerable values) { + var value = string.Join(", ", values.Distinct());
-
- @label +
+ @Html.Raw(label)
-
+
@value
diff --git a/WebCms/Views/Shared/DisplayTemplates/_CancelForm.cshtml b/WebCms/Views/Shared/DisplayTemplates/_CancelForm.cshtml index c5649ae..a40a6bc 100644 --- a/WebCms/Views/Shared/DisplayTemplates/_CancelForm.cshtml +++ b/WebCms/Views/Shared/DisplayTemplates/_CancelForm.cshtml @@ -9,7 +9,7 @@ new { @class = "confirm clearfix", confirm_msg = "Cancelling cannot be undone! Confirm cancelling '" + identifier + "'." })) { - } \ No newline at end of file diff --git a/WebCms/Views/Shared/DisplayTemplates/_DeleteForm.cshtml b/WebCms/Views/Shared/DisplayTemplates/_DeleteForm.cshtml index fefb424..d6d1a72 100644 --- a/WebCms/Views/Shared/DisplayTemplates/_DeleteForm.cshtml +++ b/WebCms/Views/Shared/DisplayTemplates/_DeleteForm.cshtml @@ -9,7 +9,7 @@ new { @class = "confirm clearfix", confirm_msg = "Deletion cannot be undone! Confirm deleting '" + identifier + "'." })) { - } \ No newline at end of file diff --git a/WebCms/Views/Web.config b/WebCms/Views/Web.config index 9ba3fb8..1facf2c 100644 --- a/WebCms/Views/Web.config +++ b/WebCms/Views/Web.config @@ -16,7 +16,6 @@ - diff --git a/WebCms/WebCms.csproj b/WebCms/WebCms.csproj index 833f527..ff3dc07 100644 --- a/WebCms/WebCms.csproj +++ b/WebCms/WebCms.csproj @@ -323,10 +323,6 @@ ..\packages\WebGrease.1.6.0\lib\WebGrease.dll True - - False - ..\References\WebGridBootstrapPager.dll - @@ -1134,6 +1130,7 @@ +