From 6c414929c3700c5b059470434ac939a52513ac5d Mon Sep 17 00:00:00 2001 From: fzr600dave Date: Fri, 11 Oct 2013 09:49:03 +0100 Subject: [PATCH] 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) --- src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs | 18 +++++++++------ .../DiskSpace/DiskSpaceResource.cs | 4 ++-- src/NzbDrone.Common/DiskProvider.cs | 12 ++++++++++ src/UI/System/DiskSpace/DiskSpaceLayout.js | 22 +++++++++---------- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs b/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs index 98c16934f..0126d84fd 100644 --- a/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs +++ b/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs @@ -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 { - public DiskSpaceModule():base("diskspace") + private readonly IDiskProvider _diskProvider; + + public DiskSpaceModule(IDiskProvider diskProvider):base("diskspace") { + _diskProvider = diskProvider; GetResourceAll = GetFreeSpace; } + public List 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(); } diff --git a/src/NzbDrone.Api/DiskSpace/DiskSpaceResource.cs b/src/NzbDrone.Api/DiskSpace/DiskSpaceResource.cs index 8d3796051..261ae6305 100644 --- a/src/NzbDrone.Api/DiskSpace/DiskSpaceResource.cs +++ b/src/NzbDrone.Api/DiskSpace/DiskSpaceResource.cs @@ -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; } } } diff --git a/src/NzbDrone.Common/DiskProvider.cs b/src/NzbDrone.Common/DiskProvider.cs index 5860d95cd..a075b5e10 100644 --- a/src/NzbDrone.Common/DiskProvider.cs +++ b/src/NzbDrone.Common/DiskProvider.cs @@ -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; + } } } \ No newline at end of file diff --git a/src/UI/System/DiskSpace/DiskSpaceLayout.js b/src/UI/System/DiskSpace/DiskSpaceLayout.js index 1db1049fd..63c03aa43 100644 --- a/src/UI/System/DiskSpace/DiskSpaceLayout.js +++ b/src/UI/System/DiskSpace/DiskSpaceLayout.js @@ -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({