diff --git a/src/UI/Cells/DownloadedQualityCell.js b/src/UI/Cells/DownloadedQualityCell.js new file mode 100644 index 000000000..0cf40c21c --- /dev/null +++ b/src/UI/Cells/DownloadedQualityCell.js @@ -0,0 +1,34 @@ +var Backgrid = require('backgrid'); +var ProfileCollection = require('../Profile/ProfileCollection'); +var _ = require('underscore'); + +module.exports = Backgrid.Cell.extend({ + className : 'profile-cell', + + _originalInit : Backgrid.Cell.prototype.initialize, + + initialize : function () { + this._originalInit.apply(this, arguments); + + this.listenTo(ProfileCollection, 'sync', this.render); + }, + + render : function() { + + this.$el.empty(); + if (this.model.get("movieFile")) { + var profileId = this.model.get("movieFile").quality.quality.id; + + var profile = _.findWhere(ProfileCollection.models, { id : profileId }); + + if (profile) { + this.$el.html(profile.get('name')); + } else { + this.$el.html(this.model.get("movieFile").quality.quality.name); + } + } + + + return this; + } +}); diff --git a/src/UI/Cells/MovieDownloadStatusCell.js b/src/UI/Cells/MovieDownloadStatusCell.js index ba35657b4..7cb154374 100644 --- a/src/UI/Cells/MovieDownloadStatusCell.js +++ b/src/UI/Cells/MovieDownloadStatusCell.js @@ -3,4 +3,8 @@ var TemplatedCell = require('./TemplatedCell'); module.exports = TemplatedCell.extend({ className : 'movie-title-cell', template : 'Cells/MovieDownloadStatusTemplate', + sortKey : function(model) { + debugger; + return 0; + } }); diff --git a/src/UI/Movies/Index/MoviesIndexLayout.js b/src/UI/Movies/Index/MoviesIndexLayout.js index 3b12a36e0..a4db4c892 100644 --- a/src/UI/Movies/Index/MoviesIndexLayout.js +++ b/src/UI/Movies/Index/MoviesIndexLayout.js @@ -13,6 +13,7 @@ var MovieLinksCell = require('../../Cells/MovieLinksCell'); var MovieActionCell = require('../../Cells/MovieActionCell'); var MovieStatusCell = require('../../Cells/MovieStatusCell'); var MovieDownloadStatusCell = require('../../Cells/MovieDownloadStatusCell'); +var DownloadedQualityCell = require('../../Cells/DownloadedQualityCell'); var FooterView = require('./FooterView'); var FooterModel = require('./FooterModel'); var ToolbarLayout = require('../../Shared/Toolbar/ToolbarLayout'); @@ -40,6 +41,11 @@ module.exports = Marionette.Layout.extend({ cell : MovieTitleCell, cellValue : 'this', }, + { + name : "downloadedQuality", + label : "Downloaded", + cell : DownloadedQualityCell, + }, { name : 'profileId', label : 'Profile', @@ -54,12 +60,19 @@ module.exports = Marionette.Layout.extend({ name : 'this', label : 'Links', cell : MovieLinksCell, - className : "movie-links-cell" + className : "movie-links-cell", + sortable : false, }, { name : "this", label : "Status", cell : MovieDownloadStatusCell, + sortValue : function(m, k) { + if (m.get("downloaded")) { + return -1; + } + return 0; + } }, { name : 'this', diff --git a/src/UI/Movies/MovieModel.js b/src/UI/Movies/MovieModel.js index a3e0d5a35..5c8538271 100644 --- a/src/UI/Movies/MovieModel.js +++ b/src/UI/Movies/MovieModel.js @@ -9,5 +9,31 @@ module.exports = Backbone.Model.extend({ episodeCount : 0, isExisting : false, status : 0 + }, + + getStatus : function() { + var monitored = this.get("monitored"); + var status = this.get("status"); + var inCinemas = this.get("inCinemas"); + var date = new Date(inCinemas); + var timeSince = new Date().getTime() - date.getTime(); + var numOfMonths = timeSince / 1000 / 60 / 60 / 24 / 30; + + if (status === "announced") { + return "announced" + } + + if (numOfMonths < 3 && numOfMonths > 0) { + + return "inCinemas"; + } + + if (status === 'released') { + return "released"; + } + + if (numOfMonths > 3) { + return "released";//TODO: Update for PreDB.me + } } }); diff --git a/src/UI/Movies/MoviesCollection.js b/src/UI/Movies/MoviesCollection.js index bc97e360d..594305ba0 100644 --- a/src/UI/Movies/MoviesCollection.js +++ b/src/UI/Movies/MoviesCollection.js @@ -75,7 +75,26 @@ var Collection = PageableCollection.extend({ title : { sortKey : 'sortTitle' }, + statusWeight : { + sortValue : function(model, attr) { + if (model.getStatus() == "released") { + return 1; + } + if (model.getStatus() == "inCinemas") { + return 0; + } + return -1; + } + }, + downloadedQuality : { + sortValue : function(model, attr) { + if (model.get("movieFile")) { + return 1000-model.get("movieFile").quality.quality.id; + } + return -1; + } + }, nextAiring : { sortValue : function(model, attr, order) { var nextAiring = model.get(attr); @@ -91,7 +110,15 @@ var Collection = PageableCollection.extend({ return Number.MAX_VALUE; } }, - + status: { + sortValue : function(model, attr) { + debugger; + if (model.get("downloaded")) { + return -1; + } + return 0; + } + }, percentOfEpisodes : { sortValue : function(model, attr) { var percentOfEpisodes = model.get(attr);