root dir management is fully functional.

pull/6/head
Keivan Beigi 12 years ago committed by kay.one
parent 57bb6e1e01
commit b50cd19add

@ -16,17 +16,24 @@ namespace NzbDrone.Api.QualityProfiles
Get["/"] = x => GetRootFolders(); Get["/"] = x => GetRootFolders();
Post["/"] = x => AddRootFolder(); Post["/"] = x => AddRootFolder();
Delete["/{id}"] = x => DeleteRootFolder((int)x.id);
} }
private Response AddRootFolder() private Response AddRootFolder()
{ {
_rootDirProvider.Add(Request.Body.FromJson<RootDir>()); var dir = _rootDirProvider.Add(Request.Body.FromJson<RootDir>());
return new Response { StatusCode = HttpStatusCode.Created }; return dir.AsResponse(HttpStatusCode.Created);
} }
private Response GetRootFolders() private Response GetRootFolders()
{ {
return _rootDirProvider.AllWithFreeSpace().AsResponse(); return _rootDirProvider.AllWithFreeSpace().AsResponse();
} }
private Response DeleteRootFolder(int folderId)
{
_rootDirProvider.Remove(folderId);
return new Response { StatusCode = HttpStatusCode.OK };
}
} }
} }

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Providers
return _database.Fetch<RootDir>(); return _database.Fetch<RootDir>();
} }
public virtual void Add(RootDir rootDir) public virtual RootDir Add(RootDir rootDir)
{ {
if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path)) if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path))
throw new ArgumentException("Invalid path"); throw new ArgumentException("Invalid path");
@ -40,7 +40,11 @@ namespace NzbDrone.Core.Providers
if (GetAll().Exists(r => DiskProvider.PathEquals(r.Path, rootDir.Path))) if (GetAll().Exists(r => DiskProvider.PathEquals(r.Path, rootDir.Path)))
throw new InvalidOperationException("Root directory already exist."); 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) public virtual void Remove(int rootDirId)
@ -96,13 +100,13 @@ namespace NzbDrone.Core.Providers
{ {
var pathRoot = _diskProvider.GetPathRoot(rootDir.Path); var pathRoot = _diskProvider.GetPathRoot(rootDir.Path);
if(!freeSpace.ContainsKey(pathRoot)) if (!freeSpace.ContainsKey(pathRoot))
{ {
try try
{ {
freeSpace.Add(pathRoot, _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path))); freeSpace.Add(pathRoot, _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path)));
} }
catch(Exception ex) catch (Exception ex)
{ {
Logger.WarnException("Error getting fromm space for: " + pathRoot, ex); Logger.WarnException("Error getting fromm space for: " + pathRoot, ex);
} }

@ -80,7 +80,7 @@
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.0.8.0" /> <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="dotless.ClientOnly" publicKeyToken="96b446c9e63eae34" culture="neutral" /> <assemblyIdentity name="dotless.ClientOnly" publicKeyToken="96b446c9e63eae34" culture="neutral" />

@ -1,4 +1,4 @@
/// <reference path="../../app.js" /> /// <reference path="../../app.js" />
NzbDrone.AddSeries.RootDirModel = Backbone.Model.extend({ NzbDrone.AddSeries.RootDirModel = Backbone.Model.extend({
url: NzbDrone.Constants.ApiRoot + 'rootdir/', idAttribute: 'Id',
}); });

@ -17,6 +17,7 @@ NzbDrone.AddSeries.RootDirItemView = Backbone.Marionette.ItemView.extend({
removeDir: function () { removeDir: function () {
this.model.destroy({ wait: true }); 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.collection.create(newDir, { wait: true });
this.fetch(); this.collection.fetch();
}, },
search: function (context) { search: function (context) {

Loading…
Cancel
Save