mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
parent
30bcc662bc
commit
07b70f9d3f
@ -8,13 +8,15 @@ namespace NzbDrone.Common.Test.ExtensionTests
|
|||||||
public class Int64ExtensionFixture
|
public class Int64ExtensionFixture
|
||||||
{
|
{
|
||||||
[TestCase(0, "0 B")]
|
[TestCase(0, "0 B")]
|
||||||
[TestCase(1000, "1.0 KB")]
|
[TestCase(1000, "1,000.0 B")]
|
||||||
[TestCase(1000000, "1.0 MB")]
|
[TestCase(1024, "1.0 KB")]
|
||||||
[TestCase(377487360, "377.5 MB")]
|
[TestCase(1000000, "976.6 KB")]
|
||||||
[TestCase(1255864686, "1.3 GB")]
|
[TestCase(377487360, "360.0 MB")]
|
||||||
[TestCase(-1000000, "-1.0 MB")]
|
[TestCase(1255864686, "1.2 GB")]
|
||||||
[TestCase(-377487360, "-377.5 MB")]
|
[TestCase(-1024, "-1.0 KB")]
|
||||||
[TestCase(-1255864686, "-1.3 GB")]
|
[TestCase(-1000000, "-976.6 KB")]
|
||||||
|
[TestCase(-377487360, "-360.0 MB")]
|
||||||
|
[TestCase(-1255864686, "-1.2 GB")]
|
||||||
public void should_calculate_string_correctly(long bytes, string expected)
|
public void should_calculate_string_correctly(long bytes, string expected)
|
||||||
{
|
{
|
||||||
bytes.SizeSuffix().Should().Be(expected);
|
bytes.SizeSuffix().Should().Be(expected);
|
||||||
|
@ -9,7 +9,7 @@ public static class Int64Extensions
|
|||||||
|
|
||||||
public static string SizeSuffix(this Int64 bytes)
|
public static string SizeSuffix(this Int64 bytes)
|
||||||
{
|
{
|
||||||
const int bytesInKb = 1000;
|
const int bytesInKb = 1024;
|
||||||
|
|
||||||
if (bytes < 0) return "-" + SizeSuffix(-bytes);
|
if (bytes < 0) return "-" + SizeSuffix(-bytes);
|
||||||
if (bytes == 0) return "0 B";
|
if (bytes == 0) return "0 B";
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
var NzbDroneCell = require('../../Cells/NzbDroneCell');
|
var NzbDroneCell = require('../../Cells/NzbDroneCell');
|
||||||
var fileSize = require('filesize');
|
|
||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
var UiSettingsModel = require('../../Shared/UiSettingsModel');
|
var UiSettingsModel = require('../../Shared/UiSettingsModel');
|
||||||
var FormatHelpers = require('../../Shared/FormatHelpers');
|
var FormatHelpers = require('../../Shared/FormatHelpers');
|
||||||
@ -19,8 +18,8 @@ module.exports = NzbDroneCell.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
var timeleft = this.cellValue.get('timeleft');
|
var timeleft = this.cellValue.get('timeleft');
|
||||||
var totalSize = fileSize(this.cellValue.get('size'), 1, false);
|
var totalSize = FormatHelpers.bytes(this.cellValue.get('size'), 2);
|
||||||
var remainingSize = fileSize(this.cellValue.get('sizeleft'), 1, false);
|
var remainingSize = FormatHelpers.bytes(this.cellValue.get('sizeleft'), 2);
|
||||||
|
|
||||||
if (timeleft === undefined) {
|
if (timeleft === undefined) {
|
||||||
this.$el.html('-');
|
this.$el.html('-');
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
var Marionette = require('marionette');
|
var Marionette = require('marionette');
|
||||||
var AsModelBoundView = require('../../../Mixins/AsModelBoundView');
|
var AsModelBoundView = require('../../../Mixins/AsModelBoundView');
|
||||||
var fileSize = require('filesize');
|
|
||||||
require('jquery-ui');
|
require('jquery-ui');
|
||||||
|
var FormatHelpers = require('../../../Shared/FormatHelpers');
|
||||||
|
|
||||||
var view = Marionette.ItemView.extend({
|
var view = Marionette.ItemView.extend({
|
||||||
template : 'Settings/Quality/Definition/QualityDefinitionItemViewTemplate',
|
template : 'Settings/Quality/Definition/QualityDefinitionItemViewTemplate',
|
||||||
@ -27,7 +27,6 @@ var view = Marionette.ItemView.extend({
|
|||||||
|
|
||||||
initialize : function(options) {
|
initialize : function(options) {
|
||||||
this.profileCollection = options.profiles;
|
this.profileCollection = options.profiles;
|
||||||
this.filesize = fileSize;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onRender : function() {
|
onRender : function() {
|
||||||
@ -66,11 +65,10 @@ var view = Marionette.ItemView.extend({
|
|||||||
_changeSize : function() {
|
_changeSize : function() {
|
||||||
var minSize = this.model.get('minSize') || this.slider.min;
|
var minSize = this.model.get('minSize') || this.slider.min;
|
||||||
var maxSize = this.model.get('maxSize') || null;
|
var maxSize = this.model.get('maxSize') || null;
|
||||||
|
|
||||||
{
|
{
|
||||||
var minBytes = minSize * 1024 * 1024;
|
var minBytes = minSize * 1024 * 1024;
|
||||||
var minThirty = fileSize(minBytes * 30, 1, false);
|
var minThirty = FormatHelpers.bytes(minBytes * 30, 2);
|
||||||
var minSixty = fileSize(minBytes * 60, 1, false);
|
var minSixty = FormatHelpers.bytes(minBytes * 60, 2);
|
||||||
|
|
||||||
this.ui.thirtyMinuteMinSize.html(minThirty);
|
this.ui.thirtyMinuteMinSize.html(minThirty);
|
||||||
this.ui.sixtyMinuteMinSize.html(minSixty);
|
this.ui.sixtyMinuteMinSize.html(minSixty);
|
||||||
@ -82,8 +80,8 @@ var view = Marionette.ItemView.extend({
|
|||||||
this.ui.sixtyMinuteMaxSize.html('Unlimited');
|
this.ui.sixtyMinuteMaxSize.html('Unlimited');
|
||||||
} else {
|
} else {
|
||||||
var maxBytes = maxSize * 1024 * 1024;
|
var maxBytes = maxSize * 1024 * 1024;
|
||||||
var maxThirty = fileSize(maxBytes * 30, 1, false);
|
var maxThirty = FormatHelpers.bytes(maxBytes * 30, 2);
|
||||||
var maxSixty = fileSize(maxBytes * 60, 1, false);
|
var maxSixty = FormatHelpers.bytes(maxBytes * 60, 2);
|
||||||
|
|
||||||
this.ui.thirtyMinuteMaxSize.html(maxThirty);
|
this.ui.thirtyMinuteMaxSize.html(maxThirty);
|
||||||
this.ui.sixtyMinuteMaxSize.html(maxSixty);
|
this.ui.sixtyMinuteMaxSize.html(maxSixty);
|
||||||
|
@ -3,16 +3,21 @@ var filesize = require('filesize');
|
|||||||
var UiSettings = require('./UiSettingsModel');
|
var UiSettings = require('./UiSettingsModel');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
bytes : function(sourceSize) {
|
bytes : function(sourceSize, sourceRounding) {
|
||||||
var size = Number(sourceSize);
|
var size = Number(sourceSize);
|
||||||
|
var rounding = Number(sourceRounding);
|
||||||
|
|
||||||
if (isNaN(size)) {
|
if (isNaN(size)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNaN(rounding)) {
|
||||||
|
rounding = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return filesize(size, {
|
return filesize(size, {
|
||||||
base : 2,
|
base : 2,
|
||||||
round : 1
|
round : rounding
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user