From 43d471af949636d8e5dbeaf37d4878edf6644544 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Tue, 13 Oct 2015 21:25:25 -0400 Subject: [PATCH] Match count update for import too --- Web/Scripts/Shared/FuelLogImport.js | 2 ++ Web/Scripts/Shared/Site.js | 29 +++++++++++--------- Web/ViewModels/FuelLog/MatchLinkViewModel.cs | 6 ++++ Web/Views/FuelLog/Index.cshtml | 11 ++------ 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Web/Scripts/Shared/FuelLogImport.js b/Web/Scripts/Shared/FuelLogImport.js index de81a50..e35ce0a 100644 --- a/Web/Scripts/Shared/FuelLogImport.js +++ b/Web/Scripts/Shared/FuelLogImport.js @@ -43,6 +43,8 @@ } if (result.Action != undefined && result.Action != null) { $('.match-status', $row).append(" " + result.Action); + var $action = $("a[matchcount]", $row); + matchCountFunc.apply($action); } submitNext(); diff --git a/Web/Scripts/Shared/Site.js b/Web/Scripts/Shared/Site.js index bd03977..8c975fc 100644 --- a/Web/Scripts/Shared/Site.js +++ b/Web/Scripts/Shared/Site.js @@ -83,21 +83,24 @@ $(function () { } }); +var matchCountFunc = function() { + var $link = $(this); + var url = $link.attr("matchcount"); + return $.ajax({ + url: url, + success: function(matchcount) { + if (matchcount > 0) { + $link.append(" " + matchcount + ""); + } else { + $link.append(" 0"); + } + } + }); +}; + // 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(" " + matchcount + ""); - } else { - $link.append(" 0"); - } - } - }); - }); + var $requests = $("a[matchcount]").map(matchCountFunc); $.when.apply($, $requests); }); diff --git a/Web/ViewModels/FuelLog/MatchLinkViewModel.cs b/Web/ViewModels/FuelLog/MatchLinkViewModel.cs index 294765a..eebce02 100644 --- a/Web/ViewModels/FuelLog/MatchLinkViewModel.cs +++ b/Web/ViewModels/FuelLog/MatchLinkViewModel.cs @@ -12,6 +12,12 @@ LogId = fuelLog.Log.LogId; } + public MatchLinkViewModel(int fuelLogId, int? logId) + { + FuelLogId = fuelLogId; + LogId = logId; + } + public MatchLinkViewModel(ImportFuelLogViewModel viewModel) { FuelLogId = viewModel.FuelLogId; diff --git a/Web/Views/FuelLog/Index.cshtml b/Web/Views/FuelLog/Index.cshtml index 1216590..5b10df3 100644 --- a/Web/Views/FuelLog/Index.cshtml +++ b/Web/Views/FuelLog/Index.cshtml @@ -1,4 +1,5 @@ @using MileageTraker.Web.Utility +@using MileageTraker.Web.ViewModels.FuelLog @model MileageTraker.Web.ViewModels.FuelLog.FuelLogResultsViewModel @{ @@ -44,15 +45,7 @@ grid.Column("MPG"), grid.Column("GasPurchased", "Gas Purchased", @@String.Format("{0:0.000}", item.GasPurchased)), grid.Column("TotalPrice", "Total Price", @@String.Format("{0:C}", item.TotalPrice)), - grid.Column("Log", "Matched Log", @ - @(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", - matchcount=Url.Action("AvailableMatchCount", "FuelLog", new {id = item.FuelLogId}) - })) - )), + grid.Column("Log", "Matched Log", item => @Html.Partial("MatchLink", new MatchLinkViewModel (item.FuelLogId, item.LogId)))), htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"}, numericLinksCount: 20 )