1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 07:22:35 +01:00

Added Disk space information to system.

(cherry picked from commit 9162501937)
This commit is contained in:
fzr600dave 2013-10-10 23:31:44 +01:00 committed by Mark McDowall
parent 4510ca8fa1
commit 041e767f3d
9 changed files with 160 additions and 5 deletions

View File

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

View File

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

View File

@ -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" />

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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