Replace WebGridBootstrapPager
Improve Leaf details page
This commit is contained in:
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace LeafWeb.WebCms.Models
|
||||
{
|
||||
@@ -67,5 +68,15 @@ namespace LeafWeb.WebCms.Models
|
||||
|
||||
return nvs;
|
||||
}
|
||||
|
||||
public bool HasExtendedParameters =>
|
||||
!(
|
||||
string.IsNullOrEmpty(siteid)
|
||||
&& string.IsNullOrEmpty(species)
|
||||
&& string.IsNullOrEmpty(lat)
|
||||
&& string.IsNullOrEmpty(latr)
|
||||
&& string.IsNullOrEmpty(lon)
|
||||
&& string.IsNullOrEmpty(lonr)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>Site identifier</summary>
|
||||
/// <remarks>do not leave blank between letters</remarks>
|
||||
[ParseInfo(1)]
|
||||
[Display(Name = "Site Id")]
|
||||
public string SiteId { get; set; }
|
||||
|
||||
/// <summary>Site latitude, northern hemisphere positive</summary>
|
||||
[Display(Name = "Latitude (°)")]
|
||||
[DisplayFormat(DataFormatString = "{0} °")]
|
||||
public double? Latitude { get; set; }
|
||||
|
||||
/// <summary>Site longitude, east positive</summary>
|
||||
[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; }
|
||||
|
||||
/*
|
||||
/// <summary>the year when the A/Ci data is taken</summary>
|
||||
[DisplayFormat(DataFormatString = "{0} year")]
|
||||
public int? SampleYear { get; set; }
|
||||
public string SampleYear { get; set; }
|
||||
|
||||
|
||||
/// <summary>the day of year (since 1 Jan) when the A/Ci data is taken</summary>
|
||||
[ParseInfo(6, units: "day")]
|
||||
@@ -85,7 +87,7 @@ namespace LeafWeb.WebCms.Models
|
||||
/// <summary>dry leaf phosphorus content of the sample</summary>
|
||||
[ParseInfo(19, units: "%")]
|
||||
public double? LfPhosphContent { get; set; }
|
||||
|
||||
*/
|
||||
static LeafInputDataSiteViewModel()
|
||||
{
|
||||
Mapper.CreateMap<LeafInputDataSite, LeafInputDataSiteViewModel>();
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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<TagBuilder>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -37,7 +37,7 @@
|
||||
</div><!-- /input-group -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="row collapse ml-1 mr-1" id="additionalSearch">
|
||||
<div class="row @if(Model.Q.HasExtendedParameters) {<text>show</text>} collapse ml-1 mr-1" id="additionalSearch">
|
||||
|
||||
<div class="col-lg-8 offset-lg-4 card card-body">
|
||||
<div class="row">
|
||||
@@ -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()
|
||||
</div>
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
),
|
||||
htmlAttributes: new { @class = "table table-sm table-striped table-bordered table-hover" }
|
||||
)
|
||||
@grid.PagerList()
|
||||
</div>
|
||||
@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)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
@model IEnumerable<LeafInputDataSiteViewModel>
|
||||
@using System.Collections.ObjectModel
|
||||
@model IEnumerable<LeafInputDataSiteViewModel>
|
||||
@{
|
||||
//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<string> values)
|
||||
{
|
||||
var value = string.Join(", ", values.Distinct());
|
||||
<div class="row pb-lg-2 pb-sm-1 @if (ViewData.Model == null){<text>d-none</text> }">
|
||||
<div class="col-sm-3 text-truncate">
|
||||
@label
|
||||
<div class="col-sm-3 text-truncate border-right border-bottom pl-4 pl-sm-5">
|
||||
@Html.Raw(label)
|
||||
</div>
|
||||
<div class="col-sm-9">
|
||||
<div class="col-sm-9 border-bottom pl-5 pl-sm-2">
|
||||
@value
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
new { @class = "confirm clearfix", confirm_msg = "Cancelling cannot be undone! Confirm cancelling '" + identifier + "'." }))
|
||||
{
|
||||
<input type="hidden" name="id" value="@leafInputId"/>
|
||||
<button type="submit" @Html.Partial("DisplayTemplates/_ViewDataCssClass") @if(ViewData.IsButtonDisabled()) {<text>disabled</text>}>
|
||||
<button type="submit" @Html.Partial("DisplayTemplates/_ViewDataCssClass") @if(ViewData.IsCssDisabled()) {<text>disabled</text>}>
|
||||
<span class="fa fa-ban"></span> Cancel
|
||||
</button>
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
new { @class = "confirm clearfix", confirm_msg = "Deletion cannot be undone! Confirm deleting '" + identifier + "'." }))
|
||||
{
|
||||
<input type="hidden" name="id" value="@leafInputId"/>
|
||||
<button type="submit" @Html.Partial("DisplayTemplates/_ViewDataCssClass") @if(ViewData.IsButtonDisabled()) {<text>disabled</text>}>
|
||||
<button type="submit" @Html.Partial("DisplayTemplates/_ViewDataCssClass") @if(ViewData.IsCssDisabled()) {<text>disabled</text>}>
|
||||
<span class="fa fa-remove"></span> Delete
|
||||
</button>
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
<namespaces>
|
||||
<add namespace="System.Web.WebPages" />
|
||||
<add namespace="System.Web.Optimization" />
|
||||
<add namespace="WebGridBootstrapPager" />
|
||||
<add namespace="LeafWeb.Core.Utility" />
|
||||
<add namespace="LeafWeb.WebCms.Models" />
|
||||
<add namespace="System.Web.Mvc" />
|
||||
|
||||
@@ -323,10 +323,6 @@
|
||||
<HintPath>..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="WebGridBootstrapPager, Version=1.0.6.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\References\WebGridBootstrapPager.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.controller.js" />
|
||||
@@ -1134,6 +1130,7 @@
|
||||
<Compile Include="Utility\RequireRequestValueAttribute.cs" />
|
||||
<Compile Include="Utility\Validation.cs" />
|
||||
<Compile Include="Utility\CssClassUtil.cs" />
|
||||
<Compile Include="Utility\WebGridExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj">
|
||||
|
||||
Reference in New Issue
Block a user