1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Updated as per markus request for viewing disk space

Added two methods to Diskprovider:-
getFixedDrives, getTotalSize
and letting UI decide on how to display space.
and changed from vent to listenTo
This commit is contained in:
fzr600dave 2013-10-11 09:49:03 +01:00
parent 5387c61864
commit 5aa00cfb64
4 changed files with 35 additions and 21 deletions

View File

@ -3,26 +3,30 @@
using System.IO;
using System.Linq;
using System.Text;
using NzbDrone.Common;
namespace NzbDrone.Api.DiskSpace
{
public class DiskSpaceModule :NzbDroneRestModule<DiskSpaceResource>
{
public DiskSpaceModule():base("diskspace")
private readonly IDiskProvider _diskProvider;
public DiskSpaceModule(IDiskProvider diskProvider):base("diskspace")
{
_diskProvider = diskProvider;
GetResourceAll = GetFreeSpace;
}
public List<DiskSpaceResource> GetFreeSpace()
{
return (DriveInfo.GetDrives()
.Where(driveInfo => driveInfo.DriveType == DriveType.Fixed)
return (_diskProvider.GetFixedDrives()
.Select(
driveInfo =>
x =>
new DiskSpaceResource()
{
DriveLetter = driveInfo.Name,
FreeSpace = SizeSuffix(driveInfo.TotalFreeSpace),
TotalSpace = SizeSuffix(driveInfo.TotalSize)
DriveLetter = x,
FreeSpace = _diskProvider.GetAvailableSpace(x).Value,
TotalSpace = _diskProvider.GetTotalSize(x).Value
})).ToList();
}

View File

@ -9,7 +9,7 @@ namespace NzbDrone.Api.DiskSpace
public class DiskSpaceResource : RestResource
{
public string DriveLetter { get; set; }
public string FreeSpace { get; set; }
public string TotalSpace { get; set; }
public Int64 FreeSpace { get; set; }
public Int64 TotalSpace { get; set; }
}
}

View File

@ -42,6 +42,8 @@ public interface IDiskProvider
void SetFolderWriteTime(string path, DateTime time);
FileAttributes GetFileAttributes(string path);
void EmptyFolder(string path);
string[] GetFixedDrives();
long? GetTotalSize(string path);
}
public class DiskProvider : IDiskProvider
@ -475,5 +477,15 @@ public void EmptyFolder(string path)
DeleteFolder(directory, true);
}
}
public string[] GetFixedDrives()
{
return (DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Fixed).Select(x => x.Name)).ToArray();
}
public long? GetTotalSize(string path)
{
return (DriveInfo.GetDrives().Single(x => x.Name == path)).TotalSize;
}
}
}

View File

@ -4,8 +4,9 @@ define([
'marionette',
'backgrid',
'System/DiskSpace/DiskSpaceCollection',
'Shared/LoadingView'
], function (vent,Marionette,Backgrid,DiskSpaceCollection,LoadingView) {
'Shared/LoadingView',
'Cells/FileSizeCell'
], function (vent,Marionette,Backgrid,DiskSpaceCollection,LoadingView,FileSizeCell) {
return Marionette.Layout.extend({
template: 'System/DiskSpace/DiskSpaceTemplate',
@ -17,35 +18,32 @@ define([
{
name: 'driveLetter',
label: 'Drive',
cell: Backgrid.StringCell
cell: 'string'
},
{
name: 'freeSpace',
label: 'Free Space',
cell: Backgrid.StringCell
cell: FileSizeCell,
sortable:true
},
{
name: 'totalSpace',
label: 'Total Space',
cell: Backgrid.StringCell
cell: FileSizeCell,
sortable:true
}
],
initialize: function () {
this.collection = new DiskSpaceCollection();
this.collectionPromise = this.collection.fetch();
vent.on(vent.Events.CommandComplete, this._commandComplete, this);
this.listenTo(this.collection, 'sync', this._showTable);
},
onRender : function() {
this.grid.show(new LoadingView());
},
onShow: function() {
var self = this;
this.collectionPromise.done(function() {
self._showTable();
});
this.collection.fetch();
},
_showTable: function() {
this.grid.show(new Backgrid.Grid({