From b50cd19add8d99ddfeeaf28a1d8b9160b081b27e Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Thu, 24 Jan 2013 17:22:14 -0800 Subject: [PATCH] root dir management is fully functional. --- NzbDrone.Api/QualityProfiles/RootFolderModule.cs | 11 +++++++++-- NzbDrone.Core/Providers/RootDirProvider.cs | 12 ++++++++---- NzbDrone.Web/Web.config | 2 +- .../_backboneApp/AddSeries/RootDir/RootDirModel.js | 2 +- .../_backboneApp/AddSeries/RootDir/RootDirView.js | 3 ++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/NzbDrone.Api/QualityProfiles/RootFolderModule.cs b/NzbDrone.Api/QualityProfiles/RootFolderModule.cs index d6b2bb088..b9adf60c2 100644 --- a/NzbDrone.Api/QualityProfiles/RootFolderModule.cs +++ b/NzbDrone.Api/QualityProfiles/RootFolderModule.cs @@ -16,17 +16,24 @@ namespace NzbDrone.Api.QualityProfiles Get["/"] = x => GetRootFolders(); Post["/"] = x => AddRootFolder(); + Delete["/{id}"] = x => DeleteRootFolder((int)x.id); } private Response AddRootFolder() { - _rootDirProvider.Add(Request.Body.FromJson()); - return new Response { StatusCode = HttpStatusCode.Created }; + var dir = _rootDirProvider.Add(Request.Body.FromJson()); + return dir.AsResponse(HttpStatusCode.Created); } private Response GetRootFolders() { return _rootDirProvider.AllWithFreeSpace().AsResponse(); } + + private Response DeleteRootFolder(int folderId) + { + _rootDirProvider.Remove(folderId); + return new Response { StatusCode = HttpStatusCode.OK }; + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs index 34f3bab1e..2c2cbc1d9 100644 --- a/NzbDrone.Core/Providers/RootDirProvider.cs +++ b/NzbDrone.Core/Providers/RootDirProvider.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Providers return _database.Fetch(); } - public virtual void Add(RootDir rootDir) + public virtual RootDir Add(RootDir rootDir) { if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path)) throw new ArgumentException("Invalid path"); @@ -40,7 +40,11 @@ namespace NzbDrone.Core.Providers if (GetAll().Exists(r => DiskProvider.PathEquals(r.Path, rootDir.Path))) throw new InvalidOperationException("Root directory already exist."); - _database.Insert(rootDir); + var id = _database.Insert(rootDir); + rootDir.Id = Convert.ToInt32(id); + rootDir.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path)); + + return rootDir; } public virtual void Remove(int rootDirId) @@ -96,13 +100,13 @@ namespace NzbDrone.Core.Providers { var pathRoot = _diskProvider.GetPathRoot(rootDir.Path); - if(!freeSpace.ContainsKey(pathRoot)) + if (!freeSpace.ContainsKey(pathRoot)) { try { freeSpace.Add(pathRoot, _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path))); } - catch(Exception ex) + catch (Exception ex) { Logger.WarnException("Error getting fromm space for: " + pathRoot, ex); } diff --git a/NzbDrone.Web/Web.config b/NzbDrone.Web/Web.config index a5d446002..844591b28 100644 --- a/NzbDrone.Web/Web.config +++ b/NzbDrone.Web/Web.config @@ -80,7 +80,7 @@ - + diff --git a/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirModel.js b/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirModel.js index 68316ceae..80153966c 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirModel.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirModel.js @@ -1,4 +1,4 @@ /// NzbDrone.AddSeries.RootDirModel = Backbone.Model.extend({ - url: NzbDrone.Constants.ApiRoot + 'rootdir/', + idAttribute: 'Id', }); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirView.js b/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirView.js index 64725897a..d83cce29c 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirView.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirView.js @@ -17,6 +17,7 @@ NzbDrone.AddSeries.RootDirItemView = Backbone.Marionette.ItemView.extend({ removeDir: function () { this.model.destroy({ wait: true }); + this.model.collection.remove(this.model); }, }); @@ -74,7 +75,7 @@ NzbDrone.AddSeries.RootDirView = Backbone.Marionette.Layout.extend({ }); this.collection.create(newDir, { wait: true }); - this.fetch(); + this.collection.fetch(); }, search: function (context) {