From 525963f2a654b68aaf51c27cd6e26565c484ee73 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 12 May 2013 21:24:04 -0700 Subject: [PATCH] Existing series view loads again --- NzbDrone.Api/RootFolders/RootFolderModule.cs | 2 +- .../RootFolders/RootFolderResource.cs | 4 ++++ .../RootFolders/RootFolderService.cs | 20 +++++++++++++------ UI/AddSeries/Collection.js | 15 ++++++++++++++ UI/AddSeries/Existing/ImportSeriesView.js | 12 +++++++---- UI/AddSeries/New/AddNewSeriesView.js | 13 +++--------- 6 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 UI/AddSeries/Collection.js diff --git a/NzbDrone.Api/RootFolders/RootFolderModule.cs b/NzbDrone.Api/RootFolders/RootFolderModule.cs index 0b9ad2ccf..c929fc1d6 100644 --- a/NzbDrone.Api/RootFolders/RootFolderModule.cs +++ b/NzbDrone.Api/RootFolders/RootFolderModule.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Api.RootFolders private List GetRootFolders() { - return ApplyToList(_rootFolderService.All); + return ApplyToList(_rootFolderService.AllWithUnmappedFolders); } private void DeleteFolder(int id) diff --git a/NzbDrone.Api/RootFolders/RootFolderResource.cs b/NzbDrone.Api/RootFolders/RootFolderResource.cs index d4d0532e6..05af828c1 100644 --- a/NzbDrone.Api/RootFolders/RootFolderResource.cs +++ b/NzbDrone.Api/RootFolders/RootFolderResource.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using NzbDrone.Api.REST; +using NzbDrone.Core.RootFolders; namespace NzbDrone.Api.RootFolders { @@ -7,5 +9,7 @@ namespace NzbDrone.Api.RootFolders { public String Path { get; set; } public Int64 FreeSpace { get; set; } + + public List UnmappedFolders { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Core/RootFolders/RootFolderService.cs b/NzbDrone.Core/RootFolders/RootFolderService.cs index 7bd810597..b17db5da5 100644 --- a/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -12,6 +12,7 @@ namespace NzbDrone.Core.RootFolders public interface IRootFolderService { List All(); + List AllWithUnmappedFolders(); RootFolder Add(RootFolder rootDir); void Remove(int id); List GetUnmappedFolders(string path); @@ -37,14 +38,21 @@ namespace NzbDrone.Core.RootFolders { var rootFolders = _rootFolderRepository.All().ToList(); + return rootFolders; + } + + public virtual List AllWithUnmappedFolders() + { + var rootFolders = _rootFolderRepository.All().ToList(); + rootFolders.ForEach(folder => + { + if (_diskProvider.FolderExists(folder.Path)) { - if (_diskProvider.FolderExists(folder.Path)) - { - folder.FreeSpace = _diskProvider.GetAvilableSpace(folder.Path); - folder.UnmappedFolders = GetUnmappedFolders(folder.Path); - } - }); + folder.FreeSpace = _diskProvider.GetAvilableSpace(folder.Path); + folder.UnmappedFolders = GetUnmappedFolders(folder.Path); + } + }); return rootFolders; } diff --git a/UI/AddSeries/Collection.js b/UI/AddSeries/Collection.js new file mode 100644 index 000000000..2d7b73808 --- /dev/null +++ b/UI/AddSeries/Collection.js @@ -0,0 +1,15 @@ +"use strict"; +define(['app', 'Series/SeriesModel'], function () { + NzbDrone.AddSeries.Collection = Backbone.Collection.extend({ + url : NzbDrone.Constants.ApiRoot + '/series/lookup', + model: NzbDrone.Series.SeriesModel, + + parse: function (response) { + _.each(response, function (model) { + model.id = undefined; + }); + + return response; + } + }); +}); diff --git a/UI/AddSeries/Existing/ImportSeriesView.js b/UI/AddSeries/Existing/ImportSeriesView.js index 5d41e1809..38e97ec9f 100644 --- a/UI/AddSeries/Existing/ImportSeriesView.js +++ b/UI/AddSeries/Existing/ImportSeriesView.js @@ -1,6 +1,11 @@ 'use strict'; define([ - 'app', 'AddSeries/RootFolders/RootFolderCollection', 'Quality/QualityProfileCollection', 'Shared/NotificationCollection', 'AddSeries/Existing/UnmappedFolderModel', 'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection, notificationCollection) { + 'app', 'AddSeries/RootFolders/RootFolderCollection', + 'Quality/QualityProfileCollection', + 'Shared/NotificationCollection', + 'AddSeries/Existing/UnmappedFolderModel', + 'AddSeries/Collection', + 'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection, notificationCollection) { NzbDrone.AddSeries.Existing.FolderMatchResultView = Backbone.Marionette.ItemView.extend({ template: 'AddSeries/SearchResultTemplate', @@ -29,7 +34,7 @@ define([ this.model.set('rootFolderId', rootFolderId); this.model.set('folder', folder); - var seriesCollection = new NzbDrone.Series.SeriesCollection(); + var seriesCollection = new NzbDrone.AddSeries.Collection(); seriesCollection.add(this.model); this.model.save(undefined, { @@ -68,7 +73,7 @@ define([ }, initialize: function () { - this.collection = new NzbDrone.Series.SeriesCollection(); + this.collection = new NzbDrone.AddSeries.Collection(); this.collection.bind('reset', this.collectionReset, this); this.on("itemview:seriesAdded", function(){ @@ -77,7 +82,6 @@ define([ }, onRender: function () { - this.collection.url = NzbDrone.Constants.ApiRoot + '/series/lookup'; this.resultView = new NzbDrone.AddSeries.SearchResultView({ collection: this.collection }); }, diff --git a/UI/AddSeries/New/AddNewSeriesView.js b/UI/AddSeries/New/AddNewSeriesView.js index 0b5911552..95c0b6d09 100644 --- a/UI/AddSeries/New/AddNewSeriesView.js +++ b/UI/AddSeries/New/AddNewSeriesView.js @@ -1,5 +1,6 @@ "use strict"; -define(['app', 'AddSeries/RootFolders/RootFolderCollection', 'AddSeries/New/SearchResultView', 'Shared/SpinnerView'], function () { +define(['app', 'AddSeries/RootFolders/RootFolderCollection', 'AddSeries/New/SearchResultView', 'Shared/SpinnerView', + 'AddSeries/Collection'], function () { NzbDrone.AddSeries.New.AddNewSeriesView = Backbone.Marionette.Layout.extend({ template: 'AddSeries/New/AddNewSeriesTemplate', route : 'Series/add/new', @@ -14,16 +15,9 @@ define(['app', 'AddSeries/RootFolders/RootFolderCollection', 'AddSeries/New/Sear initialize: function () { - this.collection = new NzbDrone.Series.SeriesCollection(); + this.collection = new NzbDrone.AddSeries.Collection(); - this.collection.parse = function (response) { - _.each(response, function (model) { model.id = undefined; - }); - - return response; - }; - NzbDrone.AddSeries.New.AddNewSeriesContext = this; NzbDrone.vent.on(NzbDrone.Events.SeriesAdded, function (options) { @@ -46,7 +40,6 @@ define(['app', 'AddSeries/RootFolders/RootFolderCollection', 'AddSeries/New/Sear self.$el.data('timeout', window.setTimeout(self.search, 500, self)); }); - this.collection.url = NzbDrone.Constants.ApiRoot + '/series/lookup'; this.resultView = new NzbDrone.AddSeries.SearchResultView({ collection: this.collection }); },