From e4e6bcae1d04a5cb50be1bad7359d9e32ec49b1b Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 27 May 2013 22:40:58 -0700 Subject: [PATCH] last used quality profile is now used as default --- NzbDrone.Api/Series/SeriesModule.cs | 1 - NzbDrone.Core/Configuration/ConfigService.cs | 7 ----- NzbDrone.Core/Configuration/IConfigService.cs | 1 - NzbDrone.Core/Tv/SeriesService.cs | 7 +---- UI/AddSeries/AddSeriesLayout.js | 4 +-- UI/AddSeries/Existing/ImportSeriesView.js | 3 -- UI/AddSeries/Existing/UnmappedFolderModel.js | 7 +---- .../RootFolderSelectionTemplate.html | 1 - UI/AddSeries/SearchResultTemplate.html | 10 +++--- UI/AddSeries/SearchResultView.js | 31 +++++++++++++++++-- UI/Config.js | 19 +++++++++++- .../QualityProfileSelectionTemplate.html | 5 +++ UI/Quality/QualityProfileTemplateHelper.js | 10 ++++++ UI/Settings/Quality/QualityLayout.js | 2 -- UI/Settings/Quality/QualityTemplate.html | 14 --------- UI/Settings/Quality/QualityView.js | 14 --------- 16 files changed, 70 insertions(+), 66 deletions(-) create mode 100644 UI/Quality/QualityProfileSelectionTemplate.html create mode 100644 UI/Quality/QualityProfileTemplateHelper.js delete mode 100644 UI/Settings/Quality/QualityTemplate.html delete mode 100644 UI/Settings/Quality/QualityView.js diff --git a/NzbDrone.Api/Series/SeriesModule.cs b/NzbDrone.Api/Series/SeriesModule.cs index a2ef639f0..c650b9e2b 100644 --- a/NzbDrone.Api/Series/SeriesModule.cs +++ b/NzbDrone.Api/Series/SeriesModule.cs @@ -30,7 +30,6 @@ namespace NzbDrone.Api.Series Get["/{slug}"] = o => GetSeries((string)o.slug.ToString()); SharedValidator.RuleFor(s => s.QualityProfileId).ValidId(); - SharedValidator.RuleFor(s => s.Path).NotEmpty().When(s => String.IsNullOrEmpty(s.RootFolderPath)); SharedValidator.RuleFor(s => s.RootFolderPath).NotEmpty().When(s => String.IsNullOrEmpty(s.Path)); diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index 0f3a55e3e..1cdc7ea9e 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -136,13 +136,6 @@ namespace NzbDrone.Core.Configuration set { SetValue("Sorting_SeasonFolderFormat", value); } } - public int DefaultQualityProfile - { - get { return GetValueInt("DefaultQualityProfile", 1); } - - set { SetValue("DefaultQualityProfile", value); } - } - public string UpdateUrl { get { return GetValue("UpdateUrl", "http://update.nzbdrone.com/vnext/"); } diff --git a/NzbDrone.Core/Configuration/IConfigService.cs b/NzbDrone.Core/Configuration/IConfigService.cs index bf51b3da0..6359f2b1e 100644 --- a/NzbDrone.Core/Configuration/IConfigService.cs +++ b/NzbDrone.Core/Configuration/IConfigService.cs @@ -22,7 +22,6 @@ namespace NzbDrone.Core.Configuration String DownloadedEpisodesFolder { get; set; } bool UseSeasonFolder { get; set; } string SortingSeasonFolderFormat { get; set; } - int DefaultQualityProfile { get; set; } bool EnableBacklogSearching { get; set; } bool AutoIgnorePreviouslyDownloadedEpisodes { get; set; } int Retention { get; set; } diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 05b56cccf..3ad7ad42a 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -108,17 +108,12 @@ namespace NzbDrone.Core.Tv _diskProvider.CreateFolder(newSeries.Path); } - + _logger.Info("Adding Series [{0}] Path: [{1}]", newSeries.Title, newSeries.Path); newSeries.Monitored = true; newSeries.CleanTitle = Parser.Parser.NormalizeTitle(newSeries.Title); - if (newSeries.QualityProfileId == 0) - { - newSeries.QualityProfileId = _configService.DefaultQualityProfile; - } - newSeries.SeasonFolder = _configService.UseSeasonFolder; newSeries.BacklogSetting = BacklogSettingType.Inherit; diff --git a/UI/AddSeries/AddSeriesLayout.js b/UI/AddSeries/AddSeriesLayout.js index 1a382b34e..6f32ea754 100644 --- a/UI/AddSeries/AddSeriesLayout.js +++ b/UI/AddSeries/AddSeriesLayout.js @@ -1,13 +1,13 @@ "use strict"; define([ 'app', - 'AddSeries/RootFolders/RootFolderCollection', 'Quality/QualityProfileCollection', + 'AddSeries/RootFolders/RootFolderCollection', 'AddSeries/RootFolders/RootFolderView', 'AddSeries/AddSeriesView', 'AddSeries/Existing/ImportSeriesView' ], - function (app, rootFolderCollection, qualityProfileCollection) { + function (app, qualityProfileCollection, rootFolderCollection) { NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ template: 'AddSeries/addSeriesLayoutTemplate', diff --git a/UI/AddSeries/Existing/ImportSeriesView.js b/UI/AddSeries/Existing/ImportSeriesView.js index 927f27d16..b508e218f 100644 --- a/UI/AddSeries/Existing/ImportSeriesView.js +++ b/UI/AddSeries/Existing/ImportSeriesView.js @@ -1,7 +1,6 @@ 'use strict'; define([ 'app', 'AddSeries/RootFolders/RootFolderCollection', - 'Quality/QualityProfileCollection', 'AddSeries/Existing/UnmappedFolderModel', 'AddSeries/Collection', 'AddSeries/SearchResultView', @@ -22,7 +21,6 @@ define([ ui: { searchButton: '.x-btn-search', searchText : '.x-txt-search', - profileList : '.x-lst-quality-profile', searchBar : '.x-search-bar', loadMore : '.x-load-more' }, @@ -99,7 +97,6 @@ define([ itemViewOptions: function () { return { - qualityProfile: this.ui.profileList, rootFolder : this.model.get('rootFolder'), folder : this.model.get('folder').path, isExisting : true diff --git a/UI/AddSeries/Existing/UnmappedFolderModel.js b/UI/AddSeries/Existing/UnmappedFolderModel.js index 107c508bb..58815c535 100644 --- a/UI/AddSeries/Existing/UnmappedFolderModel.js +++ b/UI/AddSeries/Existing/UnmappedFolderModel.js @@ -1,13 +1,8 @@ 'use strict'; -define(['app', 'Quality/QualityProfileCollection'], function (app, qualityProfiles) { +define(['app'], function () { NzbDrone.AddSeries.Existing.UnmappedFolderModel = Backbone.Model.extend({ - - defaults: { - quality: qualityProfiles - } - }); NzbDrone.AddSeries.Existing.UnmappedFolderCollection = Backbone.Collection.extend({ diff --git a/UI/AddSeries/RootFolders/RootFolderSelectionTemplate.html b/UI/AddSeries/RootFolders/RootFolderSelectionTemplate.html index fa54c561d..c562eb0f6 100644 --- a/UI/AddSeries/RootFolders/RootFolderSelectionTemplate.html +++ b/UI/AddSeries/RootFolders/RootFolderSelectionTemplate.html @@ -1,5 +1,4 @@  - {{#each qualityProfiles.models}} - - {{/each}} - +
+ {{qualityProfileSelection}} +
diff --git a/UI/AddSeries/SearchResultView.js b/UI/AddSeries/SearchResultView.js index 630c0c7e5..df1b5404b 100644 --- a/UI/AddSeries/SearchResultView.js +++ b/UI/AddSeries/SearchResultView.js @@ -1,5 +1,10 @@ 'use strict'; -define(['app', 'Series/SeriesCollection', 'AddSeries/RootFolders/RootFolderTemplateHelper'], function () { +define(['app', + 'Quality/QualityProfileCollection', + 'Config', + 'Series/SeriesCollection', + 'AddSeries/RootFolders/RootFolderTemplateHelper', + 'Quality/QualityProfileTemplateHelper'], function (app, qualityProfiles) { NzbDrone.AddSeries.SearchResultView = Backbone.Marionette.ItemView.extend({ @@ -13,7 +18,8 @@ define(['app', 'Series/SeriesCollection', 'AddSeries/RootFolders/RootFolderTempl }, events: { - 'click .x-add': 'addSeries' + 'click .x-add' : 'addSeries', + 'change .x-quality-profile': '_qualityProfileChanged' }, initialize: function () { @@ -24,12 +30,33 @@ define(['app', 'Series/SeriesCollection', 'AddSeries/RootFolders/RootFolderTempl this.model.set('isExisting', this.options.isExisting); this.model.set('path', this.options.folder); + + NzbDrone.vent.on(NzbDrone.Config.Events.ConfigUpdatedEvent, this._onConfigUpdated, this); + }, + + + _onConfigUpdated: function (options) { + + if (options.key === NzbDrone.Config.Keys.DefaultQualityProfileId) { + this.$('.x-quality-profile').val(options.value); + } + }, + + _qualityProfileChanged: function () { + NzbDrone.Config.SetValue(NzbDrone.Config.Keys.DefaultQualityProfileId, this.ui.qualityProfile.val()); }, onRender: function () { this.listenTo(this.model, 'change', this.render); + + var defaultQuality = NzbDrone.Config.GetValue(NzbDrone.Config.Keys.DefaultQualityProfileId); + + if (qualityProfiles.get(defaultQuality)) { + this.ui.qualityProfile.val(defaultQuality); + } }, + addSeries: function () { var icon = this.ui.addButton.find('icon'); icon.removeClass('icon-plus').addClass('icon-spin icon-spinner disabled'); diff --git a/UI/Config.js b/UI/Config.js index b25d3af74..ec6e83fb9 100644 --- a/UI/Config.js +++ b/UI/Config.js @@ -1,6 +1,15 @@ "use strict"; define(['app'], function () { + NzbDrone.Config = { + Events: { + ConfigUpdatedEvent: 'ConfigUpdatedEvent' + }, + Keys : { + DefaultQualityProfileId: 'DefaultQualityProfileId' + } + }; + NzbDrone.Config.GetValue = function (key, defaultValue) { var storeValue = localStorage.getItem(key); @@ -9,12 +18,20 @@ define(['app'], function () { return defaultValue; } - return storeValue; + return storeValue.toString(); }; NzbDrone.Config.SetValue = function (key, value) { + console.log('Config: [{0}] => [{1}] '.format(key, value)); + + if (NzbDrone.Config.GetValue(key) === value.toString()) { + return; + } + localStorage.setItem(key, value); + NzbDrone.vent.trigger(NzbDrone.Config.Events.ConfigUpdatedEvent, {key: key, value: value}); + }; }); diff --git a/UI/Quality/QualityProfileSelectionTemplate.html b/UI/Quality/QualityProfileSelectionTemplate.html new file mode 100644 index 000000000..a414fd13a --- /dev/null +++ b/UI/Quality/QualityProfileSelectionTemplate.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/UI/Quality/QualityProfileTemplateHelper.js b/UI/Quality/QualityProfileTemplateHelper.js new file mode 100644 index 000000000..4f63a0574 --- /dev/null +++ b/UI/Quality/QualityProfileTemplateHelper.js @@ -0,0 +1,10 @@ +'use strict'; + +define(['app', 'Quality/QualityProfileCollection'], function (app, qualityProfiles) { + + Handlebars.registerHelper('qualityProfileSelection', function () { + + var templateFunction = Marionette.TemplateCache.get('Quality/QualityProfileSelectionTemplate'); + return new Handlebars.SafeString(templateFunction(qualityProfiles.toJSON())); + }); +}); diff --git a/UI/Settings/Quality/QualityLayout.js b/UI/Settings/Quality/QualityLayout.js index fe0270cf0..72335ae3b 100644 --- a/UI/Settings/Quality/QualityLayout.js +++ b/UI/Settings/Quality/QualityLayout.js @@ -3,7 +3,6 @@ define([ 'app', 'Quality/QualityProfileCollection', 'Quality/QualitySizeCollection', - 'Settings/Quality/QualityView', 'Settings/Quality/Profile/QualityProfileCollectionView', 'Settings/Quality/Size/QualitySizeCollectionView' ], @@ -33,7 +32,6 @@ define([ }, onRender: function () { - this.qualityStandard.show(new NzbDrone.Settings.Quality.QualityView({model: this.settings, qualityProfiles: qualityProfileCollection})); this.qualityProfile.show(new NzbDrone.Settings.Quality.Profile.QualityProfileCollectionView({collection: qualityProfileCollection})); this.qualitySize.show(new NzbDrone.Settings.Quality.Size.QualitySizeCollectionView({collection: this.qualitySizeCollection})); } diff --git a/UI/Settings/Quality/QualityTemplate.html b/UI/Settings/Quality/QualityTemplate.html deleted file mode 100644 index eef420883..000000000 --- a/UI/Settings/Quality/QualityTemplate.html +++ /dev/null @@ -1,14 +0,0 @@ -
- - -
- - - - -
-
diff --git a/UI/Settings/Quality/QualityView.js b/UI/Settings/Quality/QualityView.js deleted file mode 100644 index 609378591..000000000 --- a/UI/Settings/Quality/QualityView.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; -define([ - 'app', 'Settings/SettingsModel' -], function () { - NzbDrone.Settings.Quality.QualityView = Backbone.Marionette.ItemView.extend({ - template : 'Settings/Quality/QualityTemplate', - className: 'form-horizontal', - - initialize: function (options) { - this.qualityProfileCollection = options.qualityProfiles; - this.model.set({ qualityProfiles: this.qualityProfileCollection }); - } - }); -});