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
+15 -1
View File
@@ -60,7 +60,21 @@ namespace MileageTraker.Web.Controllers
var vm = new FuelLogViewModel(fuelLog) { VehicleId = DataService.GetVehicleIdByTag(fuelLog.TagNumber) }; var vm = new FuelLogViewModel(fuelLog) { VehicleId = DataService.GetVehicleIdByTag(fuelLog.TagNumber) };
return View(vm); 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) public ViewResult Match(int id)
{ {
var fuelLog = DataService.GetFuelLog(id); var fuelLog = DataService.GetFuelLog(id);
+34 -14
View File
@@ -21,11 +21,13 @@ $(function () {
$("form select#Year").change(function () { $("form select#Year").change(function () {
var year = $(this).val(); var year = $(this).val();
var months = availableLogYearMonths[year]; var months = availableLogYearMonths[year];
var options = '<option>Select Month</option>'; var options = '<option>Select Month</option>';
for (var i = 0; i < months.length; i++) { if (months != undefined) {
options += '<option>' + months[i] + '</option>'; for (var i = 0; i < months.length; i++) {
} options += '<option>' + months[i] + '</option>';
$("form select#Month").html(options); }
}
$("form select#Month").html(options);
}); });
$("input#ModelYear,input#Price,input#VehicleId,input#EndOdometer,input#GasPurchased").numeric(); $("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 // add recent logs to a div if it exists
$(function () { $(function () {
var $recentLogs = $("#RecentLogs"); var $recentLogs = $("#RecentLogs");
if ($recentLogs.length > 0) { if ($recentLogs.length > 0) {
$.ajax({ $.ajax({
url: "/CreateLog/RecentLogs", url: "/FuelLog/RecentLogs",
success: function (data) { success: function (data) {
$recentLogs.append(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() { $(function() {
+5 -1
View File
@@ -47,7 +47,11 @@
grid.Column("Log", "Matched Log", @<text> grid.Column("Log", "Matched Log", @<text>
@(item.LogId != null @(item.LogId != null
? Html.ActionLink("View Match", "Match", new {id = item.FuelLogId}, new {@class = "btn btn-mini", target="_blank"}) ? 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>)), </text>)),
htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"}, htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"},
numericLinksCount: 20 numericLinksCount: 20
+5 -1
View File
@@ -8,5 +8,9 @@
} }
else 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})
})
} }