Added Disk space information to system.

(cherry picked from commit 91625019378247b1c6ab85afaee23f2855e3298b)
pull/4/head
fzr600dave 11 years ago committed by Mark McDowall
parent 4510ca8fa1
commit 041e767f3d

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace NzbDrone.Api.DiskSpace
{
public class DiskSpaceModule :NzbDroneRestModule<DiskSpaceResource>
{
public DiskSpaceModule():base("diskspace")
{
GetResourceAll = GetFreeSpace;
}
public List<DiskSpaceResource> GetFreeSpace()
{
return (DriveInfo.GetDrives()
.Where(driveInfo => driveInfo.DriveType == DriveType.Fixed)
.Select(
driveInfo =>
new DiskSpaceResource()
{
DriveLetter = driveInfo.Name,
FreeSpace = SizeSuffix(driveInfo.TotalFreeSpace),
TotalSpace = SizeSuffix(driveInfo.TotalSize)
})).ToList();
}
static string SizeSuffix(Int64 value)
{
string[] suffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
int i = 0;
decimal dValue = (decimal)value;
while (Math.Round(dValue / 1024) >= 1)
{
dValue /= 1024;
i++;
}
return string.Format("{0:n1}{1}", dValue, suffixes[i]);
}
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Api.REST;
namespace NzbDrone.Api.DiskSpace
{
public class DiskSpaceResource : RestResource
{
public string DriveLetter { get; set; }
public string FreeSpace { get; set; }
public string TotalSpace { get; set; }
}
}

@ -87,6 +87,8 @@
<Compile Include="Commands\CommandResource.cs" />
<Compile Include="Config\NamingConfigResource.cs" />
<Compile Include="Config\NamingModule.cs" />
<Compile Include="DiskSpace\DiskSpaceModule.cs" />
<Compile Include="DiskSpace\DiskSpaceResource.cs" />
<Compile Include="EpisodeFiles\EpisodeFileModule.cs" />
<Compile Include="EpisodeFiles\EpisodeFileResource.cs" />
<Compile Include="Directories\DirectoryLookupService.cs" />

@ -0,0 +1,8 @@
'use strict';
define(['backbone', 'System/DiskSpace/DiskSpaceModel'],
function(Backbone, DiskSpaceModel) {
return Backbone.Collection.extend({
url:window.NzbDrone.ApiRoot +'/diskspace',
model: DiskSpaceModel
});
});

@ -0,0 +1,59 @@
'use strict';
define([
'vent',
'marionette',
'backgrid',
'System/DiskSpace/DiskSpaceCollection',
'Shared/LoadingView'
], function (vent,Marionette,Backgrid,DiskSpaceCollection,LoadingView) {
return Marionette.Layout.extend({
template: 'System/DiskSpace/DiskSpaceTemplate',
regions: {
grid: '#x-grid'
},
columns:
[
{
name: 'driveLetter',
label: 'Drive',
cell: Backgrid.StringCell
},
{
name: 'freeSpace',
label: 'Free Space',
cell: Backgrid.StringCell
},
{
name: 'totalSpace',
label: 'Total Space',
cell: Backgrid.StringCell
}
],
initialize: function () {
this.collection = new DiskSpaceCollection();
this.collectionPromise = this.collection.fetch();
vent.on(vent.Events.CommandComplete, this._commandComplete, this);
},
onRender : function() {
this.grid.show(new LoadingView());
},
onShow: function() {
var self = this;
this.collectionPromise.done(function() {
self._showTable();
});
},
_showTable: function() {
this.grid.show(new Backgrid.Grid({
row: Backgrid.Row,
columns: this.columns,
collection: this.collection,
className:'table table-hover'
}));
}
});
});

@ -0,0 +1,6 @@
'use strict';
define(['backbone'], function (Backbone) {
return Backbone.Model.extend({
});
});

@ -0,0 +1,5 @@
<div class="row">
<div class="span10">
<div id="x-grid"/>
</div>
</div>

@ -5,31 +5,36 @@ define(
'marionette',
'System/About/AboutView',
'System/Logs/LogsLayout',
'System/Update/UpdateLayout'
'System/Update/UpdateLayout',
'System/DiskSpace/DiskSpaceLayout'
], function (Backbone,
Marionette,
AboutView,
LogsLayout,
UpdateLayout) {
UpdateLayout,
DiskSpaceLayout) {
return Marionette.Layout.extend({
template: 'System/SystemLayoutTemplate',
regions: {
about : '#about',
logs : '#logs',
updates : '#updates'
updates: '#updates',
diskSpace: '#diskspace'
},
ui: {
aboutTab : '.x-about-tab',
logsTab : '.x-logs-tab',
updatesTab: '.x-updates-tab'
updatesTab: '.x-updates-tab',
diskSpaceTab: '.x-diskspace-tab'
},
events: {
'click .x-about-tab' : '_showAbout',
'click .x-logs-tab' : '_showLogs',
'click .x-updates-tab': '_showUpdates'
'click .x-updates-tab': '_showUpdates',
'click .x-diskspace-tab':'_showDiskSpace'
},
initialize: function (options) {
@ -46,6 +51,8 @@ define(
case 'updates':
this._showUpdates();
break;
case 'diskspace':
this._showDiskSpace();
default:
this._showAbout();
}
@ -83,6 +90,14 @@ define(
this.updates.show(new UpdateLayout());
this.ui.updatesTab.tab('show');
this._navigate('system/updates');
},
_showDiskSpace: function (e) {
if (e) {
e.preventDefault();
}
this.diskSpace.show(new DiskSpaceLayout());
this.ui.diskSpaceTab.tab('show');
this._navigate("system/diskspace");
}
});
});

@ -2,10 +2,12 @@
<li><a href="#about" class="x-about-tab no-router">About</a></li>
<li><a href="#logs" class="x-logs-tab no-router">Logs</a></li>
<li><a href="#updates" class="x-updates-tab no-router">Updates</a></li>
<li><a href="#diskspace" class="x-diskspace-tab no-router">Disk Space</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="about"></div>
<div class="tab-pane" id="logs"></div>
<div class="tab-pane" id="updates"></div>
<div class="tab-pane" id="diskspace"></div>
</div>
Loading…
Cancel
Save