root dir management is fully functional.

This commit is contained in:
Keivan Beigi 2013-01-24 17:22:14 -08:00 committed by kay.one
parent 57bb6e1e01
commit b50cd19add
5 changed files with 21 additions and 9 deletions

View File

@ -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<RootDir>());
return new Response { StatusCode = HttpStatusCode.Created };
var dir = _rootDirProvider.Add(Request.Body.FromJson<RootDir>());
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 };
}
}
}

View File

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Providers
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))
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);
}

View File

@ -80,7 +80,7 @@
</dependentAssembly>
<dependentAssembly>
<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>
<assemblyIdentity name="dotless.ClientOnly" publicKeyToken="96b446c9e63eae34" culture="neutral" />

View File

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

View File

@ -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) {