From 041e767f3dc5f27e9b15b79021839c3b9644c83c Mon Sep 17 00:00:00 2001 From: fzr600dave Date: Thu, 10 Oct 2013 23:31:44 +0100 Subject: [PATCH] Added Disk space information to system. (cherry picked from commit 91625019378247b1c6ab85afaee23f2855e3298b) --- src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs | 43 ++++++++++++++ .../DiskSpace/DiskSpaceResource.cs | 15 +++++ src/NzbDrone.Api/NzbDrone.Api.csproj | 2 + .../System/DiskSpace/DiskSpaceCollection.js | 8 +++ src/UI/System/DiskSpace/DiskSpaceLayout.js | 59 +++++++++++++++++++ src/UI/System/DiskSpace/DiskSpaceModel.js | 6 ++ .../System/DiskSpace/DiskSpaceTemplate.html | 5 ++ src/UI/System/SystemLayout.js | 25 ++++++-- src/UI/System/SystemLayoutTemplate.html | 2 + 9 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs create mode 100644 src/NzbDrone.Api/DiskSpace/DiskSpaceResource.cs create mode 100644 src/UI/System/DiskSpace/DiskSpaceCollection.js create mode 100644 src/UI/System/DiskSpace/DiskSpaceLayout.js create mode 100644 src/UI/System/DiskSpace/DiskSpaceModel.js create mode 100644 src/UI/System/DiskSpace/DiskSpaceTemplate.html diff --git a/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs b/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs new file mode 100644 index 000000000..98c16934f --- /dev/null +++ b/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs @@ -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 + { + public DiskSpaceModule():base("diskspace") + { + GetResourceAll = GetFreeSpace; + } + public List 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]); + } + } +} diff --git a/src/NzbDrone.Api/DiskSpace/DiskSpaceResource.cs b/src/NzbDrone.Api/DiskSpace/DiskSpaceResource.cs new file mode 100644 index 000000000..8d3796051 --- /dev/null +++ b/src/NzbDrone.Api/DiskSpace/DiskSpaceResource.cs @@ -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; } + } +} diff --git a/src/NzbDrone.Api/NzbDrone.Api.csproj b/src/NzbDrone.Api/NzbDrone.Api.csproj index 7b885fe48..e7ebe0bbe 100644 --- a/src/NzbDrone.Api/NzbDrone.Api.csproj +++ b/src/NzbDrone.Api/NzbDrone.Api.csproj @@ -87,6 +87,8 @@ + + diff --git a/src/UI/System/DiskSpace/DiskSpaceCollection.js b/src/UI/System/DiskSpace/DiskSpaceCollection.js new file mode 100644 index 000000000..27fb20225 --- /dev/null +++ b/src/UI/System/DiskSpace/DiskSpaceCollection.js @@ -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 + }); +}); \ No newline at end of file diff --git a/src/UI/System/DiskSpace/DiskSpaceLayout.js b/src/UI/System/DiskSpace/DiskSpaceLayout.js new file mode 100644 index 000000000..1db1049fd --- /dev/null +++ b/src/UI/System/DiskSpace/DiskSpaceLayout.js @@ -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' + })); + } + }); +}); \ No newline at end of file diff --git a/src/UI/System/DiskSpace/DiskSpaceModel.js b/src/UI/System/DiskSpace/DiskSpaceModel.js new file mode 100644 index 000000000..1e80926fc --- /dev/null +++ b/src/UI/System/DiskSpace/DiskSpaceModel.js @@ -0,0 +1,6 @@ +'use strict'; +define(['backbone'], function (Backbone) { + return Backbone.Model.extend({ + + }); +}); \ No newline at end of file diff --git a/src/UI/System/DiskSpace/DiskSpaceTemplate.html b/src/UI/System/DiskSpace/DiskSpaceTemplate.html new file mode 100644 index 000000000..f640d03e9 --- /dev/null +++ b/src/UI/System/DiskSpace/DiskSpaceTemplate.html @@ -0,0 +1,5 @@ +
+
+
+
+
\ No newline at end of file diff --git a/src/UI/System/SystemLayout.js b/src/UI/System/SystemLayout.js index 7aca9042f..431f55e3b 100644 --- a/src/UI/System/SystemLayout.js +++ b/src/UI/System/SystemLayout.js @@ -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"); } }); }); diff --git a/src/UI/System/SystemLayoutTemplate.html b/src/UI/System/SystemLayoutTemplate.html index bddcf83b0..3eb712314 100644 --- a/src/UI/System/SystemLayoutTemplate.html +++ b/src/UI/System/SystemLayoutTemplate.html @@ -2,10 +2,12 @@
  • About
  • Logs
  • Updates
  • +
  • Disk Space
  • +
    \ No newline at end of file