From 4af27cc4b5118e7225652909bb759f3024f390b9 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 8 Feb 2012 16:26:34 -0800 Subject: [PATCH] History grid will now be built from a json array sent to the view. --- .../RegisterDatatablesModelBinder.cs | 14 ++++ NzbDrone.Web/Controllers/HistoryController.cs | 36 ++------- NzbDrone.Web/Models/HistoryGridModel.cs | 12 +++ NzbDrone.Web/Models/HistoryModel.cs | 6 +- NzbDrone.Web/NzbDrone.Web.csproj | 10 ++- NzbDrone.Web/Scripts/NzbDrone/grid.js | 14 +++- NzbDrone.Web/Views/History/History.cshtml | 26 ------- NzbDrone.Web/Views/History/Index.cshtml | 74 +++++++++++++++---- 8 files changed, 115 insertions(+), 77 deletions(-) create mode 100644 NzbDrone.Web/App_Start/RegisterDatatablesModelBinder.cs create mode 100644 NzbDrone.Web/Models/HistoryGridModel.cs delete mode 100644 NzbDrone.Web/Views/History/History.cshtml diff --git a/NzbDrone.Web/App_Start/RegisterDatatablesModelBinder.cs b/NzbDrone.Web/App_Start/RegisterDatatablesModelBinder.cs new file mode 100644 index 000000000..abf48c1e8 --- /dev/null +++ b/NzbDrone.Web/App_Start/RegisterDatatablesModelBinder.cs @@ -0,0 +1,14 @@ +using System.Web.Mvc; +using System.Web.WebPages; +//using RazorGenerator.Mvc; + +[assembly: WebActivator.PreApplicationStartMethod(typeof(NzbDrone.Web.App_Start.RegisterDatatablesModelBinder), "Start")] + +namespace NzbDrone.Web.App_Start { + public static class RegisterDatatablesModelBinder { + public static void Start() { + if (!ModelBinders.Binders.ContainsKey(typeof(Mvc.JQuery.Datatables.DataTablesParam))) + ModelBinders.Binders.Add(typeof(Mvc.JQuery.Datatables.DataTablesParam), new Mvc.JQuery.Datatables.DataTablesModelBinder()); + } + } +} diff --git a/NzbDrone.Web/Controllers/HistoryController.cs b/NzbDrone.Web/Controllers/HistoryController.cs index 93091fef1..9c1b80a68 100644 --- a/NzbDrone.Web/Controllers/HistoryController.cs +++ b/NzbDrone.Web/Controllers/HistoryController.cs @@ -1,5 +1,7 @@ using System.Linq; using System.Web.Mvc; +using System.Web.Script.Serialization; +using Mvc.JQuery.Datatables; using NzbDrone.Core.Jobs; using NzbDrone.Core.Providers; using NzbDrone.Web.Models; @@ -24,20 +26,21 @@ namespace NzbDrone.Web.Controllers { HistoryId = h.HistoryId, SeriesId = h.SeriesId, - SeasonNumber = h.Episode.SeasonNumber, - EpisodeNumber = h.Episode.EpisodeNumber, + EpisodeNumbering = string.Format("{0}x{1:00}", h.Episode.SeasonNumber, h.Episode.EpisodeNumber), EpisodeTitle = h.Episode.Title, EpisodeOverview = h.Episode.Overview, SeriesTitle = h.SeriesTitle, NzbTitle = h.NzbTitle, Quality = h.Quality.ToString(), IsProper = h.IsProper, - Date = h.Date, + Date = h.Date.ToString(), Indexer = h.Indexer, EpisodeId = h.EpisodeId - }).ToList(); + }).OrderByDescending(h => h.Date).ToList(); - return View(history); + var serialized = new JavaScriptSerializer().Serialize(history); + + return View((object)serialized); } public JsonResult Trim() @@ -72,28 +75,5 @@ namespace NzbDrone.Web.Controllers return JsonNotificationResult.Info("Episode Redownload Started"); } - - [GridAction] - public ActionResult _AjaxBinding() - { - var history = _historyProvider.AllItemsWithRelationships().Select(h => new HistoryModel - { - HistoryId = h.HistoryId, - SeriesId = h.SeriesId, - SeasonNumber = h.Episode.SeasonNumber, - EpisodeNumber = h.Episode.EpisodeNumber, - EpisodeTitle = h.Episode.Title, - EpisodeOverview = h.Episode.Overview, - SeriesTitle = h.SeriesTitle, - NzbTitle = h.NzbTitle, - Quality = h.Quality.ToString(), - IsProper = h.IsProper, - Date = h.Date, - Indexer = h.Indexer, - EpisodeId = h.EpisodeId - }); - - return View(new GridModel(history)); - } } } \ No newline at end of file diff --git a/NzbDrone.Web/Models/HistoryGridModel.cs b/NzbDrone.Web/Models/HistoryGridModel.cs new file mode 100644 index 000000000..a254321cc --- /dev/null +++ b/NzbDrone.Web/Models/HistoryGridModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace NzbDrone.Web.Models +{ + public class HistoryGridModel + { + public string JsonData { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Web/Models/HistoryModel.cs b/NzbDrone.Web/Models/HistoryModel.cs index 1bb6cbd25..3b15b99c7 100644 --- a/NzbDrone.Web/Models/HistoryModel.cs +++ b/NzbDrone.Web/Models/HistoryModel.cs @@ -8,15 +8,15 @@ namespace NzbDrone.Web.Models public int HistoryId { get; set; } public int SeriesId { get; set; } public string SeriesTitle { get; set; } - public int SeasonNumber { get; set; } - public int EpisodeNumber { get; set; } + public string EpisodeNumbering { get; set; } public string EpisodeTitle { get; set; } public string EpisodeOverview { get; set; } public string NzbTitle { get; set; } public string Quality { get; set; } - public DateTime Date { get; set; } + public string Date { get; set; } public bool IsProper { get; set; } public string Indexer { get; set; } public int EpisodeId { get; set; } + public string Details { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 101c7de0a..139890885 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -53,6 +53,9 @@ True ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + ..\packages\Mvc.JQuery.Datatables.1.1.47\lib\net40\Mvc.JQuery.Datatables.dll + ..\packages\MiniProfiler.1.9\lib\net40\MvcMiniProfiler.dll @@ -79,11 +82,13 @@ True ..\packages\EntityFramework.SqlServerCompact.4.1.8482.2\lib\System.Data.SqlServerCe.Entity.dll + True + False ..\Libraries\MVC3\System.Web.Mvc.dll @@ -268,6 +273,7 @@ + @@ -295,6 +301,7 @@ + @@ -482,6 +489,7 @@ + @@ -678,7 +686,7 @@ - + diff --git a/NzbDrone.Web/Scripts/NzbDrone/grid.js b/NzbDrone.Web/Scripts/NzbDrone/grid.js index fefe92579..3e2920a5e 100644 --- a/NzbDrone.Web/Scripts/NzbDrone/grid.js +++ b/NzbDrone.Web/Scripts/NzbDrone/grid.js @@ -30,13 +30,21 @@ $('.dataTable td:not(:last-child)').live('click', function () { } else { - oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'Details'); + oTable.fnOpen(nTr, fnFormatDetails(nTr), 'Details'); $(nTr).addClass('details-opened'); } }); //Datatables format display details -function fnFormatDetails(oTable, nTr) { +function fnFormatDetails(nTr) { var aData = oTable.fnGetData(nTr); - return aData[aData.length - 1]; + return aData["Details"]; +} + +//Create Image +function createImageAjaxLink(url, image, alt, title, classes) { + var html = "" + + "\"""; + + return html; } \ No newline at end of file diff --git a/NzbDrone.Web/Views/History/History.cshtml b/NzbDrone.Web/Views/History/History.cshtml deleted file mode 100644 index a86e8db9b..000000000 --- a/NzbDrone.Web/Views/History/History.cshtml +++ /dev/null @@ -1,26 +0,0 @@ - -@using NzbDrone.Web.Helpers -@model NzbDrone.Web.Models.HistoryModel - - - @Model.Indexer - @Html.ActionLink(Model.SeriesTitle, "Details", "Series", new { seriesId = Model.SeriesId }, null) - @Model.SeasonNumber - @Model.EpisodeNumber - @Model.EpisodeTitle - @Model.Quality - @Model.Date - - @*Commands Column*@ - - @Ajax.ImageActionLink("../../Content/Images/X.png", new { Alt = "Delete", Title = "Delete from history", @class = "searchImage" }, "Delete", "History", new { HistoryId = Model.HistoryId }, new AjaxOptions { OnSuccess = "reloadHistoryGrid" }, null) - @Ajax.ImageActionLink("../../Content/Images/Downloading.png", new { Alt = "Redownload", Title = "Redownlod Episode", @class = "searchImage" }, "Redownload", "History", new { HistoryId = @Model.HistoryId, EpisodeId = @Model.EpisodeId }, new AjaxOptions { OnSuccess = "reloadHistoryGrid" }, null) - - - @*Details Column*@ - - Overview: @Model.EpisodeOverview
- NZB Title: @Model.NzbTitle
- Proper: @Model.IsProper - - \ No newline at end of file diff --git a/NzbDrone.Web/Views/History/Index.cshtml b/NzbDrone.Web/Views/History/Index.cshtml index cabe8ea8b..9ea805a4d 100644 --- a/NzbDrone.Web/Views/History/Index.cshtml +++ b/NzbDrone.Web/Views/History/Index.cshtml @@ -1,4 +1,4 @@ -@model List +@model String @using NzbDrone.Common @using NzbDrone.Web.Models @using NzbDrone.Web.Helpers @@ -20,8 +20,7 @@ Series Title - Season # - Episode # + Episode Episode Title Quality Grabbed On @@ -30,14 +29,14 @@ Actions @*Details Column*@ - Detailsn + Details - @foreach(var history in Model) + @*@foreach(var history in Model) { Html.RenderPartial("History", history); - } + }*@ @@ -55,6 +54,10 @@ $('#historyGrid').removeClass('hidden-grid'); oTable = $('#historyGrid').dataTable({ + //"sAjaxSource": "History/AjaxBinding", + //"bProcessing": true, + "bShowAll": false, + "aaData": @Html.Raw(Model), "bPaginate": true, "bLengthChange": false, "bFilter": true, @@ -64,17 +67,56 @@ "iDisplayLength": 20, "sPaginationType": "four_button", "aoColumns": [ - { sWidth: '20px', "bSortable": false }, //Image - { sWidth: 'auto' }, //Series Title - { sWidth: '90px' }, //Season # - { sWidth: '90px' }, //Episode # - { sWidth: 'auto' }, //Episode Title - { sWidth: '70px' }, //Quality - { sWidth: '150px' }, //Grabbed On - { sWidth: '40px', "bSortable": false }, //Actions - { sWidth: 'auto', "bSortable": false, "bVisible": false } //Details + { sWidth: '20px', "bSortable": false, "mDataProp": "Indexer", "fnRender": function (row) { + return "\"""; + } + }, //Image + { sWidth: 'auto', "mDataProp": "SeriesTitle" }, //Series Title + { sWidth: '80px', "mDataProp": "EpisodeNumbering", "bSortable": false }, //EpisodeNumbering + { sWidth: 'auto', "mDataProp": "EpisodeTitle", "bSortable": false }, //Episode Title + { sWidth: '70px', "mDataProp": "Quality", "bSoratble": false }, //Quality + { sWidth: '150px', "mDataProp": "Date" }, //Grabbed On + { sWidth: '40px', "mDataProp": "HistoryId", "bSortable": false, "fnRender": function (row) { + var deleteImage = "\"Delete\""; + var redownloadImage = "\"Redownload\""; + + return deleteImage + redownloadImage; + //return createImageAjaxLink('/History/Delete?historyId=' + row.aData["HistoryId"], '../../Content/Images/X.png', 'Delete', 'Delete from History', 'searchImage'); + } + }, //Actions + { sWidth: 'auto', "mDataProp": "Details", "bSortable": false, "bVisible": false, "fnRender": function (row) { + var result = "Overview: " + row.aData["EpisodeOverview"] + "
" + + "NZB Title: " + row.aData["NzbTitle"] + "
" + + "Proper: " + row.aData["IsProper"]; + return result; + } + } //Details ], - "aaSorting": [[6, 'desc']] + "aaSorting": [[5, 'desc']] }); }); + + function deleteHistory(row, historyId) { + //Delete from DB + $.ajax({ + type: "POST", + url: deleteHistoryRowUrl, + data: { historyId: historyId }, + success: function () { + oTable.fnDeleteRow(oTable.fnGetPosition(row)); + } + }); + + } + + function redownloadHistory(row, historyId, episodeId) { + $.ajax({ + type: "POST", + url: redownloadUrl, + data: { historyId: historyId, episodeId: episodeId }, + success: function () { + oTable.fnDeleteRow(oTable.fnGetPosition(row)); + } + }); + }