diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..1b274cb93 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +*text eol=lf + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain \ No newline at end of file diff --git a/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs b/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs new file mode 100644 index 000000000..0126d84fd --- /dev/null +++ b/src/NzbDrone.Api/DiskSpace/DiskSpaceModule.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using NzbDrone.Common; + +namespace NzbDrone.Api.DiskSpace +{ + public class DiskSpaceModule :NzbDroneRestModule + { + private readonly IDiskProvider _diskProvider; + + public DiskSpaceModule(IDiskProvider diskProvider):base("diskspace") + { + _diskProvider = diskProvider; + GetResourceAll = GetFreeSpace; + } + + public List GetFreeSpace() + { + return (_diskProvider.GetFixedDrives() + .Select( + x => + new DiskSpaceResource() + { + DriveLetter = x, + FreeSpace = _diskProvider.GetAvailableSpace(x).Value, + TotalSpace = _diskProvider.GetTotalSize(x).Value + })).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..261ae6305 --- /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 Int64 FreeSpace { get; set; } + public Int64 TotalSpace { get; set; } + } +} diff --git a/src/NzbDrone.Api/NzbDrone.Api.csproj b/src/NzbDrone.Api/NzbDrone.Api.csproj index 653555dd9..2227fbe11 100644 --- a/src/NzbDrone.Api/NzbDrone.Api.csproj +++ b/src/NzbDrone.Api/NzbDrone.Api.csproj @@ -87,6 +87,8 @@ + + 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/Mixins/jquery.ajax.js b/src/UI/Mixins/jquery.ajax.js index 0a932e6c2..0fe0b047f 100644 --- a/src/UI/Mixins/jquery.ajax.js +++ b/src/UI/Mixins/jquery.ajax.js @@ -22,7 +22,7 @@ define( delete xhr.data; } - + if (xhr) { xhr.headers = xhr.headers || {}; xhr.headers.Authorization = window.NzbDrone.ApiKey; diff --git a/src/UI/System/About/AboutViewTemplate.html b/src/UI/System/About/AboutViewTemplate.html deleted file mode 100644 index efe394569..000000000 --- a/src/UI/System/About/AboutViewTemplate.html +++ /dev/null @@ -1,8 +0,0 @@ -
-
Version
-
{{version}}
-
AppData directory
-
{{appData}}
-
Startup directory
-
{{startupPath}}
-
diff --git a/src/UI/System/About/AboutView.js b/src/UI/System/Info/About/AboutView.js similarity index 82% rename from src/UI/System/About/AboutView.js rename to src/UI/System/Info/About/AboutView.js index f87b8758e..b1133db1a 100644 --- a/src/UI/System/About/AboutView.js +++ b/src/UI/System/Info/About/AboutView.js @@ -5,7 +5,7 @@ define( 'System/StatusModel' ], function (Marionette, StatusModel) { return Marionette.ItemView.extend({ - template: 'System/About/AboutViewTemplate', + template: 'System/Info/About/AboutViewTemplate', initialize: function () { this.model = StatusModel; diff --git a/src/UI/System/Info/About/AboutViewTemplate.html b/src/UI/System/Info/About/AboutViewTemplate.html new file mode 100644 index 000000000..57c32bc4e --- /dev/null +++ b/src/UI/System/Info/About/AboutViewTemplate.html @@ -0,0 +1,13 @@ +
+ About + +
+
Version
+
{{version}}
+
AppData directory
+
{{appData}}
+
Startup directory
+
{{startupPath}}
+
+
+ diff --git a/src/UI/System/Info/DiskSpace/DiskSpaceCollection.js b/src/UI/System/Info/DiskSpace/DiskSpaceCollection.js new file mode 100644 index 000000000..b65238704 --- /dev/null +++ b/src/UI/System/Info/DiskSpace/DiskSpaceCollection.js @@ -0,0 +1,8 @@ +'use strict'; +define(['backbone', 'System/Info/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/Info/DiskSpace/DiskSpaceLayout.js b/src/UI/System/Info/DiskSpace/DiskSpaceLayout.js new file mode 100644 index 000000000..9a8ef6026 --- /dev/null +++ b/src/UI/System/Info/DiskSpace/DiskSpaceLayout.js @@ -0,0 +1,57 @@ +'use strict'; +define([ + 'vent', + 'marionette', + 'backgrid', + 'System/Info/DiskSpace/DiskSpaceCollection', + 'Shared/LoadingView', + 'Cells/FileSizeCell' +], function (vent,Marionette,Backgrid,DiskSpaceCollection,LoadingView,FileSizeCell) { + return Marionette.Layout.extend({ + template: 'System/Info/DiskSpace/DiskSpaceLayoutTemplate', + + regions: { + grid: '#x-grid' + }, + columns: + [ + { + name: 'driveLetter', + label: 'Drive', + cell: 'string' + }, + { + name: 'freeSpace', + label: 'Free Space', + cell: FileSizeCell, + sortable:true + }, + { + name: 'totalSpace', + label: 'Total Space', + cell: FileSizeCell, + sortable:true + } + ], + + initialize: function () { + this.collection = new DiskSpaceCollection(); + this.listenTo(this.collection, 'sync', this._showTable); + }, + onRender : function() { + this.grid.show(new LoadingView()); + }, + + onShow: function() { + this.collection.fetch(); + }, + _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/Info/DiskSpace/DiskSpaceLayoutTemplate.html b/src/UI/System/Info/DiskSpace/DiskSpaceLayoutTemplate.html new file mode 100644 index 000000000..6cf4d34e3 --- /dev/null +++ b/src/UI/System/Info/DiskSpace/DiskSpaceLayoutTemplate.html @@ -0,0 +1,5 @@ +
+ Disk Space + +
+
\ No newline at end of file diff --git a/src/UI/System/Info/DiskSpace/DiskSpaceModel.js b/src/UI/System/Info/DiskSpace/DiskSpaceModel.js new file mode 100644 index 000000000..1e80926fc --- /dev/null +++ b/src/UI/System/Info/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/Info/SystemInfoLayout.js b/src/UI/System/Info/SystemInfoLayout.js new file mode 100644 index 000000000..e415c6d8d --- /dev/null +++ b/src/UI/System/Info/SystemInfoLayout.js @@ -0,0 +1,26 @@ +'use strict'; +define( + [ + 'backbone', + 'marionette', + 'System/Info/About/AboutView', + 'System/Info/DiskSpace/DiskSpaceLayout' + ], function (Backbone, + Marionette, + AboutView, + DiskSpaceLayout) { + return Marionette.Layout.extend({ + template: 'System/Info/SystemInfoLayoutTemplate', + + regions: { + about : '#about', + diskSpace: '#diskspace' + }, + + onRender: function () { + this.about.show(new AboutView()); + this.diskSpace.show(new DiskSpaceLayout()); + } + }); + }); + diff --git a/src/UI/System/Info/SystemInfoLayoutTemplate.html b/src/UI/System/Info/SystemInfoLayoutTemplate.html new file mode 100644 index 000000000..74ba09bf2 --- /dev/null +++ b/src/UI/System/Info/SystemInfoLayoutTemplate.html @@ -0,0 +1,7 @@ +
+
+
+ +
+
+
\ No newline at end of file diff --git a/src/UI/System/SystemLayout.js b/src/UI/System/SystemLayout.js index 7aca9042f..29c06d43b 100644 --- a/src/UI/System/SystemLayout.js +++ b/src/UI/System/SystemLayout.js @@ -3,31 +3,31 @@ define( [ 'backbone', 'marionette', - 'System/About/AboutView', + 'System/Info/SystemInfoLayout', 'System/Logs/LogsLayout', 'System/Update/UpdateLayout' ], function (Backbone, Marionette, - AboutView, + SystemInfoLayout, LogsLayout, UpdateLayout) { return Marionette.Layout.extend({ template: 'System/SystemLayoutTemplate', regions: { - about : '#about', + info : '#info', logs : '#logs', - updates : '#updates' + updates: '#updates' }, ui: { - aboutTab : '.x-about-tab', + infoTab : '.x-info-tab', logsTab : '.x-logs-tab', updatesTab: '.x-updates-tab' }, events: { - 'click .x-about-tab' : '_showAbout', + 'click .x-info-tab' : '_showInfo', 'click .x-logs-tab' : '_showLogs', 'click .x-updates-tab': '_showUpdates' }, @@ -47,7 +47,7 @@ define( this._showUpdates(); break; default: - this._showAbout(); + this._showInfo(); } }, @@ -55,14 +55,14 @@ define( Backbone.history.navigate(route); }, - _showAbout: function (e) { + _showInfo: function (e) { if (e) { e.preventDefault(); } - this.about.show(new AboutView()); - this.ui.aboutTab.tab('show'); - this._navigate('system/about'); + this.info.show(new SystemInfoLayout()); + this.ui.infoTab.tab('show'); + this._navigate('system/info'); }, _showLogs: function (e) { diff --git a/src/UI/System/SystemLayoutTemplate.html b/src/UI/System/SystemLayoutTemplate.html index bddcf83b0..d95a3996b 100644 --- a/src/UI/System/SystemLayoutTemplate.html +++ b/src/UI/System/SystemLayoutTemplate.html @@ -1,11 +1,11 @@ 
-
+
\ No newline at end of file