Added new helper to find the best file size format given a long with file size in bytes.

Added view under system to see which folders have not been processed in dropDir.
pull/3113/head
Mark McDowall 13 years ago
parent cea511a460
commit 54e7092e2d

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Helpers
{
public class FileSizeFormatHelper
{
private const Decimal OneKiloByte = 1024M;
private const Decimal OneMegaByte = OneKiloByte * 1024M;
private const Decimal OneGigaByte = OneMegaByte * 1024M;
public static string Format(long bytes, int precision)
{
if (bytes == 0)
return "0B";
decimal size = Convert.ToDecimal(bytes);
string suffix;
if (size > OneGigaByte)
{
size /= OneGigaByte;
suffix = "GB";
}
else if (size > OneMegaByte)
{
size /= OneMegaByte;
suffix = "MB";
}
else if (size > OneKiloByte)
{
size /= OneKiloByte;
suffix = "KB";
}
else
{
suffix = " B";
}
return String.Format("{0:N" + precision + "}{1}", size, suffix);
}
}
}

@ -167,6 +167,7 @@
<Compile Include="Datastore\SqliteProvider.cs" />
<Compile Include="Helpers\EpisodeRenameHelper.cs" />
<Compile Include="Helpers\EpisodeSortingHelper.cs" />
<Compile Include="Helpers\FileSizeFormatHelpercs.cs" />
<Compile Include="Helpers\SceneNameHelper.cs" />
<Compile Include="Instrumentation\LogProvider.cs" />
<Compile Include="Instrumentation\SubsonicTarget.cs" />

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace NzbDrone.Core.Providers.Core
{
@ -56,5 +58,20 @@ namespace NzbDrone.Core.Providers.Core
{
Directory.Delete(path, recursive);
}
public virtual DateTime DirectoryDateCreated(string path)
{
return Directory.GetCreationTime(path);
}
public virtual IEnumerable<FileInfo> GetFileInfos(string path, string pattern, SearchOption searchOption)
{
return new DirectoryInfo(path).GetFiles(pattern, searchOption);
}
public virtual void MoveDirectory(string source, string destination)
{
Directory.Move(source, destination);
}
}
}

@ -1,7 +1,12 @@
using System.Web.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Mvc;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Web.Models;
using Telerik.Web.Mvc;
namespace NzbDrone.Web.Controllers
@ -11,12 +16,14 @@ namespace NzbDrone.Web.Controllers
private readonly JobProvider _jobProvider;
private readonly IndexerProvider _indexerProvider;
private readonly ConfigProvider _configProvider;
private readonly DiskProvider _diskProvider;
public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider, ConfigProvider configProvider)
public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider, ConfigProvider configProvider, DiskProvider diskProvider)
{
_jobProvider = jobProvider;
_indexerProvider = indexerProvider;
_configProvider = configProvider;
_diskProvider = diskProvider;
}
public ActionResult Jobs()
@ -58,5 +65,64 @@ namespace NzbDrone.Web.Controllers
_configProvider.SetValue(key, value);
return View(new GridModel(_configProvider.All()));
}
//PostDownloadView
public ActionResult PendingProcessing()
{
ViewData["DropDir"] = _configProvider.SabDropDirectory;
return View();
}
[GridAction]
public ActionResult _PendingProcessingAjaxBinding()
{
var dropDir = _configProvider.SabDropDirectory;
var subFolders = _diskProvider.GetDirectories(dropDir);
var models = new List<PendingProcessingModel>();
//Get the CreationTime and Files
foreach (var folder in subFolders)
{
var model = new PendingProcessingModel();
model.Name = new DirectoryInfo(folder).Name;
model.Created = _diskProvider.DirectoryDateCreated(folder);
model.Path = folder.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`');
var files = _diskProvider.GetFileInfos(folder, "*.*", SearchOption.AllDirectories);
var fileResult = "<div><div style=\"width: 600px; display: inline-block;\"><b>Name</b></div><div style=\"display: inline-block;\"><b>Size</b></div></div>";
foreach (var fileInfo in files)
{
fileResult += String.Format("<div><div style=\"width: 600px; display: inline-block;\">{0}</div><div style=\"display: inline-block;\">{1}</div></div>", fileInfo.Name,
FileSizeFormatHelper.Format(fileInfo.Length, 1));
}
model.Files = fileResult;
models.Add(model);
}
return View(new GridModel(models));
}
public JsonResult RenamePendingProcessing(string path)
{
path = path.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace('`', '\'');
var di = new DirectoryInfo(path);
var dropDir = di.Parent.FullName;
var folder = di.Name;
if (!folder.StartsWith("_UNPACK_") && !folder.StartsWith("_FAILED_"))
return new JsonResult { Data = "no change" };
folder = folder.Substring(8);
var newPath = dropDir + Path.DirectorySeparatorChar + folder;
_diskProvider.MoveDirectory(path, newPath);
return new JsonResult { Data = "ok" };
}
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NzbDrone.Web.Models
{
public class PendingProcessingModel
{
public string Name { get; set; }
public string Files { get; set; }
public DateTime Created { get; set; }
public string Path { get; set; }
}
}

@ -259,6 +259,7 @@
<Compile Include="Models\AddExistingManualModel.cs" />
<Compile Include="Models\AddExistingSeriesModel.cs" />
<Compile Include="Models\AddNewSeriesModel.cs" />
<Compile Include="Models\PendingProcessingModel.cs" />
<Compile Include="Models\QualityTypeModel.cs" />
<Compile Include="Models\RootDirModel.cs" />
<Compile Include="Models\SabnzbdSettingsModel.cs" />
@ -897,6 +898,9 @@
<ItemGroup>
<Content Include="Views\AddSeries\AddExisting.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\System\PendingProcessing.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

@ -0,0 +1,60 @@
@model List<NzbDrone.Web.Models.PendingProcessingModel>
@using NzbDrone.Web.Models
@section TitleContent{
Pending Processing
}
@section ActionMenu{
@{Html.Telerik().Menu().Name("historyMenu").Items(items =>
{
items.Add().Text("Trim History").Action("Trim", "History");
items.Add().Text("Purge History").Action("Purge", "History");
}).Render();}
}
@section MainContent{
<div class="grid-container">
@{Html.Telerik().Grid<PendingProcessingModel>().Name("PendingProcessingGrid")
.TableHtmlAttributes(new { @class = "Grid" })
.Columns(columns =>
{
columns.Bound(c => c.Name);
columns.Bound(c => c.Created).Title("Creation Date");
columns.Bound(c => c.Path).Title("")
.ClientTemplate("<a href='#Rename' onClick=\"renamePending('<#= Path #>'); return false;\">Rename</a>");
})
.DetailView(detailView => detailView.ClientTemplate(
"<div><#= Files #></div>"
))
.DataBinding(data => data.Ajax().Select("_PendingProcessingAjaxBinding", "System"))
.Sortable(rows => rows.OrderBy(epSort => epSort.Add(c => c.Name).Ascending()).Enabled(true))
.Pageable(
c =>
c.PageSize(20).Position(GridPagerPosition.Bottom).Style(GridPagerStyles.NextPrevious))
.ClientEvents(clientEvents =>
{
clientEvents.OnDataBinding("grid_bind");
clientEvents.OnDataBound("grid_bound");
})
.Render();}
<span class="grid-loader"><img src="@Url.Content( "~/Content/Images/Loading.gif" )" alt="Loading"/> Loading...</span>
</div>
}
<script type="text/javascript">
var renamePendingUrl = '@Url.Action("RenamePendingProcessing", "System")';
function renamePending(path) {
$.ajax({
type: "POST",
url: renamePendingUrl,
data: jQuery.param({ path: path }),
error: function (req, status, error) {
alert("Sorry! We could rename " + name + " at this time. " + error);
},
success: function (data, textStatus, jqXHR) {
if (data == "ok") {
var grid = $('#PendingProcessingGrid').data('tGrid');
grid.ajaxRequest();
}
}
});
}
</script>
Loading…
Cancel
Save