use clone so that we only detect empty collection

when collectio is empty.. not when current filter is empty but collectionis not
pull/990/head
geogolem 8 years ago
parent 8c656626d6
commit d8d60c6bb0

@ -1,476 +1,481 @@
var _ = require('underscore'); var _ = require('underscore');
var Marionette = require('marionette'); var Marionette = require('marionette');
var Backgrid = require('backgrid'); var Backgrid = require('backgrid');
var PosterCollectionView = require('./Posters/SeriesPostersCollectionView'); var PosterCollectionView = require('./Posters/SeriesPostersCollectionView');
var ListCollectionView = require('./Overview/SeriesOverviewCollectionView'); var ListCollectionView = require('./Overview/SeriesOverviewCollectionView');
var EmptyView = require('./EmptyView'); var EmptyView = require('./EmptyView');
var MoviesCollection = require('../MoviesCollection'); var MoviesCollection = require('../MoviesCollection');
var FullMovieCollection = require('../FullMovieCollection'); var FullMovieCollection = require('../FullMovieCollection');
var InCinemasCell = require('../../Cells/InCinemasCell'); var InCinemasCell = require('../../Cells/InCinemasCell');
var RelativeDateCell = require('../../Cells/RelativeDateCell'); var RelativeDateCell = require('../../Cells/RelativeDateCell');
var MovieTitleCell = require('../../Cells/MovieTitleCell'); var MovieTitleCell = require('../../Cells/MovieTitleCell');
var TemplatedCell = require('../../Cells/TemplatedCell'); var TemplatedCell = require('../../Cells/TemplatedCell');
var ProfileCell = require('../../Cells/ProfileCell'); var ProfileCell = require('../../Cells/ProfileCell');
var MovieLinksCell = require('../../Cells/MovieLinksCell'); var MovieLinksCell = require('../../Cells/MovieLinksCell');
var MovieActionCell = require('../../Cells/MovieActionCell'); var MovieActionCell = require('../../Cells/MovieActionCell');
var MovieStatusCell = require('../../Cells/MovieStatusCell'); var MovieStatusCell = require('../../Cells/MovieStatusCell');
var MovieDownloadStatusCell = require('../../Cells/MovieDownloadStatusCell'); var MovieDownloadStatusCell = require('../../Cells/MovieDownloadStatusCell');
var DownloadedQualityCell = require('../../Cells/DownloadedQualityCell'); var DownloadedQualityCell = require('../../Cells/DownloadedQualityCell');
var FooterView = require('./FooterView'); var FooterView = require('./FooterView');
var GridPager = require('../../Shared/Grid/Pager'); var GridPager = require('../../Shared/Grid/Pager');
var FooterModel = require('./FooterModel'); var FooterModel = require('./FooterModel');
var ToolbarLayout = require('../../Shared/Toolbar/ToolbarLayout'); var ToolbarLayout = require('../../Shared/Toolbar/ToolbarLayout');
require('../../Mixins/backbone.signalr.mixin'); require('../../Mixins/backbone.signalr.mixin');
//var MoviesCollectionClient = require('../MoviesCollectionClient'); //var MoviesCollectionClient = require('../MoviesCollectionClient');
//this variable prevents double fetching the FullMovieCollection on first load //this variable prevents double fetching the FullMovieCollection on first load
//var shownOnce = false; //var shownOnce = false;
//require('../Globals'); //require('../Globals');
window.shownOnce = false; window.shownOnce = false;
module.exports = Marionette.Layout.extend({ module.exports = Marionette.Layout.extend({
template : 'Movies/Index/MoviesIndexLayoutTemplate', template : 'Movies/Index/MoviesIndexLayoutTemplate',
regions : { regions : {
seriesRegion : '#x-series', seriesRegion : '#x-series',
toolbar : '#x-toolbar', toolbar : '#x-toolbar',
toolbar2 : '#x-toolbar2', toolbar2 : '#x-toolbar2',
footer : '#x-series-footer', footer : '#x-series-footer',
pager : "#x-movie-pager", pager : "#x-movie-pager",
pagerTop : "#x-movie-pager-top" pagerTop : "#x-movie-pager-top"
}, },
columns : [ columns : [
{ {
name : 'status', name : 'status',
label : '', label : '',
cell : MovieStatusCell cell : MovieStatusCell
}, },
{ {
name : 'title', name : 'title',
label : 'Title', label : 'Title',
cell : MovieTitleCell, cell : MovieTitleCell,
cellValue : 'this', cellValue : 'this',
}, },
{ {
name : 'added', name : 'added',
label : 'Date Added', label : 'Date Added',
cell : RelativeDateCell cell : RelativeDateCell
}, },
{ {
name : "downloadedQuality", name : "downloadedQuality",
label : "Downloaded", label : "Downloaded",
cell : DownloadedQualityCell, cell : DownloadedQualityCell,
sortable : true sortable : true
}, },
{ {
name : 'profileId', name : 'profileId',
label : 'Profile', label : 'Profile',
cell : ProfileCell cell : ProfileCell
}, },
{ {
name : 'inCinemas', name : 'inCinemas',
label : 'In Cinemas', label : 'In Cinemas',
cell : RelativeDateCell cell : RelativeDateCell
}, },
{ {
name : 'this', name : 'this',
label : 'Links', label : 'Links',
cell : MovieLinksCell, cell : MovieLinksCell,
className : "movie-links-cell", className : "movie-links-cell",
sortable : false, sortable : false,
}, },
{ {
name : "this", name : "this",
label : "Status", label : "Status",
cell : MovieDownloadStatusCell, cell : MovieDownloadStatusCell,
sortable : false, sortable : false,
sortValue : function(m, k) { sortValue : function(m, k) {
if (m.get("downloaded")) { if (m.get("downloaded")) {
return -1; return -1;
} }
return 0; return 0;
} }
}, },
{ {
name : 'this', name : 'this',
label : '', label : '',
sortable : false, sortable : false,
cell : MovieActionCell cell : MovieActionCell
} }
], ],
leftSideButtons : { leftSideButtons : {
type : 'default', type : 'default',
storeState : false, storeState : false,
collapse : true, collapse : true,
items : [ items : [
{ {
title : 'Add Movie', title : 'Add Movie',
icon : 'icon-sonarr-add', icon : 'icon-sonarr-add',
route : 'addmovies' route : 'addmovies'
}, },
{ {
title : 'Movie Editor', title : 'Movie Editor',
icon : 'icon-sonarr-edit', icon : 'icon-sonarr-edit',
route : 'movieeditor' route : 'movieeditor'
}, },
{ {
title : 'RSS Sync', title : 'RSS Sync',
icon : 'icon-sonarr-rss', icon : 'icon-sonarr-rss',
command : 'rsssync', command : 'rsssync',
errorMessage : 'RSS Sync Failed!' errorMessage : 'RSS Sync Failed!'
}, },
{ {
title : 'Update Library', title : 'Update Library',
icon : 'icon-sonarr-refresh', icon : 'icon-sonarr-refresh',
command : 'refreshmovie', command : 'refreshmovie',
successMessage : 'Library was updated!', successMessage : 'Library was updated!',
errorMessage : 'Library update failed!' errorMessage : 'Library update failed!'
} }
] ]
}, },
initialize : function() { initialize : function() {
//this variable prevents us from showing the list before seriesCollection has been fetched the first time //this variable prevents us from showing the list before seriesCollection has been fetched the first time
this.seriesCollection = MoviesCollection;//.clone(); this.seriesCollection = MoviesCollection.clone();
this.seriesCollection.bindSignalR(); this.seriesCollection.bindSignalR();
this.listenTo(FullMovieCollection, 'sync', function() {
this._showFooter(); //this.listenTo(MoviesCollection, 'sync', function() {
}); // this.seriesCollection.fetch();
//});
this.listenTo(this.seriesCollection, 'sync', function(model, collection, options) {
this._renderView(); this.listenTo(FullMovieCollection, 'sync', function() {
//MoviesCollectionClient.fetch(); this._showFooter();
}); });
this.listenTo(this.seriesCollection, "change", function(model) {
if (model.get('saved')) { this.listenTo(this.seriesCollection, 'sync', function(model, collection, options) {
model.set('saved', false); this._renderView();
this.seriesCollection.fetch(); //MoviesCollectionClient.fetch();
//FullMovieCollection.fetch({reset : true }); });
//this._showFooter(); this.listenTo(this.seriesCollection, "change", function(model) {
var m = FullMovieCollection.findWhere( { tmdbId : model.get('tmdbId') }); if (model.get('saved')) {
m.set('monitored', model.get('monitored')); model.set('saved', false);
m.set('minimumAvailability', model.get('minimumAvailability')); this.seriesCollection.fetch();
m.set( {profileId : model.get('profileId') } ); //FullMovieCollection.fetch({reset : true });
//this._showFooter();
this._showFooter(); var m = FullMovieCollection.findWhere( { tmdbId : model.get('tmdbId') });
} m.set('monitored', model.get('monitored'));
}); m.set('minimumAvailability', model.get('minimumAvailability'));
m.set( {profileId : model.get('profileId') } );
this.listenTo(this.seriesCollection, 'remove', function(model, collection, options) { this._showFooter();
if (model.get('deleted')) { }
this.seriesCollection.fetch(); //need to do this so that the page shows a full page and the 'total records' number is updated });
//FullMovieCollection.fetch({reset : true}); //need to do this to update the footer
FullMovieCollection.remove(model);
this._showFooter(); this.listenTo(this.seriesCollection, 'remove', function(model, collection, options) {
} if (model.get('deleted')) {
this.seriesCollection.fetch(); //need to do this so that the page shows a full page and the 'total records' number is updated
}); //FullMovieCollection.fetch({reset : true}); //need to do this to update the footer
FullMovieCollection.remove(model);
this.sortingOptions = { this._showFooter();
type : 'sorting', }
storeState : false,
viewCollection : this.seriesCollection, });
callback : this._sort,
items : [ this.sortingOptions = {
{ type : 'sorting',
title : 'Title', storeState : false,
name : 'title' viewCollection : this.seriesCollection,
}, callback : this._sort,
{ items : [
title: 'Downloaded', {
name: 'downloadedQuality' title : 'Title',
}, name : 'title'
{ },
title : 'Profile', {
name : 'profileId' title: 'Downloaded',
}, name: 'downloadedQuality'
{ },
title : 'In Cinemas', {
name : 'inCinemas' title : 'Profile',
}, name : 'profileId'
/*{ },
title : "Status", {
name : "status", title : 'In Cinemas',
}*/ name : 'inCinemas'
] },
}; /*{
title : "Status",
this.filteringOptions = { name : "status",
type : 'radio', }*/
storeState : true, ]
menuKey : 'series.filterMode', };
defaultAction : 'all',
items : [ this.filteringOptions = {
{ type : 'radio',
key : 'all', storeState : true,
title : '', menuKey : 'series.filterMode',
tooltip : 'All', defaultAction : 'all',
icon : 'icon-sonarr-all', items : [
callback : this._setFilter {
}, key : 'all',
{ title : '',
key : 'monitored', tooltip : 'All',
title : '', icon : 'icon-sonarr-all',
tooltip : 'Monitored Only', callback : this._setFilter
icon : 'icon-sonarr-monitored', },
callback : this._setFilter {
}, key : 'monitored',
{ title : '',
key : 'missing', tooltip : 'Monitored Only',
title : '', icon : 'icon-sonarr-monitored',
tooltip : 'Missing Only', callback : this._setFilter
icon : 'icon-sonarr-missing', },
callback : this._setFilter {
}, key : 'missing',
{ title : '',
key : 'released', tooltip : 'Missing Only',
title : '', icon : 'icon-sonarr-missing',
tooltip : 'Released', callback : this._setFilter
icon : 'icon-sonarr-movie-released', },
callback : this._setFilter {
}, key : 'released',
{ title : '',
key : 'announced', tooltip : 'Released',
title : '', icon : 'icon-sonarr-movie-released',
tooltip : 'Announced', callback : this._setFilter
icon : 'icon-sonarr-movie-announced', },
callback : this._setFilter {
}, key : 'announced',
{ title : '',
key : 'cinemas', tooltip : 'Announced',
title : '', icon : 'icon-sonarr-movie-announced',
tooltip : 'In Cinemas', callback : this._setFilter
icon : 'icon-sonarr-movie-cinemas', },
callback : this._setFilter {
} key : 'cinemas',
] title : '',
}; tooltip : 'In Cinemas',
icon : 'icon-sonarr-movie-cinemas',
this.viewButtons = { callback : this._setFilter
type : 'radio', }
storeState : true, ]
menuKey : 'seriesViewMode', };
defaultAction : 'listView',
items : [ this.viewButtons = {
{ type : 'radio',
key : 'posterView', storeState : true,
title : '', menuKey : 'seriesViewMode',
tooltip : 'Posters', defaultAction : 'listView',
icon : 'icon-sonarr-view-poster', items : [
callback : this._showPosters {
}, key : 'posterView',
{ title : '',
key : 'listView', tooltip : 'Posters',
title : '', icon : 'icon-sonarr-view-poster',
tooltip : 'Overview List', callback : this._showPosters
icon : 'icon-sonarr-view-list', },
callback : this._showList {
}, key : 'listView',
{ title : '',
key : 'tableView', tooltip : 'Overview List',
title : '', icon : 'icon-sonarr-view-list',
tooltip : 'Table', callback : this._showList
icon : 'icon-sonarr-view-table', },
callback : this._showTable {
} key : 'tableView',
] title : '',
}; tooltip : 'Table',
}, icon : 'icon-sonarr-view-table',
callback : this._showTable
onShow : function() { }
this._showToolbar(); ]
this._fetchCollection(); };
if (window.shownOnce) { },
this._showFooter();
} onShow : function() {
window.shownOnce = true; this._showToolbar();
}, this._fetchCollection();
if (window.shownOnce) {
_showTable : function() { this._showFooter();
this.currentView = new Backgrid.Grid({ }
collection : this.seriesCollection, window.shownOnce = true;
columns : this.columns, },
className : 'table table-hover'
}); _showTable : function() {
this.currentView = new Backgrid.Grid({
this._showPager(); collection : this.seriesCollection,
this._renderView(); columns : this.columns,
}, className : 'table table-hover'
});
_showList : function() {
//this.current = "list"; this._showPager();
this.currentView = new ListCollectionView({ this._renderView();
collection : this.seriesCollection },
});
_showList : function() {
this._renderView(); //this.current = "list";
}, this.currentView = new ListCollectionView({
collection : this.seriesCollection
_showPosters : function() { });
this.currentView = new PosterCollectionView({
collection : this.seriesCollection this._renderView();
}); },
this._renderView(); _showPosters : function() {
}, this.currentView = new PosterCollectionView({
collection : this.seriesCollection
_sort : function() { });
console.warn("Sorting");
}, this._renderView();
},
_renderView : function() {
if (MoviesCollection.length === 0) { _sort : function() {
this.seriesRegion.show(new EmptyView()); console.warn("Sorting");
},
this.toolbar.close();
this.toolbar2.close(); _renderView : function() {
} else { if (MoviesCollection.length === 0) {
this.renderedOnce = true; this.seriesRegion.show(new EmptyView());
this.seriesRegion.show(this.currentView);
this.listenTo(this.currentView.collection, 'sync', function(eventName){ this.toolbar.close();
this._showPager(); this.toolbar2.close();
}); } else {
this._showToolbar(); this.renderedOnce = true;
} this.seriesRegion.show(this.currentView);
}, this.listenTo(this.currentView.collection, 'sync', function(eventName){
this._showPager();
_fetchCollection : function() { });
this.seriesCollection.fetch(); this._showToolbar();
}, }
},
_setFilter : function(buttonContext) {
var mode = buttonContext.model.get('key'); _fetchCollection : function() {
this.seriesCollection.setFilterMode(mode); this.seriesCollection.fetch();
}, },
_showToolbar : function() { _setFilter : function(buttonContext) {
if (this.toolbar.currentView) { var mode = buttonContext.model.get('key');
return; this.seriesCollection.setFilterMode(mode);
} },
this.toolbar2.show(new ToolbarLayout({ _showToolbar : function() {
right : [ if (this.toolbar.currentView) {
this.filteringOptions return;
], }
context : this
})); this.toolbar2.show(new ToolbarLayout({
right : [
this.toolbar.show(new ToolbarLayout({ this.filteringOptions
right : [ ],
this.sortingOptions, context : this
this.viewButtons }));
],
left : [ this.toolbar.show(new ToolbarLayout({
this.leftSideButtons right : [
], this.sortingOptions,
context : this this.viewButtons
})); ],
}, left : [
this.leftSideButtons
_showPager : function() { ],
var pager = new GridPager({ context : this
columns : this.columns, }));
collection : this.seriesCollection, },
});
var pagerTop = new GridPager({ _showPager : function() {
columns : this.columns, var pager = new GridPager({
collection : this.seriesCollection, columns : this.columns,
}); collection : this.seriesCollection,
this.pager.show(pager); });
this.pagerTop.show(pagerTop); var pagerTop = new GridPager({
}, columns : this.columns,
collection : this.seriesCollection,
_showFooter : function() { });
var footerModel = new FooterModel(); this.pager.show(pager);
var movies = FullMovieCollection.models.length; this.pagerTop.show(pagerTop);
//instead of all the counters could do something like this with different query in the where... },
//var releasedMovies = FullMovieCollection.where({ 'released' : this.model.get('released') });
// releasedMovies.length _showFooter : function() {
var footerModel = new FooterModel();
var announced = 0; var movies = FullMovieCollection.models.length;
var incinemas = 0; //instead of all the counters could do something like this with different query in the where...
var released = 0; //var releasedMovies = FullMovieCollection.where({ 'released' : this.model.get('released') });
// releasedMovies.length
var monitored = 0;
var announced = 0;
var downloaded =0; var incinemas = 0;
var missingMonitored=0; var released = 0;
var missingNotMonitored=0;
var missingMonitoredNotAvailable=0; var monitored = 0;
var missingMonitoredAvailable=0;
var downloaded =0;
var downloadedMonitored=0; var missingMonitored=0;
var downloadedNotMonitored=0; var missingNotMonitored=0;
var missingMonitoredNotAvailable=0;
_.each(FullMovieCollection.models, function(model) { var missingMonitoredAvailable=0;
if (model.get('status').toLowerCase() === 'released') { var downloadedMonitored=0;
released++; var downloadedNotMonitored=0;
}
else if (model.get('status').toLowerCase() === 'incinemas') { _.each(FullMovieCollection.models, function(model) {
incinemas++;
} if (model.get('status').toLowerCase() === 'released') {
else if (model.get('status').toLowerCase() === 'announced') { released++;
announced++; }
} else if (model.get('status').toLowerCase() === 'incinemas') {
incinemas++;
if (model.get('monitored')) { }
monitored++; else if (model.get('status').toLowerCase() === 'announced') {
if (model.get('downloaded')) { announced++;
downloadedMonitored++; }
}
} if (model.get('monitored')) {
else { //not monitored monitored++;
if (model.get('downloaded')) { if (model.get('downloaded')) {
downloadedNotMonitored++; downloadedMonitored++;
} }
else { //missing }
missingNotMonitored++; else { //not monitored
} if (model.get('downloaded')) {
} downloadedNotMonitored++;
}
if (model.get('downloaded')) { else { //missing
downloaded++; missingNotMonitored++;
} }
else { //missing }
if (!model.get('isAvailable')) {
if (model.get('monitored')) { if (model.get('downloaded')) {
missingMonitoredNotAvailable++; downloaded++;
} }
} else { //missing
if (!model.get('isAvailable')) {
if (model.get('monitored')) { if (model.get('monitored')) {
missingMonitored++; missingMonitoredNotAvailable++;
if (model.get('isAvailable')) { }
missingMonitoredAvailable++; }
}
} if (model.get('monitored')) {
} missingMonitored++;
}); if (model.get('isAvailable')) {
missingMonitoredAvailable++;
footerModel.set({ }
movies : movies, }
announced : announced, }
incinemas : incinemas, });
released : released,
monitored : monitored, footerModel.set({
downloaded : downloaded, movies : movies,
downloadedMonitored : downloadedMonitored, announced : announced,
downloadedNotMonitored : downloadedNotMonitored, incinemas : incinemas,
missingMonitored : missingMonitored, released : released,
missingMonitoredAvailable : missingMonitoredAvailable, monitored : monitored,
missingMonitoredNotAvailable : missingMonitoredNotAvailable, downloaded : downloaded,
missingNotMonitored : missingNotMonitored downloadedMonitored : downloadedMonitored,
}); downloadedNotMonitored : downloadedNotMonitored,
missingMonitored : missingMonitored,
this.footer.show(new FooterView({ model : footerModel })); missingMonitoredAvailable : missingMonitoredAvailable,
} missingMonitoredNotAvailable : missingMonitoredNotAvailable,
}); missingNotMonitored : missingNotMonitored
});
this.footer.show(new FooterView({ model : footerModel }));
}
});

Loading…
Cancel
Save