From c1a5e8e7593a96fdf66b1a1fe1b95bfd5c91456f Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Fri, 16 Feb 2018 17:12:34 +0100 Subject: [PATCH] Fixed: Filters not working. Fuck you backbone. --- src/UI/Series/SeriesCollection.js | 120 ++++++++++++++++++++++++++++++ src/UI/Series/SeriesModel.js | 31 ++++++++ src/UI/main.js | 3 + 3 files changed, 154 insertions(+) create mode 100644 src/UI/Series/SeriesCollection.js create mode 100644 src/UI/Series/SeriesModel.js diff --git a/src/UI/Series/SeriesCollection.js b/src/UI/Series/SeriesCollection.js new file mode 100644 index 000000000..3d7914864 --- /dev/null +++ b/src/UI/Series/SeriesCollection.js @@ -0,0 +1,120 @@ +var _ = require('underscore'); +var Backbone = require('backbone'); +var PageableCollection = require('backbone.pageable'); +var SeriesModel = require('./SeriesModel'); +var ApiData = require('../Shared/ApiData'); +var AsFilteredCollection = require('../Mixins/AsFilteredCollection'); +var AsSortedCollection = require('../Mixins/AsSortedCollection'); +var AsPersistedStateCollection = require('../Mixins/AsPersistedStateCollection'); +var moment = require('moment'); +require('../Mixins/backbone.signalr.mixin'); + +var Collection = PageableCollection.extend({ + url : window.NzbDrone.ApiRoot + '/series', + model : SeriesModel, + tableName : 'series', + + state : { + sortKey : 'sortTitle', + order : -1, + pageSize : 100000, + secondarySortKey : 'sortTitle', + secondarySortOrder : -1 + }, + + mode : 'client', + + save : function() { + var self = this; + + var proxy = _.extend(new Backbone.Model(), { + id : '', + + url : self.url + '/editor', + + toJSON : function() { + return self.filter(function(model) { + return model.edited; + }); + } + }); + + this.listenTo(proxy, 'sync', function(proxyModel, models) { + this.add(models, { merge : true }); + this.trigger('save', this); + }); + + return proxy.save(); + }, + + filterModes : { + 'all' : [ + null, + null + ], + 'continuing' : [ + 'status', + 'continuing' + ], + 'ended' : [ + 'status', + 'ended' + ], + 'monitored' : [ + 'monitored', + true + ], + 'missing' : [ + null, + null, + function(model) { return model.get('episodeCount') !== model.get('episodeFileCount'); } + ] + }, + + sortMappings : { + title : { + sortKey : 'sortTitle' + }, + + nextAiring : { + sortValue : function(model, attr, order) { + var nextAiring = model.get(attr); + + if (nextAiring) { + return moment(nextAiring).unix(); + } + + if (order === 1) { + return 0; + } + + return Number.MAX_VALUE; + } + }, + + percentOfEpisodes : { + sortValue : function(model, attr) { + var percentOfEpisodes = model.get(attr); + var episodeCount = model.get('episodeCount'); + + return percentOfEpisodes + episodeCount / 1000000; + } + }, + + path : { + sortValue : function(model) { + var path = model.get('path'); + + return path.toLowerCase(); + } + } + } +}); + +Collection = AsFilteredCollection.call(Collection); +Collection = AsSortedCollection.call(Collection); +Collection = AsPersistedStateCollection.call(Collection); + +var data = ApiData.get('series'); + +module.exports = new Collection(data, { full : true }).bindSignalR(); \ No newline at end of file diff --git a/src/UI/Series/SeriesModel.js b/src/UI/Series/SeriesModel.js new file mode 100644 index 000000000..2deda4584 --- /dev/null +++ b/src/UI/Series/SeriesModel.js @@ -0,0 +1,31 @@ +var Backbone = require('backbone'); +var _ = require('underscore'); + +module.exports = Backbone.Model.extend({ + urlRoot : window.NzbDrone.ApiRoot + '/series', + + defaults : { + episodeFileCount : 0, + episodeCount : 0, + isExisting : false, + status : 0 + }, + + setSeasonMonitored : function(seasonNumber) { + _.each(this.get('seasons'), function(season) { + if (season.seasonNumber === seasonNumber) { + season.monitored = !season.monitored; + } + }); + }, + + setSeasonPass : function(seasonNumber) { + _.each(this.get('seasons'), function(season) { + if (season.seasonNumber >= seasonNumber) { + season.monitored = true; + } else { + season.monitored = false; + } + }); + } +}); \ No newline at end of file diff --git a/src/UI/main.js b/src/UI/main.js index 88fa53c1b..6ba99f38d 100644 --- a/src/UI/main.js +++ b/src/UI/main.js @@ -12,6 +12,8 @@ var ControlPanelController = require('./Shared/ControlPanel/ControlPanelControll var ServerStatusModel = require('./System/StatusModel'); var Tooltip = require('./Shared/Tooltip'); var UiSettingsController = require('./Shared/UiSettingsController'); +//We need this for filters to work, fuck you backbone. +var SeriesCollection = require('./Series/SeriesCollection'); require('./jQuery/ToTheTop'); require('./Instrumentation/StringFormat'); @@ -21,6 +23,7 @@ require('./Shared/piwikCheck'); require('./Shared/VersionChangeMonitor'); new MoviesController(); +//new SeriesCollection(); new ModalController(); new ControlPanelController(); new Router();