Improve charting UI for error cases
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.UI.DataVisualization.Charting;
|
using System.Web.UI.DataVisualization.Charting;
|
||||||
using System.Web.UI.WebControls;
|
using System.Web.UI.WebControls;
|
||||||
@@ -57,7 +58,7 @@ namespace LeafWeb.Web.Controllers
|
|||||||
var curveData = GetCurveData(leafOutputFile.FileContents.Contents, curveId);
|
var curveData = GetCurveData(leafOutputFile.FileContents.Contents, curveId);
|
||||||
|
|
||||||
if (curveData == null)
|
if (curveData == null)
|
||||||
return File("/Content/favicon/apple-icon-57x57.png", "image/png"); // TODO: different image ?
|
return new HttpStatusCodeResult(HttpStatusCode.NotFound);
|
||||||
|
|
||||||
var charts = GetChartBitmaps(curveData).ToList();
|
var charts = GetChartBitmaps(curveData).ToList();
|
||||||
|
|
||||||
@@ -75,11 +76,18 @@ namespace LeafWeb.Web.Controllers
|
|||||||
|
|
||||||
private CurveData GetCurveData(byte[] fileContents, string curveId)
|
private CurveData GetCurveData(byte[] fileContents, string curveId)
|
||||||
{
|
{
|
||||||
LeafGasComparison[] leafGasComparisons;
|
try
|
||||||
using (var parser = new LeafGasComparisonParser(fileContents))
|
{
|
||||||
leafGasComparisons = parser.Parse(curveId);
|
LeafGasComparison[] leafGasComparisons;
|
||||||
|
using (var parser = new LeafGasComparisonParser(fileContents))
|
||||||
return CurveDataConverter.Convert(leafGasComparisons).First();
|
leafGasComparisons = parser.Parse(curveId);
|
||||||
|
return CurveDataConverter.Convert(leafGasComparisons).First();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogManager.GetCurrentClassLogger().Warn(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] GetCurveIds(byte[] fileContents)
|
private string[] GetCurveIds(byte[] fileContents)
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
@model LeafWeb.Web.ViewModels.Chart.ChartViewModel
|
@model LeafWeb.Web.ViewModels.Chart.ChartViewModel
|
||||||
@{
|
@{
|
||||||
ViewBag.Title = "Chart";
|
ViewBag.Title = "Chart";
|
||||||
|
var selectText = "Select CurveId";
|
||||||
}
|
}
|
||||||
<h1>@ViewBag.Title</h1>
|
<h1>@ViewBag.Title</h1>
|
||||||
<h3>Identifier: <strong>@Model.LeafInputIdentifier</strong></h3>
|
<h3>Identifier: <strong>@Model.LeafInputIdentifier</strong></h3>
|
||||||
|
|
||||||
@Html.DropDownList("CurveId", new SelectList(Model.AvailableCurveId, Model.CurveId), "Select CurveId")
|
@Html.DropDownList("CurveId", new SelectList(Model.AvailableCurveId, Model.CurveId), selectText)
|
||||||
|
|
||||||
<img id="chart"/>
|
<img id="chart"/>
|
||||||
|
<span class="help-block">
|
||||||
|
<span id="chart-error"></span>
|
||||||
|
</span>
|
||||||
|
|
||||||
@section Scripts
|
@section Scripts
|
||||||
{
|
{
|
||||||
@@ -15,17 +19,27 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
$('#CurveId')
|
$('#CurveId')
|
||||||
.change(function () {
|
.change(function () {
|
||||||
|
$('#chart-error').removeClass('text-danger').text('');
|
||||||
var $chart = $("#chart");
|
var $chart = $("#chart");
|
||||||
var $spinner = $(this).after('<i class="fa fa-spinner fa-spin"></i>').next('i');
|
$chart.removeAttr('src');
|
||||||
$chart.attr('src', "");
|
|
||||||
var curveId = $("option:selected", this).text();
|
var curveId = $("option:selected", this).text();
|
||||||
|
if (curveId === "@Html.Raw(selectText)") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var $spinner = $(this).after('<i class="fa fa-spinner fa-spin"></i>').next('i');
|
||||||
var url =
|
var url =
|
||||||
"@Html.Raw(Url.Action("ChartCurve", new {leafInputId = Model.LeafInputId, curveId="curveId"}))";
|
"@Html.Raw(Url.Action("ChartCurve", new {leafInputId = Model.LeafInputId, curveId="curveId"}))";
|
||||||
url = url.replace("=curveId", "=" + curveId);
|
url = url.replace("=curveId", "=" + curveId);
|
||||||
$chart.attr('src', url)
|
$chart.load(function () {
|
||||||
.load(function() {
|
|
||||||
$spinner.remove();
|
$spinner.remove();
|
||||||
});
|
})
|
||||||
|
.error(function () {
|
||||||
|
$chart.removeAttr('src');
|
||||||
|
$spinner.remove();
|
||||||
|
$('#chart-error').addClass('text-danger').text('A problem was encountered loading this chart.');
|
||||||
|
})
|
||||||
|
.attr('src', url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user