Repurposed the Missing page to include filter options and display episodes that haven't reached cutoff.

--HG--
rename : src/NzbDrone.Api/Missing/MissingModule.cs => src/NzbDrone.Api/Wanted/MissingModule.cs
rename : src/UI/Missing/ControlsColumnTemplate.html => src/UI/Wanted/ControlsColumnTemplate.html
rename : src/UI/Missing/MissingCollection.js => src/UI/Wanted/Missing/MissingCollection.js
rename : src/UI/Missing/MissingLayout.js => src/UI/Wanted/WantedLayout.js
rename : src/UI/Missing/MissingLayoutTemplate.html => src/UI/Wanted/WantedLayoutTemplate.html
extra : source : 2c76f3e423d39446f3bd7799b7344d7be63c70f5
This commit is contained in:
Taloth Saldono 2014-02-09 20:03:49 +01:00 committed by Mark McDowall
parent 935c26d03e
commit d416dd4177
23 changed files with 596 additions and 62 deletions

View File

@ -150,7 +150,8 @@
<Compile Include="Mapping\MappingValidation.cs" />
<Compile Include="Mapping\ResourceMappingException.cs" />
<Compile Include="Mapping\ValueInjectorExtensions.cs" />
<Compile Include="Missing\MissingModule.cs" />
<Compile Include="Wanted\CutoffModule.cs" />
<Compile Include="Wanted\MissingModule.cs" />
<Compile Include="Config\NamingSampleResource.cs" />
<Compile Include="NzbDroneRestModuleWithSignalR.cs" />
<Compile Include="Qualities\QualityProfileValidation.cs" />

View File

@ -0,0 +1,45 @@
using System.Linq;
using NzbDrone.Api.Episodes;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Api.Wanted
{
public class CutoffModule : NzbDroneRestModule<EpisodeResource>
{
private readonly IEpisodeService _episodeService;
private readonly SeriesRepository _seriesRepository;
public CutoffModule(IEpisodeService episodeService, SeriesRepository seriesRepository)
:base("wanted/cutoff")
{
_episodeService = episodeService;
_seriesRepository = seriesRepository;
GetResourcePaged = GetCutoffUnmetEpisodes;
}
private PagingResource<EpisodeResource> GetCutoffUnmetEpisodes(PagingResource<EpisodeResource> pagingResource)
{
var pagingSpec = new PagingSpec<Episode>
{
Page = pagingResource.Page,
PageSize = pagingResource.PageSize,
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection
};
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;
else
pagingSpec.FilterExpression = v => v.Monitored == true && v.Series.Monitored == true;
PagingResource<EpisodeResource> resource = ApplyToPage(_episodeService.GetCutoffUnmetEpisodes, pagingSpec);
resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList();
return resource;
}
}
}

View File

@ -4,7 +4,7 @@ using NzbDrone.Api.Extensions;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv;
namespace NzbDrone.Api.Missing
namespace NzbDrone.Api.Wanted
{
public class MissingModule : NzbDroneRestModule<EpisodeResource>
{
@ -12,7 +12,7 @@ namespace NzbDrone.Api.Missing
private readonly SeriesRepository _seriesRepository;
public MissingModule(IEpisodeService episodeService, SeriesRepository seriesRepository)
:base("missing")
:base("wanted/missing")
{
_episodeService = episodeService;
_seriesRepository = seriesRepository;
@ -28,8 +28,14 @@ namespace NzbDrone.Api.Missing
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection
};
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;
else
pagingSpec.FilterExpression = v => v.Monitored == true && v.Series.Monitored == true;
PagingResource<EpisodeResource> resource = ApplyToPage(v => _episodeService.GetMissingEpisodes(v), pagingSpec);
var resource = ApplyToPage(_episodeService.EpisodesWithoutFiles, pagingSpec);
resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList();
return resource;

View File

@ -79,7 +79,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
[Test]
public void should_get_monitored_episodes()
{
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
var episodes = Subject.GetMissingEpisodes(_pagingSpec, false);
episodes.Records.Should().HaveCount(1);
}
@ -88,7 +88,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
[Ignore("Specials not implemented")]
public void should_get_episode_including_specials()
{
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, true);
var episodes = Subject.GetMissingEpisodes(_pagingSpec, true);
episodes.Records.Should().HaveCount(2);
}
@ -96,7 +96,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
[Test]
public void should_not_include_unmonitored_episodes()
{
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
var episodes = Subject.GetMissingEpisodes(_pagingSpec, false);
episodes.Records.Should().NotContain(e => e.Monitored == false);
}
@ -104,7 +104,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
[Test]
public void should_not_contain_unmonitored_series()
{
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
var episodes = Subject.GetMissingEpisodes(_pagingSpec, false);
episodes.Records.Should().NotContain(e => e.SeriesId == _unmonitoredSeries.Id);
}
@ -112,7 +112,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
[Test]
public void should_have_count_of_one()
{
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
var episodes = Subject.GetMissingEpisodes(_pagingSpec, false);
episodes.TotalRecords.Should().Be(1);
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using Marr.Data.QGen;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.MediaFiles;
namespace NzbDrone.Core.Tv
{
@ -17,7 +17,8 @@ namespace NzbDrone.Core.Tv
List<Episode> GetEpisodes(int seriesId);
List<Episode> GetEpisodes(int seriesId, int seasonNumber);
List<Episode> GetEpisodeByFileId(int fileId);
PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec, bool includeSpecials);
PagingSpec<Episode> GetMissingEpisodes(PagingSpec<Episode> pagingSpec, bool includeSpecials);
List<Episode> GetCutoffUnmetEpisodes(PagingSpec<Episode> pagingSpec, bool includeSpecials);
Episode FindEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate);
void SetMonitoredFlat(Episode episode, bool monitored);
@ -81,7 +82,7 @@ namespace NzbDrone.Core.Tv
return Query.Where(e => e.EpisodeFileId == fileId).ToList();
}
public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec, bool includeSpecials)
public PagingSpec<Episode> GetMissingEpisodes(PagingSpec<Episode> pagingSpec, bool includeSpecials)
{
var currentTime = DateTime.UtcNow;
var startingSeasonNumber = 1;
@ -91,12 +92,47 @@ namespace NzbDrone.Core.Tv
startingSeasonNumber = 0;
}
pagingSpec.Records = GetEpisodesWithoutFilesQuery(pagingSpec, currentTime, startingSeasonNumber).ToList();
pagingSpec.TotalRecords = GetEpisodesWithoutFilesQuery(pagingSpec, currentTime, startingSeasonNumber).GetRowCount();
pagingSpec.TotalRecords = GetMissingEpisodesQuery(pagingSpec, currentTime, startingSeasonNumber).GetRowCount();
pagingSpec.Records = GetMissingEpisodesQuery(pagingSpec, currentTime, startingSeasonNumber).ToList();
return pagingSpec;
}
public List<Episode> GetCutoffUnmetEpisodes(PagingSpec<Episode> pagingSpec, bool includeSpecials)
{
var currentTime = DateTime.UtcNow;
var startingSeasonNumber = 1;
if (includeSpecials)
{
startingSeasonNumber = 0;
}
var query = Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
.Join<Episode, EpisodeFile>(JoinType.Left, e => e.EpisodeFile, (e, s) => e.EpisodeFileId == s.Id)
.Where(pagingSpec.FilterExpression)
.AndWhere(e => e.EpisodeFileId != 0)
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
.AndWhere(e => e.AirDateUtc <= currentTime)
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection());
return query.ToList();
}
private SortBuilder<Episode> GetMissingEpisodesQuery(PagingSpec<Episode> pagingSpec, DateTime currentTime, int startingSeasonNumber)
{
var query = Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
.Where(pagingSpec.FilterExpression)
.AndWhere(e => e.EpisodeFileId == 0)
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
.AndWhere(e => e.AirDateUtc <= currentTime)
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
.Skip(pagingSpec.PagingOffset())
.Take(pagingSpec.PageSize);
return query;
}
public Episode FindEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber)
{
return Query.Where(s => s.SeriesId == seriesId)
@ -141,18 +177,5 @@ namespace NzbDrone.Core.Tv
{
SetFields(new Episode { Id = episodeId, EpisodeFileId = fileId }, episode => episode.EpisodeFileId);
}
private SortBuilder<Episode> GetEpisodesWithoutFilesQuery(PagingSpec<Episode> pagingSpec, DateTime currentTime, int startingSeasonNumber)
{
return Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
.Where(e => e.EpisodeFileId == 0)
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
.AndWhere(e => e.AirDateUtc <= currentTime)
.AndWhere(e => e.Monitored)
.AndWhere(e => e.Series.Monitored)
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
.Skip(pagingSpec.PagingOffset())
.Take(pagingSpec.PageSize);
}
}
}

View File

@ -7,6 +7,7 @@ using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tv.Events;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Tv
{
@ -20,7 +21,8 @@ namespace NzbDrone.Core.Tv
Episode FindEpisode(int seriesId, String date);
List<Episode> GetEpisodeBySeries(int seriesId);
List<Episode> GetEpisodesBySeason(int seriesId, int seasonNumber);
PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec);
PagingSpec<Episode> GetMissingEpisodes(PagingSpec<Episode> pagingSpec);
PagingSpec<Episode> GetCutoffUnmetEpisodes(PagingSpec<Episode> pagingSpec);
List<Episode> GetEpisodesByFileId(int episodeFileId);
void UpdateEpisode(Episode episode);
void SetEpisodeMonitored(int episodeId, bool monitored);
@ -40,12 +42,14 @@ namespace NzbDrone.Core.Tv
{
private readonly IEpisodeRepository _episodeRepository;
private readonly IQualityProfileRepository _qualityProfileRepository;
private readonly IConfigService _configService;
private readonly Logger _logger;
public EpisodeService(IEpisodeRepository episodeRepository, IConfigService configService, Logger logger)
public EpisodeService(IEpisodeRepository episodeRepository, IQualityProfileRepository qualityProfileRepository, IConfigService configService, Logger logger)
{
_episodeRepository = episodeRepository;
_qualityProfileRepository = qualityProfileRepository;
_configService = configService;
_logger = logger;
}
@ -88,7 +92,7 @@ namespace NzbDrone.Core.Tv
{
return _episodeRepository.GetEpisodes(seriesId, seasonNumber);
}
public Episode FindEpisodeByName(int seriesId, int seasonNumber, string episodeTitle)
{
// TODO: can replace this search mechanism with something smarter/faster/better
@ -105,11 +109,39 @@ namespace NzbDrone.Core.Tv
public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec)
{
var episodeResult = _episodeRepository.EpisodesWithoutFiles(pagingSpec, false);
var episodeResult = _episodeRepository.GetMissingEpisodes(pagingSpec, false);
return episodeResult;
}
public PagingSpec<Episode> GetCutoffUnmetEpisodes(PagingSpec<Episode> pagingSpec)
{
var allSpec = new PagingSpec<Episode>
{
SortKey = pagingSpec.SortKey,
SortDirection = pagingSpec.SortDirection,
FilterExpression = pagingSpec.FilterExpression
};
var allItems = _episodeRepository.GetCutoffUnmetEpisodes(allSpec, false);
var qualityProfileComparers = _qualityProfileRepository.All().ToDictionary(v => v.Id, v => new { Profile = v, Comparer = new QualityModelComparer(v) });
var filtered = allItems.Where(episode =>
{
var profile = qualityProfileComparers[episode.Series.QualityProfileId];
return profile.Comparer.Compare(episode.EpisodeFile.Value.Quality.Quality, profile.Profile.Cutoff) < 0;
}).ToList();
pagingSpec.Records = filtered
.Skip(pagingSpec.PagingOffset())
.Take(pagingSpec.PageSize)
.ToList();
pagingSpec.TotalRecords = filtered.Count;
return pagingSpec;
}
public List<Episode> GetEpisodesByFileId(int episodeFileId)
{
return _episodeRepository.GetEpisodeByFileId(episodeFileId);

View File

@ -6,7 +6,7 @@
<mapping url="http://localhost:8989/Upcoming" local-file="$PROJECT_DIR$/Upcoming" />
<mapping url="http://localhost:8989/app.js" local-file="$PROJECT_DIR$/app.js" />
<mapping url="http://localhost:8989/Mixins" local-file="$PROJECT_DIR$/Mixins" />
<mapping url="http://localhost:8989/Missing" local-file="$PROJECT_DIR$/Missing" />
<mapping url="http://localhost:8989/Wanted" local-file="$PROJECT_DIR$/Wanted" />
<mapping url="http://localhost:8989/Quality" local-file="$PROJECT_DIR$/Quality" />
<mapping url="http://localhost:8989/Config.js" local-file="$PROJECT_DIR$/Config.js" />
<mapping url="http://localhost:8989/Shared" local-file="$PROJECT_DIR$/Shared" />

View File

@ -6,7 +6,7 @@
<mapping url="http://localhost:8989/Upcoming" local-file="$PROJECT_DIR$/Upcoming" />
<mapping url="http://localhost:8989/app.js" local-file="$PROJECT_DIR$/app.js" />
<mapping url="http://localhost:8989/Mixins" local-file="$PROJECT_DIR$/Mixins" />
<mapping url="http://localhost:8989/Missing" local-file="$PROJECT_DIR$/Missing" />
<mapping url="http://localhost:8989/Wanted" local-file="$PROJECT_DIR$/Wanted" />
<mapping url="http://localhost:8989/Config.js" local-file="$PROJECT_DIR$/Config.js" />
<mapping url="http://localhost:8989/Quality" local-file="$PROJECT_DIR$/Quality" />
<mapping url="http://localhost:8989/AddSeries" local-file="$PROJECT_DIR$/AddSeries" />

View File

@ -52,7 +52,24 @@ define(
return;
}
else if (hasFile && this.model.get('episodeFile')) {
var episodeFile = this.model.get('episodeFile');
var quality = episodeFile.quality;
var size = FormatHelpers.bytes(episodeFile.size);
var title = 'Episode downloaded';
if (quality.proper) {
title += ' [PROPER] - {0}'.format(size);
this.$el.html('<span class="badge badge-info" title="{0}">{1}</span>'.format(title, quality.quality.name));
}
else {
title += ' - {0}'.format(size);
this.$el.html('<span class="badge badge-inverse" title="{0}">{1}</span>'.format(title, quality.quality.name));
}
return;
}
else {
var model = this.model;
var downloading = QueueCollection.findEpisode(model.get('id'));

View File

@ -7,7 +7,7 @@ define(
'History/HistoryLayout',
'Settings/SettingsLayout',
'AddSeries/AddSeriesLayout',
'Missing/MissingLayout',
'Wanted/WantedLayout',
'Calendar/CalendarLayout',
'Release/ReleaseLayout',
'System/SystemLayout',
@ -20,7 +20,7 @@ define(
HistoryLayout,
SettingsLayout,
AddSeriesLayout,
MissingLayout,
WantedLayout,
CalendarLayout,
ReleaseLayout,
SystemLayout,
@ -44,10 +44,10 @@ define(
this.showMainRegion(new SettingsLayout({ action: action }));
},
missing: function () {
this.setTitle('Missing');
wanted: function (action) {
this.setTitle('Wanted');
this.showMainRegion(new MissingLayout());
this.showMainRegion(new WantedLayout({ action: action }));
},
history: function (action) {

View File

@ -24,7 +24,7 @@ define(
};
this.prototype.setFilterMode = function(mode, options) {
this.setFilter(this.filterModes[mode], options);
return this.setFilter(this.filterModes[mode], options);
};
var originalMakeFullCollection = this.prototype._makeFullCollection;

View File

@ -29,10 +29,10 @@
</a>
</li>
<li>
<a href="{{UrlBase}}/missing">
<a href="{{UrlBase}}/wanted">
<i class="icon-warning-sign"></i>
<br>
Missing
Wanted
</a>
</li>
<li>

View File

@ -14,7 +14,8 @@ define(
'calendar' : 'calendar',
'settings' : 'settings',
'settings/:action(/:query)' : 'settings',
'missing' : 'missing',
'wanted' : 'wanted',
'wanted/:action' : 'wanted',
'history' : 'history',
'history/:action' : 'history',
'rss' : 'rss',

View File

@ -16,13 +16,17 @@ define(
initialize: function (options) {
this.menu = options.menu;
if (this.menu.storeState) {
this.setActive();
}
this.setActive();
},
setActive: function () {
var storedKey = Config.getValue(this.menu.menuKey, this.menu.defaultAction);
var storedKey = this.menu.defaultAction;
if (this.menu.storeState)
storedKey = Config.getValue(this.menu.menuKey, storedKey);
if (!storedKey)
return;
this.collection.each(function (model) {
if (model.get('key').toLocaleLowerCase() === storedKey.toLowerCase()) {

View File

@ -1,19 +1,21 @@
'use strict';
define(
[
'underscore',
'Series/EpisodeModel',
'backbone.pageable',
'Mixins/AsFilteredCollection',
'Mixins/AsPersistedStateCollection'
], function (EpisodeModel, PagableCollection, AsPersistedStateCollection) {
], function (_, EpisodeModel, PagableCollection, AsFilteredCollection, AsPersistedStateCollection) {
var collection = PagableCollection.extend({
url : window.NzbDrone.ApiRoot + '/missing',
url : window.NzbDrone.ApiRoot + '/wanted/cutoff',
model: EpisodeModel,
tableName: 'missing',
tableName: 'wanted.cutoff',
state: {
pageSize: 15,
sortKey : 'airDateUtc',
order : 1
pageSize : 15,
sortKey : 'airDateUtc',
order : 1
},
queryParams: {
@ -27,6 +29,12 @@ define(
'1' : 'desc'
}
},
// Filter Modes
filterModes: {
'monitored' : ['monitored', 'true'],
'unmonitored' : ['monitored', 'false'],
},
parseState: function (resp) {
return {totalRecords: resp.totalRecords};
@ -41,5 +49,6 @@ define(
}
});
collection = AsFilteredCollection.call(collection);
return AsPersistedStateCollection.call(collection);
});

View File

@ -0,0 +1,206 @@
'use strict';
define(
[
'underscore',
'marionette',
'backgrid',
'Wanted/Cutoff/CutoffUnmetCollection',
'Cells/SeriesTitleCell',
'Cells/EpisodeNumberCell',
'Cells/EpisodeTitleCell',
'Cells/RelativeDateCell',
'Cells/EpisodeStatusCell',
'Shared/Grid/Pager',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView',
'Shared/Messenger',
'Commands/CommandController',
'backgrid.selectall'
], function (_,
Marionette,
Backgrid,
CutoffUnmetCollection,
SeriesTitleCell,
EpisodeNumberCell,
EpisodeTitleCell,
RelativeDateCell,
EpisodeStatusCell,
GridPager,
ToolbarLayout,
LoadingView,
Messenger,
CommandController) {
return Marionette.Layout.extend({
template: 'Wanted/Cutoff/CutoffUnmetLayoutTemplate',
regions: {
missing: '#x-missing',
toolbar: '#x-toolbar',
pager : '#x-pager'
},
ui: {
searchSelectedButton: '.btn i.icon-search'
},
columns:
[
{
name : '',
cell : 'select-row',
headerCell: 'select-all',
sortable : false
},
{
name : 'series',
label : 'Series Title',
sortable : false,
cell : SeriesTitleCell
},
{
name : 'this',
label : 'Episode',
sortable : false,
cell : EpisodeNumberCell
},
{
name : 'this',
label : 'Episode Title',
sortable : false,
cell : EpisodeTitleCell,
},
{
name : 'airDateUtc',
label : 'Air Date',
cell : RelativeDateCell
},
{
name : 'status',
label : 'Status',
cell : EpisodeStatusCell,
sortable: false
}
],
initialize: function () {
this.collection = new CutoffUnmetCollection();
this.listenTo(this.collection, 'sync', this._showTable);
},
onShow: function () {
this.missing.show(new LoadingView());
this._showToolbar();
this.collection.fetch();
},
_showTable: function () {
this.missingGrid = new Backgrid.Grid({
columns : this.columns,
collection: this.collection,
className : 'table table-hover'
});
this.missing.show(this.missingGrid);
this.pager.show(new GridPager({
columns : this.columns,
collection: this.collection
}));
},
_showToolbar: function () {
var leftSideButtons = {
type : 'default',
storeState: false,
items :
[
{
title: 'Search Selected',
icon : 'icon-search',
callback: this._searchSelected,
ownerContext: this
},
{
title: 'Season Pass',
icon : 'icon-bookmark',
route: 'seasonpass'
}
]
};
var filterOptions = {
type : 'radio',
storeState : false,
menuKey : 'wanted.filterMode',
defaultAction : 'monitored',
items :
[
{
key : 'monitored',
title : '',
tooltip : 'Monitored Only',
icon : 'icon-nd-monitored',
callback : this._setFilter
},
{
key : 'unmonitored',
title : '',
tooltip : 'Unmonitored Only',
icon : 'icon-nd-unmonitored',
callback : this._setFilter
},
]
};
this.toolbar.show(new ToolbarLayout({
left :
[
leftSideButtons
],
right :
[
filterOptions
],
context: this
}));
CommandController.bindToCommand({
element: this.$('.x-toolbar-left-1 .btn i.icon-search'),
command: {
name: 'episodeSearch'
}
});
},
_setFilter: function(buttonContext) {
var mode = buttonContext.model.get('key');
this.collection.state.currentPage = 1;
var promise = this.collection.setFilterMode(mode);
if (buttonContext)
buttonContext.ui.icon.spinForPromise(promise);
},
_searchSelected: function () {
var selected = this.missingGrid.getSelectedModels();
if (selected.length === 0) {
Messenger.show({
type: 'error',
message: 'No episodes selected'
});
return;
}
var ids = _.pluck(selected, 'id');
CommandController.Execute('episodeSearch', {
name : 'episodeSearch',
episodeIds: ids
});
}
});
});

View File

@ -0,0 +1,54 @@
'use strict';
define(
[
'underscore',
'Series/EpisodeModel',
'backbone.pageable',
'Mixins/AsFilteredCollection',
'Mixins/AsPersistedStateCollection'
], function (_, EpisodeModel, PagableCollection, AsFilteredCollection, AsPersistedStateCollection) {
var collection = PagableCollection.extend({
url : window.NzbDrone.ApiRoot + '/wanted/missing',
model: EpisodeModel,
tableName: 'wanted.missing',
state: {
pageSize : 15,
sortKey : 'airDateUtc',
order : 1
},
queryParams: {
totalPages : null,
totalRecords: null,
pageSize : 'pageSize',
sortKey : 'sortKey',
order : 'sortDir',
directions : {
'-1': 'asc',
'1' : 'desc'
}
},
// Filter Modes
filterModes: {
'monitored' : ['monitored', 'true'],
'unmonitored' : ['monitored', 'false'],
},
parseState: function (resp) {
return {totalRecords: resp.totalRecords};
},
parseRecords: function (resp) {
if (resp) {
return resp.records;
}
return resp;
}
});
collection = AsFilteredCollection.call(collection);
return AsPersistedStateCollection.call(collection);
});

View File

@ -4,11 +4,12 @@ define(
'underscore',
'marionette',
'backgrid',
'Missing/MissingCollection',
'Wanted/Missing/MissingCollection',
'Cells/SeriesTitleCell',
'Cells/EpisodeNumberCell',
'Cells/EpisodeTitleCell',
'Cells/RelativeDateCell',
'Cells/EpisodeStatusCell',
'Shared/Grid/Pager',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView',
@ -23,13 +24,14 @@ define(
EpisodeNumberCell,
EpisodeTitleCell,
RelativeDateCell,
EpisodeStatusCell,
GridPager,
ToolbarLayout,
LoadingView,
Messenger,
CommandController) {
return Marionette.Layout.extend({
template: 'Missing/MissingLayoutTemplate',
template: 'Wanted/Missing/MissingLayoutTemplate',
regions: {
missing: '#x-missing',
@ -52,25 +54,31 @@ define(
{
name : 'series',
label : 'Series Title',
sortable: false,
sortable : false,
cell : SeriesTitleCell
},
{
name : 'this',
label : 'Episode',
sortable: false,
sortable : false,
cell : EpisodeNumberCell
},
{
name : 'this',
label : 'Episode Title',
sortable: false,
cell : EpisodeTitleCell
sortable : false,
cell : EpisodeTitleCell,
},
{
name : 'airDateUtc',
label: 'Air Date',
cell : RelativeDateCell
name : 'airDateUtc',
label : 'Air Date',
cell : RelativeDateCell
},
{
name : 'status',
label : 'Status',
cell : EpisodeStatusCell,
sortable: false
}
],
@ -82,8 +90,8 @@ define(
onShow: function () {
this.missing.show(new LoadingView());
this.collection.fetch();
this._showToolbar();
this.collection.fetch();
},
_showTable: function () {
@ -120,12 +128,40 @@ define(
}
]
};
var filterOptions = {
type : 'radio',
storeState : false,
menuKey : 'wanted.filterMode',
defaultAction : 'monitored',
items :
[
{
key : 'monitored',
title : '',
tooltip : 'Monitored Only',
icon : 'icon-nd-monitored',
callback : this._setFilter
},
{
key : 'unmonitored',
title : '',
tooltip : 'Unmonitored Only',
icon : 'icon-nd-unmonitored',
callback : this._setFilter
},
]
};
this.toolbar.show(new ToolbarLayout({
left :
[
leftSideButtons
],
right :
[
filterOptions
],
context: this
}));
@ -136,6 +172,16 @@ define(
}
});
},
_setFilter: function(buttonContext) {
var mode = buttonContext.model.get('key');
this.collection.state.currentPage = 1;
var promise = this.collection.setFilterMode(mode);
if (buttonContext)
buttonContext.ui.icon.spinForPromise(promise);
},
_searchSelected: function () {
var selected = this.missingGrid.getSelectedModels();

View File

@ -0,0 +1,11 @@
<div id="x-toolbar"/>
<div class="row">
<div class="span12">
<div id="x-missing"/>
</div>
</div>
<div class="row">
<div class="span12">
<div id="x-pager"/>
</div>
</div>

View File

@ -0,0 +1,69 @@
'use strict';
define(
[
'marionette',
'backbone',
'backgrid',
'Wanted/Missing/MissingLayout',
'Wanted/Cutoff/CutoffUnmetLayout'
], function (Marionette, Backbone, Backgrid, MissingLayout, CutoffUnmetLayout) {
return Marionette.Layout.extend({
template: 'Wanted/WantedLayoutTemplate',
regions: {
content : '#content'
//missing : '#missing',
//cutoff : '#cutoff'
},
ui: {
missingTab : '.x-missing-tab',
cutoffTab : '.x-cutoff-tab'
},
events: {
'click .x-missing-tab' : '_showMissing',
'click .x-cutoff-tab' : '_showCutoffUnmet'
},
initialize: function (options) {
if (options.action) {
this.action = options.action.toLowerCase();
}
},
onShow: function () {
switch (this.action) {
case 'cutoff':
this._showCutoffUnmet();
break;
default:
this._showMissing();
}
},
_navigate: function (route) {
Backbone.history.navigate(route);
},
_showMissing: function (e) {
if (e) {
e.preventDefault();
}
this.content.show(new MissingLayout());
this.ui.missingTab.tab('show');
this._navigate('/wanted/missing');
},
_showCutoffUnmet: function (e) {
if (e) {
e.preventDefault();
}
this.content.show(new CutoffUnmetLayout());
this.ui.cutoffTab.tab('show');
this._navigate('/wanted/cutoff');
}
});
});

View File

@ -0,0 +1,10 @@
<ul class="nav nav-tabs">
<li><a href="#missing" class="x-missing-tab no-router">Missing</a></li>
<li><a href="#cutoff" class="x-cutoff-tab no-router">Cutoff Unmet</a></li>
</ul>
<div class="tab-pane" id="content"></div>
<!--<div class="tab-content">
<div class="tab-pane" id="missing"></div>
<div class="tab-pane" id="cutoff"></div>
</div>-->