mirror of
https://github.com/webmin/webmin.git
synced 2026-05-04 22:30:33 +01:00
Nice size field for new LVs
This commit is contained in:
@@ -21,6 +21,7 @@ else {
|
||||
'is_snap' => $in{'snap'},
|
||||
'size' => ($vg->{'pe_total'} - $vg->{'pe_alloc'})*
|
||||
$vg->{'pe_size'} };
|
||||
$lv->{'size'} = &nice_round($lv->{'size'});
|
||||
}
|
||||
|
||||
print &ui_form_start("save_lv.cgi");
|
||||
@@ -40,8 +41,16 @@ else {
|
||||
print &ui_table_row($text{'lv_name'},
|
||||
&ui_textbox("name", $lv->{'name'}, 20));
|
||||
|
||||
print &ui_table_row($text{'lv_size'},
|
||||
&ui_textbox("size", $lv->{'size'}, 8)." kB");
|
||||
if (!$in{'lv'}) {
|
||||
# Can show nice size chooser
|
||||
print &ui_table_row($text{'lv_size'},
|
||||
&ui_bytesbox("size", $lv->{'size'}*1024, 8));
|
||||
}
|
||||
else {
|
||||
# Show in exactly kB
|
||||
print &ui_table_row($text{'lv_size'},
|
||||
&ui_textbox("size", $lv->{'size'}, 8)." kB");
|
||||
}
|
||||
}
|
||||
|
||||
# Number of physical extents
|
||||
|
||||
@@ -657,5 +657,29 @@ local $ver = $out =~ /\s+([0-9\.]+)/ ? $1 : undef;
|
||||
return wantarray ? ( $ver, $out ) : $ver;
|
||||
}
|
||||
|
||||
# nice_round(number)
|
||||
# Round some number to TB, GB, MB or kB, depending on size
|
||||
sub nice_round
|
||||
{
|
||||
local ($bytes) = @_;
|
||||
my $units;
|
||||
if ($bytes >= 10*1024*1024*1024*1024) {
|
||||
$units = 1024*1024*1024*1024;
|
||||
}
|
||||
elsif ($bytes >= 10*1024*1024*1024) {
|
||||
$units = 1024*1024*1024;
|
||||
}
|
||||
elsif ($bytes >= 10*1024*1024) {
|
||||
$units = 1024*1024;
|
||||
}
|
||||
elsif ($bytes >= 10*1024) {
|
||||
$units = 1024;
|
||||
}
|
||||
else {
|
||||
$units = 1;
|
||||
}
|
||||
return int($bytes / $units) * $units;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
@@ -40,6 +40,11 @@ else {
|
||||
$same && (!$in{'lv'} || $in{'lv'} ne $in{'name'}) &&
|
||||
&error($text{'lv_esame'});
|
||||
$in{'size'} =~ /^\d+$/ || &error($text{'lv_esize'});
|
||||
if (defined($in{'size_units'})) {
|
||||
# Convert selected units to kB
|
||||
$in{'size'} = $in{'size'}*$in{'size_units'}/1024;
|
||||
delete($in{'size_units'});
|
||||
}
|
||||
$in{'snap'} || $in{'lv'} || $in{'stripe_def'} ||
|
||||
$in{'stripe'} =~ /^[1-9]\d*$/ || &error($text{'lv_estripe'});
|
||||
|
||||
|
||||
12
ui-lib.pl
12
ui-lib.pl
@@ -466,7 +466,10 @@ sub ui_bytesbox
|
||||
{
|
||||
my ($name, $bytes, $size, $dis) = @_;
|
||||
my $units = 1;
|
||||
if ($bytes >= 10*1024*1024*1024) {
|
||||
if ($bytes >= 10*1024*1024*1024*1024) {
|
||||
$units = 1024*1024*1024*1024;
|
||||
}
|
||||
elsif ($bytes >= 10*1024*1024*1024) {
|
||||
$units = 1024*1024*1024;
|
||||
}
|
||||
elsif ($bytes >= 10*1024*1024) {
|
||||
@@ -485,8 +488,11 @@ if ($bytes ne "") {
|
||||
$size = &ui_max_text_width($size || 8);
|
||||
return &ui_textbox($name, $bytes, $size, $dis)." ".
|
||||
&ui_select($name."_units", $units,
|
||||
[ [ 1, "bytes" ], [ 1024, "kB" ], [ 1024*1024, "MB" ],
|
||||
[ 1024*1024*1024, "GB" ] ], undef, undef, undef, $dis);
|
||||
[ [ 1, "bytes" ],
|
||||
[ 1024, "kB" ],
|
||||
[ 1024*1024, "MB" ],
|
||||
[ 1024*1024*1024, "GB" ],
|
||||
[ 1024*1024*1024*1024, "TB" ] ], undef, undef, undef, $dis);
|
||||
}
|
||||
|
||||
# ui_upload(name, size, [disabled?], [tags])
|
||||
|
||||
@@ -1597,6 +1597,7 @@ if ($rcode == 303 || $rcode == 302 || $rcode == 301) {
|
||||
$page = $header{'location'};
|
||||
}
|
||||
elsif ($header{'location'}) {
|
||||
# Assume relative to same dir
|
||||
if ($_[2]) { ${$_[2]} = "Invalid Location header $header{'location'}"; return; }
|
||||
else { &error("Invalid Location header $header{'location'}"); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user