From 3aa0507912da5139578118349d4b0b7dccfca379 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 9 Jul 2013 08:41:42 -0700 Subject: [PATCH] Toggle episode monitored status from the table --- NzbDrone.Api/Episodes/EpisodeModule.cs | 8 ++++++++ NzbDrone.Api/NzbDrone.Api.csproj | 1 + NzbDrone.Api/Seasons/SeasonModule.cs | 24 ++++++++++++++++-------- NzbDrone.Api/Seasons/SeasonResource.cs | 16 ++++++++++++++++ UI/Cells/ToggleCell.js | 10 +++++++--- UI/Series/Details/SeasonLayout.js | 7 ++++--- 6 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 NzbDrone.Api/Seasons/SeasonResource.cs diff --git a/NzbDrone.Api/Episodes/EpisodeModule.cs b/NzbDrone.Api/Episodes/EpisodeModule.cs index e2d4e23d5..bb17aa218 100644 --- a/NzbDrone.Api/Episodes/EpisodeModule.cs +++ b/NzbDrone.Api/Episodes/EpisodeModule.cs @@ -19,6 +19,7 @@ public EpisodeModule(IEpisodeService episodeService, MediaFileRepository mediaFi _mediaFileRepository = mediaFileRepository; GetResourceAll = GetEpisodes; + UpdateResource = SetMonitored; } private List GetEpisodes() @@ -35,5 +36,12 @@ private List GetEpisodes() return resource.ToList(); } + + private EpisodeResource SetMonitored(EpisodeResource episodeResource) + { + _episodeService.SetEpisodeMonitored(episodeResource.Id, episodeResource.Monitored); + + return episodeResource; + } } } \ No newline at end of file diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 7dd87b51a..896dcebfa 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -140,6 +140,7 @@ + diff --git a/NzbDrone.Api/Seasons/SeasonModule.cs b/NzbDrone.Api/Seasons/SeasonModule.cs index 62b69e2fa..4c11a2f06 100644 --- a/NzbDrone.Api/Seasons/SeasonModule.cs +++ b/NzbDrone.Api/Seasons/SeasonModule.cs @@ -1,29 +1,37 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using Nancy; using NzbDrone.Api.Extensions; +using NzbDrone.Api.REST; using NzbDrone.Core.Tv; namespace NzbDrone.Api.Seasons { - public class SeasonModule : NzbDroneApiModule + public class SeasonModule : NzbDroneRestModule { private readonly ISeasonService _seasonService; public SeasonModule(ISeasonService seasonService) - : base("/Season") + : base("/season") { _seasonService = seasonService; - Get["/"] = x => GetSeasons(); + GetResourceAll = GetSeasons; + UpdateResource = SetMonitored; } - private Response GetSeasons() + private List GetSeasons() { var seriesId = Request.Query.SeriesId; - return JsonExtensions.AsResponse(_seasonService.GetSeasonsBySeries(seriesId)); + return ToListResource(() => _seasonService.GetSeasonsBySeries(seriesId)); + } + + private SeasonResource SetMonitored(SeasonResource seasonResource) + { + _seasonService.SetMonitored(seasonResource.SeriesId, seasonResource.SeasonNumber, seasonResource.Monitored); + + return seasonResource; } } - - } \ No newline at end of file diff --git a/NzbDrone.Api/Seasons/SeasonResource.cs b/NzbDrone.Api/Seasons/SeasonResource.cs new file mode 100644 index 000000000..aeeb13354 --- /dev/null +++ b/NzbDrone.Api/Seasons/SeasonResource.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NzbDrone.Api.REST; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Api.Seasons +{ + public class SeasonResource : RestResource + { + public int SeriesId { get; set; } + public int SeasonNumber { get; set; } + public Boolean Monitored { get; set; } + } +} diff --git a/UI/Cells/ToggleCell.js b/UI/Cells/ToggleCell.js index ebe82af8e..f0337aa82 100644 --- a/UI/Cells/ToggleCell.js +++ b/UI/Cells/ToggleCell.js @@ -21,11 +21,8 @@ define( this.model.save(); }, - render: function () { this.$el.empty(); - - this.$el.html(''); var name = this.column.get('name'); @@ -36,6 +33,13 @@ define( else { this.$('i').addClass(this.column.get('falseClass')); } + + var tooltip = this.column.get('tooltip'); + + if (tooltip) { + this.$('i').attr('title', tooltip); + } + return this; } }); diff --git a/UI/Series/Details/SeasonLayout.js b/UI/Series/Details/SeasonLayout.js index 31c0c466f..d9cb29b3c 100644 --- a/UI/Series/Details/SeasonLayout.js +++ b/UI/Series/Details/SeasonLayout.js @@ -28,11 +28,12 @@ define( columns: [ { - name : 'ignored', + name : 'monitored', label : '', cell : ToggleCell, - trueClass : 'icon-bookmark-empty', - falseClass: 'icon-bookmark' + trueClass : 'icon-bookmark', + falseClass: 'icon-bookmark-empty', + tooltip : 'Toggle monitored status' }, { name : 'episodeNumber',