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:
parent
5387c61864
commit
5aa00cfb64
@ -3,26 +3,30 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using NzbDrone.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Api.DiskSpace
|
namespace NzbDrone.Api.DiskSpace
|
||||||
{
|
{
|
||||||
public class DiskSpaceModule :NzbDroneRestModule<DiskSpaceResource>
|
public class DiskSpaceModule :NzbDroneRestModule<DiskSpaceResource>
|
||||||
{
|
{
|
||||||
public DiskSpaceModule():base("diskspace")
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
|
||||||
|
public DiskSpaceModule(IDiskProvider diskProvider):base("diskspace")
|
||||||
{
|
{
|
||||||
|
_diskProvider = diskProvider;
|
||||||
GetResourceAll = GetFreeSpace;
|
GetResourceAll = GetFreeSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DiskSpaceResource> GetFreeSpace()
|
public List<DiskSpaceResource> GetFreeSpace()
|
||||||
{
|
{
|
||||||
return (DriveInfo.GetDrives()
|
return (_diskProvider.GetFixedDrives()
|
||||||
.Where(driveInfo => driveInfo.DriveType == DriveType.Fixed)
|
|
||||||
.Select(
|
.Select(
|
||||||
driveInfo =>
|
x =>
|
||||||
new DiskSpaceResource()
|
new DiskSpaceResource()
|
||||||
{
|
{
|
||||||
DriveLetter = driveInfo.Name,
|
DriveLetter = x,
|
||||||
FreeSpace = SizeSuffix(driveInfo.TotalFreeSpace),
|
FreeSpace = _diskProvider.GetAvailableSpace(x).Value,
|
||||||
TotalSpace = SizeSuffix(driveInfo.TotalSize)
|
TotalSpace = _diskProvider.GetTotalSize(x).Value
|
||||||
})).ToList();
|
})).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ namespace NzbDrone.Api.DiskSpace
|
|||||||
public class DiskSpaceResource : RestResource
|
public class DiskSpaceResource : RestResource
|
||||||
{
|
{
|
||||||
public string DriveLetter { get; set; }
|
public string DriveLetter { get; set; }
|
||||||
public string FreeSpace { get; set; }
|
public Int64 FreeSpace { get; set; }
|
||||||
public string TotalSpace { get; set; }
|
public Int64 TotalSpace { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,8 @@ public interface IDiskProvider
|
|||||||
void SetFolderWriteTime(string path, DateTime time);
|
void SetFolderWriteTime(string path, DateTime time);
|
||||||
FileAttributes GetFileAttributes(string path);
|
FileAttributes GetFileAttributes(string path);
|
||||||
void EmptyFolder(string path);
|
void EmptyFolder(string path);
|
||||||
|
string[] GetFixedDrives();
|
||||||
|
long? GetTotalSize(string path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DiskProvider : IDiskProvider
|
public class DiskProvider : IDiskProvider
|
||||||
@ -475,5 +477,15 @@ public void EmptyFolder(string path)
|
|||||||
DeleteFolder(directory, true);
|
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',
|
'marionette',
|
||||||
'backgrid',
|
'backgrid',
|
||||||
'System/DiskSpace/DiskSpaceCollection',
|
'System/DiskSpace/DiskSpaceCollection',
|
||||||
'Shared/LoadingView'
|
'Shared/LoadingView',
|
||||||
], function (vent,Marionette,Backgrid,DiskSpaceCollection,LoadingView) {
|
'Cells/FileSizeCell'
|
||||||
|
], function (vent,Marionette,Backgrid,DiskSpaceCollection,LoadingView,FileSizeCell) {
|
||||||
return Marionette.Layout.extend({
|
return Marionette.Layout.extend({
|
||||||
template: 'System/DiskSpace/DiskSpaceTemplate',
|
template: 'System/DiskSpace/DiskSpaceTemplate',
|
||||||
|
|
||||||
@ -17,35 +18,32 @@ define([
|
|||||||
{
|
{
|
||||||
name: 'driveLetter',
|
name: 'driveLetter',
|
||||||
label: 'Drive',
|
label: 'Drive',
|
||||||
cell: Backgrid.StringCell
|
cell: 'string'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'freeSpace',
|
name: 'freeSpace',
|
||||||
label: 'Free Space',
|
label: 'Free Space',
|
||||||
cell: Backgrid.StringCell
|
cell: FileSizeCell,
|
||||||
|
sortable:true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'totalSpace',
|
name: 'totalSpace',
|
||||||
label: 'Total Space',
|
label: 'Total Space',
|
||||||
cell: Backgrid.StringCell
|
cell: FileSizeCell,
|
||||||
|
sortable:true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
this.collection = new DiskSpaceCollection();
|
this.collection = new DiskSpaceCollection();
|
||||||
this.collectionPromise = this.collection.fetch();
|
this.listenTo(this.collection, 'sync', this._showTable);
|
||||||
|
|
||||||
vent.on(vent.Events.CommandComplete, this._commandComplete, this);
|
|
||||||
},
|
},
|
||||||
onRender : function() {
|
onRender : function() {
|
||||||
this.grid.show(new LoadingView());
|
this.grid.show(new LoadingView());
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
var self = this;
|
this.collection.fetch();
|
||||||
this.collectionPromise.done(function() {
|
|
||||||
self._showTable();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
_showTable: function() {
|
_showTable: function() {
|
||||||
this.grid.show(new Backgrid.Grid({
|
this.grid.show(new Backgrid.Grid({
|
||||||
|
Loading…
Reference in New Issue
Block a user