From f3e601d4edb3eddc2efc3508386a3037fbab17b1 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 26 Jan 2013 19:04:15 -0800 Subject: [PATCH] added quality profile support to add series. --- NzbDrone.Web/NzbDrone.Web.csproj | 4 ++ .../AddNewSeries/AddNewSeriesView.js | 14 ++++-- .../AddNewSeries/SearchResultTemplate.html | 9 ++-- .../AddNewSeries/SearchResultView.js | 2 + .../_backboneApp/AddSeries/AddSeriesLayout.js | 8 +++- .../AddSeries/RootDir/RootDirCollection.js | 3 +- .../AddSeries/SearchResultCollection.js | 2 +- .../AddSeries/SearchResultModel.js | 8 ++++ .../Quality/qualityProfileCollection.js | 7 +++ .../Quality/qualityProfileModel.js | 47 +++++++++++++++++++ .../Quality/qualityTypeCollection.js | 4 ++ .../_backboneApp/Quality/qualityTypeModel.js | 34 ++++++++++++++ NzbDrone.Web/_backboneApp/Shared/ErrorView.js | 2 +- NzbDrone.Web/_backboneApp/app.js | 3 +- 14 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 NzbDrone.Web/_backboneApp/Quality/qualityProfileCollection.js create mode 100644 NzbDrone.Web/_backboneApp/Quality/qualityProfileModel.js create mode 100644 NzbDrone.Web/_backboneApp/Quality/qualityTypeCollection.js create mode 100644 NzbDrone.Web/_backboneApp/Quality/qualityTypeModel.js diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 2a1c25128..6c965456c 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -195,6 +195,10 @@ + + + + diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/AddNewSeriesView.js b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/AddNewSeriesView.js index df668b338..9344a699f 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/AddNewSeriesView.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/AddNewSeriesView.js @@ -15,12 +15,17 @@ NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.Layout.extend({ collection: new NzbDrone.AddSeries.SearchResultCollection(), - initialize: function (rootFolders) { - if (rootFolders === undefined) { + initialize: function (options) { + if (options.rootFolders === undefined) { throw "rootFolder arg is required."; } - this.rootFoldersCollection = rootFolders; + if (options.qualityProfiles === undefined) { + throw "qualityProfiles arg is required."; + } + + this.rootFoldersCollection = options.rootFolders; + this.qualityProfilesCollection = options.qualityProfiles; }, onRender: function () { @@ -61,7 +66,8 @@ NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.Layout.extend({ resultUpdated: function (options, context) { _.each(options.models, function (model) { - model.set('rootFolders', context.rootFoldersCollection.rootFolders.models); + model.set('rootFolders', context.rootFoldersCollection.models); + model.set('qualityProfiles', context.qualityProfilesCollection.models); }); context.searchResult.show(context.resultView); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultTemplate.html b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultTemplate.html index a50cfd853..05f0a3f7c 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultTemplate.html +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultTemplate.html @@ -4,16 +4,15 @@
- {{#each rootFolders}} {{/each}}
diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultView.js b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultView.js index 796cc235e..413ab5272 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultView.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultView.js @@ -8,6 +8,8 @@ NzbDrone.AddSeries.SearchItemView = Backbone.Marionette.ItemView.extend({ className: 'search-item accordion-group', onRender: function () { this.listenTo(this.model, 'change', this.render); + //this.listenTo(this.model.get('rootFolders'), 'reset', this.render); + //this.listenTo(this.model.get('qualityProfiles'), 'reset', this.render); } }); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js b/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js index cff69b2a6..6b61b3c9d 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js @@ -1,6 +1,7 @@ /// /// /// +/// /// NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ @@ -21,6 +22,7 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ rootFolderCollection: new NzbDrone.AddSeries.RootDirCollection(), + qualityProfileCollection: new NzbDrone.Quality.QualityProfileCollection(), onRender: function () { this.$('#myTab a').click(function (e) { @@ -28,7 +30,9 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ $(this).tab('show'); }); - this.addNew.show(new NzbDrone.AddSeries.AddNewSeriesView({ rootFolders: this.rootFolderCollection })); + this.qualityProfileCollection.fetch(); + + this.addNew.show(new NzbDrone.AddSeries.AddNewSeriesView({ rootFolders: this.rootFolderCollection, qualityProfiles: this.qualityProfileCollection })); //this.importExisting.show(new NzbDrone.ImportExistingView()); this.rootFolders.show(new NzbDrone.AddSeries.RootDirView({ collection: this.rootFolderCollection })); @@ -36,7 +40,7 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ NzbDrone.vent.listenTo(this.rootFolderCollection, 'remove', this.evaluateActions, this); NzbDrone.vent.listenTo(this.rootFolderCollection, 'reset', this.evaluateActions, this); }, - + evaluateActions: function () { if (this.rootFolderCollection.length == 0) { this.ui.addNewTab.hide(); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirCollection.js b/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirCollection.js index 57dc6fa27..9bf78f728 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirCollection.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirCollection.js @@ -1,7 +1,8 @@ /// +/// NzbDrone.AddSeries.RootDirCollection = Backbone.Collection.extend({ - url: NzbDrone.Constants.ApiRoot + 'rootdir/', + url: NzbDrone.Constants.ApiRoot + '/rootdir', model: NzbDrone.AddSeries.RootDirModel, }); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/SearchResultCollection.js b/NzbDrone.Web/_backboneApp/AddSeries/SearchResultCollection.js index c69890fff..44ff85732 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/SearchResultCollection.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/SearchResultCollection.js @@ -2,7 +2,7 @@ /// NzbDrone.AddSeries.SearchResultCollection = Backbone.Collection.extend({ - url: NzbDrone.Constants.ApiRoot + 'series/lookup', + url: NzbDrone.Constants.ApiRoot + '/series/lookup', model: NzbDrone.AddSeries.SearchResultModel, }); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/SearchResultModel.js b/NzbDrone.Web/_backboneApp/AddSeries/SearchResultModel.js index 88ddd1747..139e879d6 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/SearchResultModel.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/SearchResultModel.js @@ -1,4 +1,6 @@ /// +/// +/// NzbDrone.AddSeries.SearchResultModel = Backbone.Model.extend({ mutators: { seriesYear: function () { @@ -11,5 +13,11 @@ NzbDrone.AddSeries.SearchResultModel = Backbone.Model.extend({ return date; } } + }, + + defaults: { + qualityProfiles: new NzbDrone.Quality.QualityProfileCollection(), + rootFolders: new NzbDrone.AddSeries.RootDirCollection() } + }); diff --git a/NzbDrone.Web/_backboneApp/Quality/qualityProfileCollection.js b/NzbDrone.Web/_backboneApp/Quality/qualityProfileCollection.js new file mode 100644 index 000000000..446b08cb0 --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Quality/qualityProfileCollection.js @@ -0,0 +1,7 @@ +/// +/// + +NzbDrone.Quality.QualityProfileCollection = Backbone.Collection.extend({ + model: NzbDrone.Quality.QualityProfileModel, + url: NzbDrone.Constants.ApiRoot + '/qualityprofiles' +}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Quality/qualityProfileModel.js b/NzbDrone.Web/_backboneApp/Quality/qualityProfileModel.js new file mode 100644 index 000000000..9db408c1f --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Quality/qualityProfileModel.js @@ -0,0 +1,47 @@ +/// + +NzbDrone.Quality.QualityProfileModel = Backbone.Model.extend({ + initialize: function () { + this.validators = {}; + + this.validators.name = function (value) { + return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must enter a name' }; + }; + + //this.validators.allowed = function (value) { + // return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must have allowed qualities' }; + //}; + //Todo: Cutoff should be something that is allowed (double check) + this.validators.cutoff = function (value) { + return value != null ? { isValid: true } : { isValid: false, message: 'You must have a valid cutoff' }; + }; + }, + + validateItem: function (key) { + return (this.validators[key]) ? this.validators[key](this.get(key)) : { isValid: true }; + }, + + // TODO: Implement Backbone's standard validate() method instead. + validateAll: function () { + + var messages = {}; + + for (var key in this.validators) { + if (this.validators.hasOwnProperty(key)) { + var check = this.validators[key](this.get(key)); + if (check.isValid === false) { + messages[key] = check.message; + } + } + } + + return _.size(messages) > 0 ? { isValid: false, messages: messages } : { isValid: true }; + }, + + defaults: { + Id: null, + Name: '', + //allowed: {}, + Cutoff: null + } +}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Quality/qualityTypeCollection.js b/NzbDrone.Web/_backboneApp/Quality/qualityTypeCollection.js new file mode 100644 index 000000000..500cbdc0c --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Quality/qualityTypeCollection.js @@ -0,0 +1,4 @@ +NzbDrone.Quality.QualityTypeCollection = Backbone.Collection.extend({ + model: NzbDrone.Quality.QualityTypeModel, + url: NzbDrone.Constants.ApiRoot + '/qualitytypes' +}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Quality/qualityTypeModel.js b/NzbDrone.Web/_backboneApp/Quality/qualityTypeModel.js new file mode 100644 index 000000000..92d2d7a4b --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Quality/qualityTypeModel.js @@ -0,0 +1,34 @@ +NzbDrone.Quality.QualityTypeModel = Backbone.Model.extend({ + + initialize: function () { + this.validators = {}; + }, + + validateItem: function (key) { + return (this.validators[key]) ? this.validators[key](this.get(key)) : { isValid: true }; + }, + + // TODO: Implement Backbone's standard validate() method instead. + validateAll: function () { + + var messages = {}; + + for (var key in this.validators) { + if (this.validators.hasOwnProperty(key)) { + var check = this.validators[key](this.get(key)); + if (check.isValid === false) { + messages[key] = check.message; + } + } + } + + return _.size(messages) > 0 ? { isValid: false, messages: messages } : { isValid: true }; + }, + + defaults: { + Id: null, + Name: '', + MaxSize: 100, + MinSize: 0 + } +}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Shared/ErrorView.js b/NzbDrone.Web/_backboneApp/Shared/ErrorView.js index e147cf517..c61dedb1d 100644 --- a/NzbDrone.Web/_backboneApp/Shared/ErrorView.js +++ b/NzbDrone.Web/_backboneApp/Shared/ErrorView.js @@ -57,7 +57,7 @@ $(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) { var errorView = NzbDrone.Shared.ErrorView.instance; var model = new NzbDrone.Shared.ErrorModel(); - model.set('title', ajaxOptions.url + " : " + xmlHttpRequest.statusText); + model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText); model.set('message', xmlHttpRequest.responseText); errorView.collection.add(model); diff --git a/NzbDrone.Web/_backboneApp/app.js b/NzbDrone.Web/_backboneApp/app.js index f8790cd3c..8adb53e9c 100644 --- a/NzbDrone.Web/_backboneApp/app.js +++ b/NzbDrone.Web/_backboneApp/app.js @@ -19,6 +19,7 @@ if (typeof console == "undefined") { NzbDrone = new Backbone.Marionette.Application(); NzbDrone.AddSeries = NzbDrone.module("AddSeries"); +NzbDrone.Quality = NzbDrone.module("Quality"); NzbDrone.Shared = NzbDrone.module("Shared"); /* @@ -31,7 +32,7 @@ NzbDrone.ModelBinder = new Backbone.ModelBinder(); NzbDrone.Constants = { - ApiRoot: '/api/' + ApiRoot: '/api' }; NzbDrone.Events = {