From 13aa79d5f9d40198324d5a204534d30c66caece3 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Mon, 28 Jan 2013 17:59:18 -0800 Subject: [PATCH] code to support import existing series. --- NzbDrone.Api/NzbDrone.Api.csproj | 2 +- .../RootFolderModule.cs | 6 +- NzbDrone.Core/Providers/RootDirProvider.cs | 1 + NzbDrone.Core/Repository/RootDir.cs | 6 +- NzbDrone.Web/NzbDrone.Web.csproj | 8 ++- .../_backboneApp/AddSeries/AddSeriesLayout.js | 5 +- .../ImportSeriesTemplate.html | 5 ++ .../ImportExistingSeries/ImportSeriesView.js | 28 ++++++++ .../_backboneApp/CassetteConfiguration.cs | 2 +- .../_backboneApp/Shared/ErrorModel.js | 23 ------ .../_backboneApp/Shared/ErrorTemplate.html | 9 --- NzbDrone.Web/_backboneApp/Shared/ErrorView.js | 66 ----------------- .../_backboneApp/Shared/NotificationModel.js | 42 +++++++++++ .../Shared/NotificationTemplate.html | 9 +++ .../_backboneApp/Shared/NotificationView.js | 72 +++++++++++++++++++ 15 files changed, 175 insertions(+), 109 deletions(-) rename NzbDrone.Api/{QualityProfiles => RootFolders}/RootFolderModule.cs (92%) create mode 100644 NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesTemplate.html create mode 100644 NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesView.js delete mode 100644 NzbDrone.Web/_backboneApp/Shared/ErrorModel.js delete mode 100644 NzbDrone.Web/_backboneApp/Shared/ErrorTemplate.html delete mode 100644 NzbDrone.Web/_backboneApp/Shared/ErrorView.js create mode 100644 NzbDrone.Web/_backboneApp/Shared/NotificationModel.js create mode 100644 NzbDrone.Web/_backboneApp/Shared/NotificationTemplate.html create mode 100644 NzbDrone.Web/_backboneApp/Shared/NotificationView.js diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 64e7e85e9..63e4b4977 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -94,7 +94,7 @@ - + diff --git a/NzbDrone.Api/QualityProfiles/RootFolderModule.cs b/NzbDrone.Api/RootFolders/RootFolderModule.cs similarity index 92% rename from NzbDrone.Api/QualityProfiles/RootFolderModule.cs rename to NzbDrone.Api/RootFolders/RootFolderModule.cs index 5fd17a02b..306b2d61c 100644 --- a/NzbDrone.Api/QualityProfiles/RootFolderModule.cs +++ b/NzbDrone.Api/RootFolders/RootFolderModule.cs @@ -1,10 +1,10 @@ -using Nancy; +using System.Linq; +using Nancy; using NzbDrone.Api.Extentions; using NzbDrone.Core.Providers; -using NzbDrone.Api.QualityType; using NzbDrone.Core.Repository; -namespace NzbDrone.Api.QualityProfiles +namespace NzbDrone.Api.RootFolders { public class RootDirModule : NzbDroneApiModule { diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs index 2c2cbc1d9..3e1ef5bc2 100644 --- a/NzbDrone.Core/Providers/RootDirProvider.cs +++ b/NzbDrone.Core/Providers/RootDirProvider.cs @@ -85,6 +85,7 @@ namespace NzbDrone.Core.Providers foreach (var rootDir in rootDirs) { rootDir.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path)); + rootDir.UnmappedFolders = GetUnmappedFolders(rootDir.Path); } return rootDirs; diff --git a/NzbDrone.Core/Repository/RootDir.cs b/NzbDrone.Core/Repository/RootDir.cs index 28f0d1c00..3003dbf6f 100644 --- a/NzbDrone.Core/Repository/RootDir.cs +++ b/NzbDrone.Core/Repository/RootDir.cs @@ -1,4 +1,5 @@ -using PetaPoco; +using System.Collections.Generic; +using PetaPoco; namespace NzbDrone.Core.Repository { @@ -12,5 +13,8 @@ namespace NzbDrone.Core.Repository [ResultColumn] public ulong FreeSpace { get; set; } + + [Ignore] + public List UnmappedFolders { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 7ce94346e..36e1623e5 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -183,6 +183,8 @@ + + @@ -391,9 +393,9 @@ - - - + + + diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js b/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js index 6b61b3c9d..a4a6bfb66 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js @@ -3,6 +3,7 @@ /// /// /// +/// NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ template: "AddSeries/addSeriesLayoutTemplate", @@ -33,14 +34,14 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ this.qualityProfileCollection.fetch(); this.addNew.show(new NzbDrone.AddSeries.AddNewSeriesView({ rootFolders: this.rootFolderCollection, qualityProfiles: this.qualityProfileCollection })); - //this.importExisting.show(new NzbDrone.ImportExistingView()); + this.importExisting.show(new NzbDrone.AddSeries.ExistingFolderListView({ collection: this.rootFolderCollection })); this.rootFolders.show(new NzbDrone.AddSeries.RootDirView({ collection: this.rootFolderCollection })); NzbDrone.vent.listenTo(this.rootFolderCollection, 'add', this.evaluateActions, this); 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/ImportExistingSeries/ImportSeriesTemplate.html b/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesTemplate.html new file mode 100644 index 000000000..0bf996b91 --- /dev/null +++ b/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesTemplate.html @@ -0,0 +1,5 @@ +{{#each unmappedFolders}} +
+ {{this}} +
+{{/each}} diff --git a/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesView.js b/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesView.js new file mode 100644 index 000000000..35cd10395 --- /dev/null +++ b/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesView.js @@ -0,0 +1,28 @@ +/// +/// +/// + +NzbDrone.AddSeries.ExistingFolderItemView = Backbone.Marionette.ItemView.extend({ + + template: "AddSeries/ImportExistingSeries/ImportSeriesTemplate", + + events: { + //'click .x-add': 'add' + }, + +}); + +NzbDrone.AddSeries.ExistingFolderListView = Backbone.Marionette.CollectionView.extend({ + + itemView: NzbDrone.AddSeries.ExistingFolderItemView, + + initialize: function (options) { + + if (this.collection === undefined) { + throw "root folder collection is required."; + } + + this.listenTo(this.collection, 'reset', this.render, this); + }, + +}); diff --git a/NzbDrone.Web/_backboneApp/CassetteConfiguration.cs b/NzbDrone.Web/_backboneApp/CassetteConfiguration.cs index 32c71a0cd..209219294 100644 --- a/NzbDrone.Web/_backboneApp/CassetteConfiguration.cs +++ b/NzbDrone.Web/_backboneApp/CassetteConfiguration.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Web.Backbone.NzbDrone bundles.Add(NZBDRONE, new[]{ APP_PATH + "\\AddSeries\\AddSeriesLayout.js", - APP_PATH + "\\Shared\\ErrorView.js", + APP_PATH + "\\Shared\\NotificationView.js", }); diff --git a/NzbDrone.Web/_backboneApp/Shared/ErrorModel.js b/NzbDrone.Web/_backboneApp/Shared/ErrorModel.js deleted file mode 100644 index 352128146..000000000 --- a/NzbDrone.Web/_backboneApp/Shared/ErrorModel.js +++ /dev/null @@ -1,23 +0,0 @@ -/// - -NzbDrone.Shared.ErrorCollection = Backbone.Collection.extend({ - - model: NzbDrone.Shared.ErrorModel, - -}); - - -NzbDrone.Shared.ErrorModel = Backbone.Model.extend({ - - mutators: { - pre: function () { - return this.get('message').lines().lenght > 1; - } - }, - - - defaults: { - "title": "NO_TITLE", - "message": "NO_MESSAGE", - } -}); diff --git a/NzbDrone.Web/_backboneApp/Shared/ErrorTemplate.html b/NzbDrone.Web/_backboneApp/Shared/ErrorTemplate.html deleted file mode 100644 index d9b5e2422..000000000 --- a/NzbDrone.Web/_backboneApp/Shared/ErrorTemplate.html +++ /dev/null @@ -1,9 +0,0 @@ -
- - {{title}} - {{#if preFormatted}} -
 {{message}}
- {{else}} - {{message}} - {{/if}} -
diff --git a/NzbDrone.Web/_backboneApp/Shared/ErrorView.js b/NzbDrone.Web/_backboneApp/Shared/ErrorView.js deleted file mode 100644 index c61dedb1d..000000000 --- a/NzbDrone.Web/_backboneApp/Shared/ErrorView.js +++ /dev/null @@ -1,66 +0,0 @@ -/// -/// - -NzbDrone.Shared.ErrorItemView = Backbone.Marionette.ItemView.extend({ - template: "Shared/ErrorTemplate", -}); - -NzbDrone.Shared.ErrorView = Backbone.Marionette.CollectionView.extend({ - - itemView: NzbDrone.Shared.ErrorItemView, - - initialize: function () { - - this.collection = new NzbDrone.Shared.ErrorCollection(); - this.listenTo(this.collection, 'reset', this.render); - }, -}); - - - -NzbDrone.addInitializer(function (options) { - - console.log("initializing error handler"); - - NzbDrone.Shared.ErrorView.instance = new NzbDrone.Shared.ErrorView(); - - NzbDrone.errorRegion.show(NzbDrone.Shared.ErrorView.instance); - -}); - - -window.onerror = function (msg, url, line) { - - var errorView = NzbDrone.Shared.ErrorView.instance; - - if (errorView) { - var model = new NzbDrone.Shared.ErrorModel(); - - var a = document.createElement('a'); - a.href = url; - - model.set('title', a.pathname.split('/').pop() + " : " + line); - model.set('message', msg); - errorView.collection.add(model); - } else { - alert("Error: " + msg + "\nurl: " + url + "\nline #: " + line); - } - - var suppressErrorAlert = false; - return suppressErrorAlert; -}; - -$(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) { - - if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) return; - - var errorView = NzbDrone.Shared.ErrorView.instance; - - var model = new NzbDrone.Shared.ErrorModel(); - model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText); - model.set('message', xmlHttpRequest.responseText); - errorView.collection.add(model); - - var suppressErrorAlert = false; - return suppressErrorAlert; -}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Shared/NotificationModel.js b/NzbDrone.Web/_backboneApp/Shared/NotificationModel.js new file mode 100644 index 000000000..162f8f28d --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Shared/NotificationModel.js @@ -0,0 +1,42 @@ +/// + +NzbDrone.Shared.NotificationCollection = Backbone.Collection.extend({ + + model: NzbDrone.Shared.NotificationModel, + +}); + + +NzbDrone.Shared.NotificationModel = Backbone.Model.extend({ + + mutators: { + pre: function () { + return this.get('message').lines().lenght > 1; + }, + iconClass: function () { + + if (this.has('icon')) { + return "icon"; + } + + if (this.get('level') == 'info') { + return "icon-info-sign"; + } + else if (this.get('level') == 'success') { + return 'icon-ok-sign'; + } + else if (this.get('level') == 'error') { + return 'icon-warning-sign'; + } + + return ""; + } + }, + + + defaults: { + "level": "info", + "title": "", + "message": "", + } +}); diff --git a/NzbDrone.Web/_backboneApp/Shared/NotificationTemplate.html b/NzbDrone.Web/_backboneApp/Shared/NotificationTemplate.html new file mode 100644 index 000000000..8bc4600aa --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Shared/NotificationTemplate.html @@ -0,0 +1,9 @@ +
+ + {{title}} + {{#if preFormatted}} +
 {{message}}
+ {{else}} + {{message}} + {{/if}} +
diff --git a/NzbDrone.Web/_backboneApp/Shared/NotificationView.js b/NzbDrone.Web/_backboneApp/Shared/NotificationView.js new file mode 100644 index 000000000..564f4ff97 --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Shared/NotificationView.js @@ -0,0 +1,72 @@ +/// +/// + +NzbDrone.Shared.NotificationItemView = Backbone.Marionette.ItemView.extend({ + template: "Shared/NotificationTemplate", + + events: { + 'click .x-close': 'kill' + }, + + kill: function () { + + var self = this; + + $.Deferred(function () { + self.$el.slideUp('slow'); + }).done(function () { + self.model.destroy(); + }); + + + } +}); + +NzbDrone.Shared.NotificationCollectionView = Backbone.Marionette.CollectionView.extend({ + + itemView: NzbDrone.Shared.NotificationItemView, + + initialize: function () { + this.collection = new NzbDrone.Shared.NotificationCollection(); + }, +}); + +NzbDrone.addInitializer(function (options) { + NzbDrone.errorRegion.show(NzbDrone.Shared.NotificationCollectionView.Instance); +}); + + +NzbDrone.Shared.NotificationCollectionView.Instance = new NzbDrone.Shared.NotificationCollectionView(); + +window.onerror = function (msg, url, line) { + + try { + var model = new NzbDrone.Shared.NotificationModel(); + + var a = document.createElement('a'); + a.href = url; + + model.set('title', a.pathname.split('/').pop() + " : " + line); + model.set('message', msg); + model.set('level', 'error'); + NzbDrone.Shared.NotificationCollectionView.Instance.collection.add(model); + } catch (error) { + alert("Couldn't report JS error. " + error); + } + + var suppressErrorAlert = false; + return suppressErrorAlert; +}; + +$(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) { + + if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) return; + var model = new NzbDrone.Shared.NotificationModel(); + model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText); + model.set('message', xmlHttpRequest.responseText); + model.set('level', 'error'); + NzbDrone.Shared.NotificationCollectionView.Instance.collection.add(model); + + var suppressErrorAlert = false; + return suppressErrorAlert; +}); \ No newline at end of file