Match count badges

This commit is contained in:
2015-10-13 20:39:51 -04:00
parent 49c55ffba6
commit 78e8924bfa
4 changed files with 59 additions and 17 deletions
+14
View File
@@ -61,6 +61,20 @@ namespace MileageTraker.Web.Controllers
return View(vm);
}
public JsonResult AvailableMatchCount(int id)
{
var fuelLog = DataService.GetFuelLog(id);
var fuelLogViewModel = new FuelLogViewModel(fuelLog) {VehicleId = DataService.GetVehicleIdByTag(fuelLog.TagNumber)};
var logs = from l in DataService.GetPossibleMatchingLogs(fuelLog).ToList()
where l != fuelLog.Log
let v = l.Vehicle
let vm = new LogMatchViewModel(l, v, fuelLogViewModel)
select vm;
return Json(logs.Count(), JsonRequestBehavior.AllowGet);
}
public ViewResult Match(int id)
{
var fuelLog = DataService.GetFuelLog(id);
+34 -14
View File
@@ -21,11 +21,13 @@ $(function () {
$("form select#Year").change(function () {
var year = $(this).val();
var months = availableLogYearMonths[year];
var options = '<option>Select Month</option>';
for (var i = 0; i < months.length; i++) {
options += '<option>' + months[i] + '</option>';
}
$("form select#Month").html(options);
var options = '<option>Select Month</option>';
if (months != undefined) {
for (var i = 0; i < months.length; i++) {
options += '<option>' + months[i] + '</option>';
}
}
$("form select#Month").html(options);
});
$("input#ModelYear,input#Price,input#VehicleId,input#EndOdometer,input#GasPurchased").numeric();
@@ -70,15 +72,33 @@ $(function () {
// add recent logs to a div if it exists
$(function () {
var $recentLogs = $("#RecentLogs");
if ($recentLogs.length > 0) {
$.ajax({
url: "/CreateLog/RecentLogs",
success: function (data) {
$recentLogs.append(data);
}
});
}
var $recentLogs = $("#RecentLogs");
if ($recentLogs.length > 0) {
$.ajax({
url: "/FuelLog/RecentLogs",
success: function (data) {
$recentLogs.append(data);
}
});
}
});
// add get match count for all the current items
$(function () {
var $requests = $("a[matchcount]").map(function() {
var $link = $(this);
return $.ajax({
url: $link.attr("matchcount"),
success: function (matchcount) {
if (matchcount > 0) {
$link.append(" <span class='badge badge-info'>" + matchcount + "</span>");
} else {
$link.append(" <span class='badge'>0</span>");
}
}
});
});
$.when.apply($, $requests);
});
$(function() {
+5 -1
View File
@@ -47,7 +47,11 @@
grid.Column("Log", "Matched Log", @<text>
@(item.LogId != null
? Html.ActionLink("View Match", "Match", new {id = item.FuelLogId}, new {@class = "btn btn-mini", target="_blank"})
: Html.ActionLink("Match", "Match", new {id = item.FuelLogId}, new {@class = "btn btn-warning btn-mini", target="_blank"}))
: Html.ActionLink("Match", "Match", new {id = item.FuelLogId},
new {@class = "btn btn-warning btn-mini",
target="_blank",
matchcount=Url.Action("AvailableMatchCount", "FuelLog", new {id = item.FuelLogId})
}))
</text>)),
htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"},
numericLinksCount: 20
+5 -1
View File
@@ -8,5 +8,9 @@
}
else
{
@Html.ActionLink("Match", "Match", new {id = Model.FuelLogId}, new {@class = "btn btn-warning btn-mini", target = "_blank"})
@Html.ActionLink("Match", "Match", new {id = Model.FuelLogId},
new {@class = "btn btn-warning btn-mini",
target="_blank",
matchcount=Url.Action("AvailableMatchCount", "FuelLog", new {id = Model.FuelLogId})
})
}