Merge branch 'diskspace' into develop

This commit is contained in:
Mark McDowall 2013-10-13 08:58:39 -07:00
commit 1689aa4f64
17 changed files with 235 additions and 23 deletions

22
.gitattributes vendored Normal file
View File

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

View File

@ -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<DiskSpaceResource>
{
private readonly IDiskProvider _diskProvider;
public DiskSpaceModule(IDiskProvider diskProvider):base("diskspace")
{
_diskProvider = diskProvider;
GetResourceAll = GetFreeSpace;
}
public List<DiskSpaceResource> 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]);
}
}
}

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 Int64 FreeSpace { get; set; }
public Int64 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

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

View File

@ -22,7 +22,7 @@ define(
delete xhr.data;
}
if (xhr) {
xhr.headers = xhr.headers || {};
xhr.headers.Authorization = window.NzbDrone.ApiKey;

View File

@ -1,8 +0,0 @@
<dl class="dl-horizontal">
<dt>Version</dt>
<dd>{{version}}</dd>
<dt>AppData directory</dt>
<dd>{{appData}}</dd>
<dt>Startup directory</dt>
<dd>{{startupPath}}</dd>
</dl>

View File

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

View File

@ -0,0 +1,13 @@
<fieldset>
<legend>About</legend>
<dl class="dl-horizontal">
<dt>Version</dt>
<dd>{{version}}</dd>
<dt>AppData directory</dt>
<dd>{{appData}}</dd>
<dt>Startup directory</dt>
<dd>{{startupPath}}</dd>
</dl>
</fieldset>

View File

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

View File

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

View File

@ -0,0 +1,5 @@
<fieldset>
<legend>Disk Space</legend>
<div id="x-grid"/>
</fieldset>

View File

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

View File

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

View File

@ -0,0 +1,7 @@
<div class="row">
<div class="span12" id="about"></div>
</div>
<div class="row">
<div class="span12" id="diskspace"></div>
</div>

View File

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

View File

@ -1,11 +1,11 @@
<ul class="nav nav-tabs">
<li><a href="#about" class="x-about-tab no-router">About</a></li>
<li><a href="#info" class="x-info-tab no-router">Info</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>
</ul>
<div class="tab-content">
<div class="tab-pane" id="about"></div>
<div class="tab-pane" id="info"></div>
<div class="tab-pane" id="logs"></div>
<div class="tab-pane" id="updates"></div>
</div>