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
(cherry picked from commit 5aa00cfb6498d4731d5d880c346afe747a61024e)
pull/4/head
fzr600dave 11 years ago committed by Mark McDowall
parent 041e767f3d
commit 6c414929c3

@ -3,26 +3,30 @@ using System.Collections.Generic;
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();
}

@ -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; }
}
}

@ -42,6 +42,8 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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;
}
}
}

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

Loading…
Cancel
Save