mirror of
https://github.com/unraid/webgui.git
synced 2026-01-27 12:09:06 -06:00
Shares: new set up with primary and secondary
Includes automatic floor calculation for shares
This commit is contained in:
@@ -3,8 +3,8 @@ Title="Share Settings"
|
||||
Tag="share-alt-square"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
/* Copyright 2005-2023, Lime Technology
|
||||
* Copyright 2012-2023, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
@@ -18,7 +18,7 @@ Tag="share-alt-square"
|
||||
$width = [123,300];
|
||||
|
||||
if ($name == "") {
|
||||
/* default values when adding new share */
|
||||
// default values when adding new share
|
||||
$share = ["nameOrig" => "",
|
||||
"name" => "",
|
||||
"comment" => "",
|
||||
@@ -28,34 +28,66 @@ if ($name == "") {
|
||||
"include" => "",
|
||||
"exclude" => "",
|
||||
"useCache" => "no",
|
||||
"cachePool" => "cache",
|
||||
"cow" => "auto"];
|
||||
"cachePool" => "",
|
||||
"exclusive" => "no",
|
||||
"cow" => "auto"
|
||||
];
|
||||
$loc = 0;
|
||||
} elseif (array_key_exists($name, $shares)) {
|
||||
/* edit existing share */
|
||||
// edit existing share
|
||||
$share = $shares[$name];
|
||||
// find current location(s) of share
|
||||
$tag = implode('|',array_merge(['disk'],pools_filter($disks)));
|
||||
$loc = count(array_filter(explode(',',preg_replace("/($tag)/",',$1',exec("getfattr --no-dereference --absolute-names --only-values -n system.LOCATIONS ".escapeshellarg("/mnt/user/$name")." 2>/dev/null")))));
|
||||
} else {
|
||||
/* handle share deleted case */
|
||||
// handle share deleted case
|
||||
echo "<p class='notice'>"._('Share')." '".htmlspecialchars($name)."' "._('has been deleted').".</p><input type='button' value=\""._('Done')."\" onclick='done()'>";
|
||||
return;
|
||||
}
|
||||
// Check for non existent pool device
|
||||
if ($share['cachePool'] && !in_array($share['cachePool'],$pools)) $share['useCache'] = "no";
|
||||
|
||||
/* Check for non existent pool device. */
|
||||
if ($share['cachePool']) {
|
||||
if (! in_array($share['cachePool'], $pools)) {
|
||||
$share['useCache'] = "no";
|
||||
}
|
||||
}
|
||||
|
||||
/* check for empty share */
|
||||
// check for empty share
|
||||
function shareEmpty($name) {
|
||||
return (($files = @scandir("/mnt/user/$name")) && (count($files) <= 2));
|
||||
return is_dir("/mnt/user/$name") ? count(scandir("/mnt/user/$name",SCANDIR_SORT_NONE))<=2 : true;
|
||||
}
|
||||
|
||||
function globalInclude($name) {
|
||||
global $var;
|
||||
return substr($name,0,4)=='disk' && (!$var['shareUserInclude'] || strpos("{$var['shareUserInclude']},","$name,")!==false);
|
||||
return substr($name,0,4)=='disk' && (!$var['shareUserInclude'] || in_array($name,explode(',',$var['shareUserInclude'])));
|
||||
}
|
||||
function presetSpace($val) {
|
||||
if (!$val) return;
|
||||
$units = ['KB','MB','GB','TB','PB','EB','ZB','YB'];
|
||||
$val = filter_var($val,FILTER_SANITIZE_NUMBER_INT);
|
||||
$base = $val>0 ? floor(log($val,1000)) : 0;
|
||||
return ($val/pow(1000,$base)).' '.$units[$base];
|
||||
}
|
||||
function fsSize() {
|
||||
global $disks,$pools;
|
||||
$fsSize = $small = [];
|
||||
foreach (data_filter($disks) as $disk) $small[] = _var($disk,'fsSize');
|
||||
$fsSize[] = '"":"'.min(array_filter($small)).'"';
|
||||
foreach ($pools as $pool) $fsSize[] = '"'.$pool.'":"'._var($disks[$pool],'fsSize',0).'"';
|
||||
return implode(',',$fsSize);
|
||||
}
|
||||
function fsType() {
|
||||
global $disks,$pools;
|
||||
$fsType = [];
|
||||
foreach ($pools as $pool) $fsType[] = '"'.$pool.'":"'.str_replace('luks:','',_var($disks[$pool],'fsType')).'"';
|
||||
return implode(',',$fsType);
|
||||
}
|
||||
function primary() {
|
||||
global $share;
|
||||
return $share['useCache']=='no' ? '' : $share['cachePool'];
|
||||
}
|
||||
function secondary() {
|
||||
global $share;
|
||||
return in_array($share['useCache'],['no','only']) ? '0' : '1';
|
||||
}
|
||||
function direction() {
|
||||
global $share;
|
||||
return $share['useCache']=='prefer' ? '1' : '0';
|
||||
}
|
||||
|
||||
// global shares include/exclude
|
||||
$myDisks = array_filter(array_diff(array_keys(array_filter($disks,'my_disks')), explode(',',$var['shareUserExclude'])), 'globalInclude');
|
||||
?>
|
||||
@@ -64,6 +96,14 @@ $myDisks = array_filter(array_diff(array_keys(array_filter($disks,'my_disks')),
|
||||
:share_edit_global2_help:
|
||||
<?endif;?>
|
||||
|
||||
<style>
|
||||
div.shade-white{background-color:#ededed;margin-top:10px;padding:8px 0 3px 0}
|
||||
div.shade-black{background-color:#212121;margin-top:10px;padding:8px 0 3px 0}
|
||||
div.shade-azure{background-color:#edeaef;margin-top:10px;padding:8px 0 3px 0}
|
||||
div.shade-gray{background-color:#121510;margin-top:10px;padding:8px 0 3px 0}
|
||||
#s1,#s2,#s3,#s4,#s5{display:none}
|
||||
</style>
|
||||
|
||||
<div id="" class="clone1">
|
||||
<span class="clone">_(Read settings from)_</span><i class="fa fa-arrow-left fa-fw"></i>
|
||||
<span class="wrap"><select name="readshare" class="clone" onchange="toggleButton('readshare',false)">
|
||||
@@ -76,7 +116,7 @@ foreach ($shares as $list) if ($list['name']!=$name || !$name) echo mk_option(""
|
||||
<?if ($name):?>
|
||||
<div id="" class="clone2">
|
||||
<span class="clone">_(Write settings to)_</span><i class="fa fa-arrow-right fa-fw"></i>
|
||||
<span class="wrap"><select id="s3" name="writeshare" multiple="multiple" style="display:none" onchange="toggleButton('writeshare',this.id)">
|
||||
<span class="wrap"><select id="s5" name="writeshare" multiple onchange="toggleButton('writeshare',this.id)">
|
||||
<?
|
||||
$rows = [];
|
||||
foreach ($shares as $list) if ($list['name']!=$name) $rows[] = mk_option("", $list['name'], compress($list['name']));
|
||||
@@ -87,36 +127,43 @@ foreach ($rows as $row) echo $row;
|
||||
</div>
|
||||
<?endif;?>
|
||||
|
||||
<form markdown="1" name="share_edit" method="POST" action="/update.htm" target="progressFrame" onsubmit="return prepareEdit(this)"<?=$name?" onchange=\"toggleButton('writeshare',true);$('#s3').dropdownchecklist('disable')\">":">"?>
|
||||
<form markdown="1" name="share_edit" method="POST" action="/update.htm" target="progressFrame" onsubmit="return prepareEdit()"<?=$name?" onchange=\"toggleButton('writeshare',true);$('#s5').dropdownchecklist('disable')\">":">"?>
|
||||
<input type="hidden" name="shareNameOrig" value="<?=htmlspecialchars($share['nameOrig'])?>">
|
||||
<input type="hidden" name="shareUseCache" value="<?=$share['useCache']?>">
|
||||
<input type="hidden" name="shareAllocator" value="">
|
||||
<input type="hidden" name="shareSplitLevel" value="">
|
||||
<input type="hidden" name="shareInclude" value="">
|
||||
<input type="hidden" name="shareExclude" value="">
|
||||
|
||||
<div markdown="1" class="shade-<?=$display['theme']?>">
|
||||
_(Share name)_:
|
||||
: <input type="text" name="shareName" maxlength="40" value="<?=htmlspecialchars($name)?>" title="_(Hidden share names are not allowed)_" pattern="^[^\.].+">
|
||||
: <input type="text" name="shareName" maxlength="40" autocomplete="off" spellcheck="false" value="<?=htmlspecialchars($name)?>" title="_(Hidden share names are not allowed)_" pattern="^[^\.].+">
|
||||
|
||||
:share_edit_name_help:
|
||||
|
||||
_(Comments)_:
|
||||
: <input type="text" name="shareComment" maxlength="256" value="<?=htmlspecialchars($share['comment'])?>">
|
||||
: <input type="text" name="shareComment" maxlength="256" autocomplete="off" spellcheck="false" value="<?=htmlspecialchars($share['comment'])?>">
|
||||
|
||||
:share_edit_comments_help:
|
||||
|
||||
_(Use cache pool (for new files/directories))_:
|
||||
: <span class="input"><select name="shareUseCache" onchange="updateScreen(this.value)"<?=$pool_devices?'':' disabled'?>>
|
||||
<?=mk_option($share['useCache'], "no", _('No'))?>
|
||||
<?=mk_option($share['useCache'], "yes", _('Yes'))?>
|
||||
<?=mk_option($share['useCache'], "prefer", _('Prefer'))?>
|
||||
<?=mk_option($share['useCache'], "only", _('Only'))?>
|
||||
</select></span><span id="moverAction"></span>
|
||||
_(Minimum free space)_:
|
||||
: <input type="text" name="shareFloor" maxlength="16" autocomplete="off" spellcheck="false" class="narrow" value="<?=presetSpace($share['floor'])?>" placeholder="0">
|
||||
|
||||
:share_edit_cache_pool_help:
|
||||
:share_edit_free_space_help:
|
||||
|
||||
_(Select cache pool)_:
|
||||
: <select name="shareCachePool">
|
||||
</div>
|
||||
<div markdown="1" class="shade-<?=$display['theme']?>">
|
||||
_(Primary storage (for new files and folders))_:
|
||||
: <select id="primary" name="shareCachePool" onchange="updateScreen(z(4),'slow')">
|
||||
<?=mk_option(primary(),'',_('Array'))?>
|
||||
<?foreach ($pools as $pool):?>
|
||||
<?if ($disks[$pool]['devices']) echo mk_option($share['cachePool'],$pool,ucfirst($pool),$disks[$pool]['shareEnabled']=='yes'?"":"disabled")?>
|
||||
<?if ($disks[$pool]['devices']) echo mk_option(primary(),$pool,ucfirst($pool),$disks[$pool]['shareEnabled']=='yes'?"":"disabled")?>
|
||||
<?endforeach;?>
|
||||
</select>
|
||||
|
||||
:share_edit_primary_storage_help:
|
||||
|
||||
<div markdown="1" id="cow-setting">
|
||||
_(Enable Copy-on-write)_:
|
||||
: <span class="input"><select name="shareCOW"<?if ($name):?> disabled<?endif;?>>
|
||||
<?=mk_option($share['cow'], "no", _('No'))?>
|
||||
@@ -125,8 +172,20 @@ _(Enable Copy-on-write)_:
|
||||
|
||||
:share_edit_copy_on_write_help:
|
||||
|
||||
</div>
|
||||
<div markdown="1" id="exclusive">
|
||||
_(Exclusive access)_:
|
||||
: <select name="shareExclusive">
|
||||
<?=mk_option(_var($share,'exclusive','no'),'no',_('No'));?>
|
||||
<?=mk_option(_var($share,'exclusive','no'),'yes',_('Yes'),$loc>1?'disabled':'');?>
|
||||
</select>
|
||||
|
||||
:share_edit_exclusive_access_help:
|
||||
|
||||
</div>
|
||||
<div markdown="1" id="moreSettings1">
|
||||
_(Allocation method)_:
|
||||
: <select name="shareAllocator">
|
||||
: <select name="shareAllocator1">
|
||||
<?=mk_option($share['allocator'], "highwater", _('High-water'))?>
|
||||
<?=mk_option($share['allocator'], "fillup", _('Fill-up'))?>
|
||||
<?=mk_option($share['allocator'], "mostfree", _('Most-free'))?>
|
||||
@@ -134,13 +193,8 @@ _(Allocation method)_:
|
||||
|
||||
:share_edit_allocation_method_help:
|
||||
|
||||
_(Minimum free space)_:
|
||||
: <input type="text" name="shareFloor" maxlength="16" class="narrow" value="<?=htmlspecialchars($share['floor'])?>">
|
||||
|
||||
:share_edit_free_space_help:
|
||||
|
||||
_(Split level)_:
|
||||
: <select name="shareSplitLevel">
|
||||
: <select name="shareSplitLevel1">
|
||||
<?=mk_option($share['splitLevel'], "", _('Automatically split any directory as required'))?>
|
||||
<?=mk_option($share['splitLevel'], "1", _('Automatically split only the top level directory as required'))?>
|
||||
<?=mk_option($share['splitLevel'], "2", _('Automatically split only the top two directory levels as required'))?>
|
||||
@@ -153,122 +207,257 @@ _(Split level)_:
|
||||
:share_edit_split_level_help:
|
||||
|
||||
_(Included disk(s))_:
|
||||
: <select id="s1" name="shareInclude" multiple="multiple" style="display:none">
|
||||
: <select id="s1" name="shareInclude1" multiple>
|
||||
<?foreach ($myDisks as $disk):?>
|
||||
<?=mk_option_luks($disk, $share['include'], strstr($disks[$disk]['fsType'],':',true))?>
|
||||
<?=mk_option_luks($disk, $share['include'], strstr(_var($disks[$disk],'fsType'),':',true))?>
|
||||
<?endforeach;?>
|
||||
</select>
|
||||
|
||||
:share_edit_included_disks_help:
|
||||
|
||||
_(Excluded disk(s))_:
|
||||
: <select id="s2" name="shareExclude" multiple="multiple" style="display:none">
|
||||
: <select id="s2" name="shareExclude1" multiple>
|
||||
<?foreach ($myDisks as $disk):?>
|
||||
<?=mk_option_luks($disk, $share['exclude'], strstr($disks[$disk]['fsType'],':',true))?>
|
||||
<?=mk_option_luks($disk, $share['exclude'], strstr(_var($disks[$disk],'fsType'),':',true))?>
|
||||
<?endforeach;?>
|
||||
</select>
|
||||
|
||||
:share_edit_excluded_disks_help:
|
||||
|
||||
<?if (!$name):?>
|
||||
|
||||
: <input type="submit" name="cmdEditShare" value="_(Add Share)_" onclick="this.value='Add Share'"><input type="button" value="_(Done)_" onclick="done()">
|
||||
<?elseif (shareEmpty($name)):?>
|
||||
</div>
|
||||
</div>
|
||||
<div markdown="1" class="shade-<?=$display['theme']?>">
|
||||
_(Secondary storage)_:
|
||||
: <select id="secondary" onchange="updateScreen(z(4),'slow')">
|
||||
<?=mk_option(secondary(),'0',_('None'))?>
|
||||
<?=mk_option(secondary(),'1',_('Array'))?>
|
||||
</select>
|
||||
|
||||
:share_edit_secondary_storage_help:
|
||||
|
||||
<div markdown="1" id="moreSettings2">
|
||||
_(Allocation method)_:
|
||||
: <select name="shareAllocator2">
|
||||
<?=mk_option($share['allocator'], "highwater", _('High-water'))?>
|
||||
<?=mk_option($share['allocator'], "fillup", _('Fill-up'))?>
|
||||
<?=mk_option($share['allocator'], "mostfree", _('Most-free'))?>
|
||||
</select>
|
||||
|
||||
:share_edit_allocation_method_help:
|
||||
|
||||
_(Split level)_:
|
||||
: <select name="shareSplitLevel2">
|
||||
<?=mk_option($share['splitLevel'], "", _('Automatically split any directory as required'))?>
|
||||
<?=mk_option($share['splitLevel'], "1", _('Automatically split only the top level directory as required'))?>
|
||||
<?=mk_option($share['splitLevel'], "2", _('Automatically split only the top two directory levels as required'))?>
|
||||
<?=mk_option($share['splitLevel'], "3", _('Automatically split only the top three directory levels as required'))?>
|
||||
<?=mk_option($share['splitLevel'], "4", _('Automatically split only the top four directory levels as required'))?>
|
||||
<?=mk_option($share['splitLevel'], "5", _('Automatically split only the top five directory levels as required'))?>
|
||||
<?=mk_option($share['splitLevel'], "0", _('Manual: do not automatically split directories'))?>
|
||||
</select>
|
||||
|
||||
:share_edit_split_level_help:
|
||||
|
||||
_(Included disk(s))_:
|
||||
: <select id="s3" name="shareInclude2" multiple>
|
||||
<?foreach ($myDisks as $disk):?>
|
||||
<?=mk_option_luks($disk, $share['include'], strstr(_var($disks[$disk],'fsType'),':',true))?>
|
||||
<?endforeach;?>
|
||||
</select>
|
||||
|
||||
:share_edit_included_disks_help:
|
||||
|
||||
_(Excluded disk(s))_:
|
||||
: <select id="s4" name="shareExclude2" multiple>
|
||||
<?foreach ($myDisks as $disk):?>
|
||||
<?=mk_option_luks($disk, $share['exclude'], strstr(_var($disks[$disk],'fsType'),':',true))?>
|
||||
<?endforeach;?>
|
||||
</select>
|
||||
|
||||
:share_edit_excluded_disks_help:
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div markdown="1" class="shade-<?=$display['theme']?>">
|
||||
<div markdown="1" id="moverDirection1">
|
||||
_(Mover action)_:
|
||||
: <span class="input"><select id="direction" onchange="updateScreen(z(3),'slow')">
|
||||
<?=mk_option(direction(),'0','')?>
|
||||
<?=mk_option(direction(),'1','')?>
|
||||
</select></span><span id="moverAction1"></span>
|
||||
|
||||
:share_edit_mover_action_help:
|
||||
|
||||
</div>
|
||||
<div markdown="1" id="moverDirection2">
|
||||
_(Mover action)_:
|
||||
: <span class="input"><select disabled>
|
||||
<?=mk_option('','',"_(Not used)_")?>
|
||||
</select></span><span id="moverAction2"></span>
|
||||
|
||||
:share_edit_mover_action_help:
|
||||
|
||||
</div>
|
||||
<?if ($name):?>
|
||||
<?if (shareEmpty($name)):?>
|
||||
_(Share status)_:
|
||||
: _(Share is empty)_
|
||||
|
||||
:share_edit_status_help:
|
||||
|
||||
_(Delete)_<input type="checkbox" name="confirmDelete" onchange="chkDelete(this.form, this.form.cmdEditShare);">
|
||||
: <input type="submit" name="cmdEditShare" value="_(Apply)_" onclick="if (this.value=='_(Delete)_') this.value='Delete'; else this.value='Apply'" disabled><input type="button" value="_(Done)_" onclick="done()">
|
||||
<?else:?>
|
||||
_(Share status)_:
|
||||
: _(Share contains data)_
|
||||
|
||||
:share_edit_delete_help:
|
||||
|
||||
<?endif;?>
|
||||
<?endif;?>
|
||||
</div>
|
||||
<?if (!$name):?>
|
||||
|
||||
: <input type="submit" name="cmdEditShare" value="_(Add Share)_" onclick="this.value='Add Share'"><input type="button" value="_(Done)_" onclick="done()">
|
||||
<?elseif (shareEmpty($name)):?>
|
||||
_(Delete)_<input type="checkbox" name="confirmDelete" onchange="chkDelete(this.form, this.form.cmdEditShare);">
|
||||
: <input type="submit" name="cmdEditShare" value="_(Apply)_" onclick="if (this.value=='_(Delete)_') this.value='Delete'; else this.value='Apply'" disabled><input type="button" value="_(Done)_" onclick="done()">
|
||||
<?else:?>
|
||||
|
||||
: <input type="submit" name="cmdEditShare" value="_(Apply)_" onclick="this.value='Apply'" disabled><input type="button" value="_(Done)_" onclick="done()">
|
||||
<?endif;?>
|
||||
</form>
|
||||
<script>
|
||||
var form = document.share_edit;
|
||||
|
||||
$(function() {
|
||||
initDropdown(false,true);
|
||||
<?if ($tabbed):?>
|
||||
$('#tab1').bind({click:function(){initDropdown(true,true);}});
|
||||
<?endif;?>
|
||||
updateScreen(document.share_edit.shareUseCache.value);
|
||||
presetSpace(document.share_edit.shareFloor);
|
||||
updateScreen(form.shareUseCache.value);
|
||||
});
|
||||
function initDropdown(remove,create) {
|
||||
if (remove) {
|
||||
$('#s1').dropdownchecklist('destroy');
|
||||
$('#s2').dropdownchecklist('destroy');
|
||||
<?if ($name):?>
|
||||
$('#s3').dropdownchecklist('destroy');
|
||||
$('#s4').dropdownchecklist('destroy');
|
||||
<?if ($name):?>
|
||||
$('#s5').dropdownchecklist('destroy');
|
||||
<?endif;?>
|
||||
}
|
||||
if (create) {
|
||||
$('#s1').dropdownchecklist({emptyText:"_(All)_", width:<?=$width[1]?>, explicitClose:"..._(close)_"});
|
||||
$('#s2').dropdownchecklist({emptyText:"_(None)_", width:<?=$width[1]?>, explicitClose:"..._(close)_"});
|
||||
$('#s3').dropdownchecklist({emptyText:"_(All)_", width:<?=$width[1]?>, explicitClose:"..._(close)_"});
|
||||
$('#s4').dropdownchecklist({emptyText:"_(None)_", width:<?=$width[1]?>, explicitClose:"..._(close)_"});
|
||||
<?if ($name):?>
|
||||
$("#s3").dropdownchecklist({firstItemChecksAll:true, emptyText:"_(select)_...", width:<?=$width[0]?>, explicitClose:"..._(close)_"});
|
||||
$("#s5").dropdownchecklist({firstItemChecksAll:true, emptyText:"_(select)_...", width:<?=$width[0]?>, explicitClose:"..._(close)_"});
|
||||
<?endif;?>
|
||||
}
|
||||
}
|
||||
function updateScreen(cache) {
|
||||
switch (cache) {
|
||||
case 'yes':
|
||||
var textAction = "_(Mover transfers files from cache to array)_";
|
||||
break;
|
||||
case 'prefer':
|
||||
var textAction = "_(Mover transfers files from array to cache)_";
|
||||
break;
|
||||
default:
|
||||
var textAction = "_(Mover takes no action)_";
|
||||
break;
|
||||
function z(i) {
|
||||
switch (i) {
|
||||
case 0: return $('#primary').prop('selectedIndex');
|
||||
case 1: return $('#secondary').prop('selectedIndex');
|
||||
case 2: return $('#direction').prop('selectedIndex');
|
||||
case 3: return z(2)==0 ? 'yes' : 'prefer';
|
||||
case 4: return z(0)==0 ? 'no' : (z(1)==0 ? 'only' : z(3));
|
||||
}
|
||||
document.getElementById('moverAction').innerHTML = textAction;
|
||||
}
|
||||
function updateCOW(i,slow) {
|
||||
const fsType = {<?=fsType()?>};
|
||||
if (fsType[i]=='btrfs') $('#cow-setting').show(slow); else $('#cow-setting').hide(slow);
|
||||
}
|
||||
function updateScreen(cache,slow) {
|
||||
switch (cache) {
|
||||
case 'no':
|
||||
document.share_edit.shareCOW.disabled = true;
|
||||
document.share_edit.shareCachePool.disabled = true;
|
||||
document.share_edit.shareAllocator.disabled = false;
|
||||
document.share_edit.shareFloor.disabled = false;
|
||||
document.share_edit.shareSplitLevel.disabled = false;
|
||||
$('#primary option:eq('+z(0)+')').prop('selected',true);
|
||||
$('#secondary option:eq(0)').prop('selected',true);
|
||||
$('#secondary option:eq(1)').prop('disabled',true);
|
||||
$('#moverDirection1').hide();
|
||||
$('#moverDirection2').show();
|
||||
$('#exclusive').hide(slow);
|
||||
$('#moreSettings1').show(slow);
|
||||
$('#moreSettings2').hide(slow);
|
||||
$('#cow-setting').hide(slow);
|
||||
form.shareAllocator.disabled = false;
|
||||
form.shareSplitLevel.disabled = false;
|
||||
$('#s1').dropdownchecklist('enable');
|
||||
$('#s2').dropdownchecklist('enable');
|
||||
$('#moverAction2').html("_(Mover takes no action)_");
|
||||
break;
|
||||
case 'yes':
|
||||
$('#primary option:eq('+z(0)+')').prop('selected',true);
|
||||
$('#secondary option:eq('+z(1)+')').prop('selected',true);
|
||||
$('#secondary option:eq(1)').prop('disabled',false);
|
||||
$('#moverDirection1 option:eq(0)').text($('#primary option:eq('+z(0)+')').text()+' → '+$('#secondary option:eq('+z(1)+')').text());
|
||||
$('#moverDirection1 option:eq(1)').text($('#secondary option:eq('+z(1)+')').text()+' → '+$('#primary option:eq('+z(0)+')').text());
|
||||
$('#moverDirection1').val('0').show();
|
||||
$('#moverDirection2').hide();
|
||||
$('#exclusive').hide(slow);
|
||||
$('#moreSettings1').hide(slow);
|
||||
$('#moreSettings2').show(slow);
|
||||
updateCOW(form.shareCachePool.value,slow);
|
||||
form.shareAllocator.disabled = false;
|
||||
form.shareSplitLevel.disabled = false;
|
||||
$('#s3').dropdownchecklist('enable');
|
||||
$('#s4').dropdownchecklist('enable');
|
||||
$('#moverAction1').html("_(Mover transfers files from Primary storage to Secondary storage)_");
|
||||
break;
|
||||
case 'only':
|
||||
document.share_edit.shareCOW.disabled = false;
|
||||
document.share_edit.shareCachePool.disabled = false;
|
||||
document.share_edit.shareAllocator.disabled = true;
|
||||
document.share_edit.shareFloor.disabled = true;
|
||||
document.share_edit.shareSplitLevel.disabled = true;
|
||||
$('#primary option:eq('+z(0)+')').prop('selected',true);
|
||||
$('#secondary option:eq('+z(1)+')').prop('selected',true);
|
||||
$('#secondary option:eq(1)').prop('disabled',false);
|
||||
$('#moverDirection1').hide();
|
||||
$('#moverDirection2').show();
|
||||
$('#exclusive').show(slow);
|
||||
$('#moreSettings1').hide(slow);
|
||||
$('#moreSettings2').hide(slow);
|
||||
updateCOW(form.shareCachePool.value,slow);
|
||||
form.shareAllocator.disabled = true;
|
||||
form.shareSplitLevel.disabled = true;
|
||||
$('#s1').dropdownchecklist('disable');
|
||||
$('#s2').dropdownchecklist('disable');
|
||||
$('#moverAction2').html("_(Mover takes no action)_");
|
||||
break;
|
||||
default:
|
||||
document.share_edit.shareCOW.disabled = false;
|
||||
document.share_edit.shareCachePool.disabled = false;
|
||||
document.share_edit.shareAllocator.disabled = false;
|
||||
document.share_edit.shareFloor.disabled = false;
|
||||
document.share_edit.shareSplitLevel.disabled = false;
|
||||
$('#s1').dropdownchecklist('enable');
|
||||
$('#s2').dropdownchecklist('enable');
|
||||
case 'prefer':
|
||||
$('#primary option:eq('+z(0)+')').prop('selected',true);
|
||||
$('#secondary option:eq('+z(1)+')').prop('selected',true);
|
||||
$('#secondary option:eq(1)').prop('disabled',false);
|
||||
$('#moverDirection1 option:eq(0)').text($('#primary option:eq('+z(0)+')').text()+' → '+$('#secondary option:eq('+z(1)+')').text());
|
||||
$('#moverDirection1 option:eq(1)').text($('#secondary option:eq('+z(1)+')').text()+' → '+$('#primary option:eq('+z(0)+')').text());
|
||||
$('#moverDirection1').val('1').show();
|
||||
$('#moverDirection2').hide();
|
||||
$('#exclusive').hide(slow);
|
||||
$('#moreSettings1').hide(slow);
|
||||
$('#moreSettings2').show(slow);
|
||||
updateCOW(form.shareCachePool.value,slow);
|
||||
form.shareAllocator.disabled = false;
|
||||
form.shareSplitLevel.disabled = false;
|
||||
$('#s3').dropdownchecklist('enable');
|
||||
$('#s4').dropdownchecklist('enable');
|
||||
$('#moverAction1').html("_(Mover transfers files from Secondary storage to Primary storage)_");
|
||||
break;
|
||||
}
|
||||
}
|
||||
function presetSpace(shareFloor) {
|
||||
var unit = ['KB','MB','GB','TB','PB'];
|
||||
var scale = shareFloor.value;
|
||||
if (scale.replace(/[0-9.,\s]/g,'').length>0) return;
|
||||
var base = scale>0 ? Math.floor(Math.log(scale)/Math.log(1000)):0;
|
||||
if (base>=unit.length) base = unit.length-1;
|
||||
shareFloor.value = (scale/Math.pow(1000, base))+unit[base];
|
||||
function unite(field) {
|
||||
var list = [];
|
||||
for (var i=0,item; item=field.options[i]; i++) if (item.selected) list.push(item.value);
|
||||
return list.join(',');
|
||||
}
|
||||
function setFloor(val) {
|
||||
const fsSize = {<?=fsSize()?>};
|
||||
const units = ['K','M','G','T','P','E','Z','Y'];
|
||||
var size = fsSize[$('#primary').val()] * 0.1; // 10% of available size
|
||||
var base = Math.pow(1000,Math.floor(Math.log(size)/Math.log(1000)));
|
||||
size = val.replace(/[A-Z.,\s]/gi,'')==0 ? (Math.floor(size/base) * base).toString() : val;
|
||||
var unit = size.replace(/[0-9.,\s]/g,'');
|
||||
base = unit.length==2 ? 1000 : (unit.length==1 ? 1024 : 0);
|
||||
return base>0 ? size.replace(unit,'') * Math.pow(base,units.indexOf(unit.toUpperCase().replace('B',''))) : size;
|
||||
}
|
||||
// Compose input fields
|
||||
function prepareEdit(form) {
|
||||
function prepareEdit() {
|
||||
// Test share name validity
|
||||
var share = form.shareName.value.trim();
|
||||
if (share.length==0) {
|
||||
@@ -289,40 +478,28 @@ function prepareEdit(form) {
|
||||
swal({title:"_(Invalid Characters)_",text:"_(You cannot use the following within share names)_"+' : \\ / * < > | " ?',type:'error',html:true,confirmButtonText:"_(Ok)_"});
|
||||
return false;
|
||||
}
|
||||
// Update settings
|
||||
form.shareName.value = share;
|
||||
// Adjust minimum free space value to selected unit
|
||||
var unit = 'KB,MB,GB,TB,PB';
|
||||
var scale = form.shareFloor.value;
|
||||
var index = unit.indexOf(scale.replace(/[0-9.,\s]/g,'').toUpperCase());
|
||||
form.shareFloor.value = scale.replace(/[A-Z\s]/gi,'') * Math.pow(1000, (index>0 ? index/3 : 0))
|
||||
// Return include as single line input
|
||||
var include = '';
|
||||
for (var i=0,item; item=form.shareInclude.options[i]; i++) {
|
||||
if (item.selected) {
|
||||
if (include.length) include += ',';
|
||||
include += item.value;
|
||||
item.selected = false;
|
||||
}
|
||||
form.shareUseCache.value = z(4);
|
||||
form.shareFloor.value = setFloor(form.shareFloor.value);
|
||||
switch (form.shareUseCache.value) {
|
||||
case 'no':
|
||||
form.shareAllocator.value = form.shareAllocator1.value;
|
||||
form.shareSplitLevel.value = form.shareSplitLevel1.value;
|
||||
form.shareInclude.value = unite(form.shareInclude1);
|
||||
form.shareExclude.value = unite(form.shareExclude1);
|
||||
break;
|
||||
case 'yes':
|
||||
case 'prefer':
|
||||
form.shareAllocator.value = form.shareAllocator2.value;
|
||||
form.shareSplitLevel.value = form.shareSplitLevel2.value;
|
||||
form.shareInclude.value = unite(form.shareInclude2);
|
||||
form.shareExclude.value = unite(form.shareExclude2);
|
||||
break;
|
||||
}
|
||||
item = form.shareInclude.options[0];
|
||||
item.value = include;
|
||||
item.selected = true;
|
||||
// Return exclude as single line input
|
||||
var exclude = '';
|
||||
for (var i=0,item; item=form.shareExclude.options[i]; i++) {
|
||||
if (item.selected) {
|
||||
if (exclude.length) exclude += ',';
|
||||
exclude += item.value;
|
||||
item.selected = false;
|
||||
}
|
||||
}
|
||||
item = form.shareExclude.options[0];
|
||||
item.value = exclude;
|
||||
item.selected = true;
|
||||
return true;
|
||||
}
|
||||
function readShare() {
|
||||
var form = document.share_edit;
|
||||
var name = $('select[name="readshare"]').val();
|
||||
initDropdown(true,false);
|
||||
$.get('/webGui/include/ShareData.php',{name:name},function(json) {
|
||||
@@ -350,7 +527,7 @@ function writeShare(data,n,i) {
|
||||
}
|
||||
} else {
|
||||
var data = [], i = 0;
|
||||
$('select#s3 option').map(function() {
|
||||
$('select#s5 option').map(function() {
|
||||
if ($(this).prop('selected')==true && $(this).val()!='(All)') {
|
||||
data[i] = {};
|
||||
data[i]['shareName'] = $(this).val();
|
||||
|
||||
@@ -37,10 +37,11 @@ $(function() {
|
||||
table.share_status thead tr td:first-child{width:15%}
|
||||
table.share_status thead tr td:nth-child(n+3){width:9%!important}
|
||||
table.share_status thead tr td:nth-child(5){width:13%!important}
|
||||
i.fa-fw{margin-right:2px}
|
||||
</style>
|
||||
|
||||
<table class="share_status">
|
||||
<thead><tr><td>_(Name)_</td><td>_(Comment)_</td><td>_(SMB)_</td><td>_(NFS)_</td><td>_(Cache)_</td><td>_(Size)_</td><td>_(Free)_</td></tr></thead>
|
||||
<thead><tr><td>_(Name)_</td><td>_(Comment)_</td><td>_(SMB)_</td><td>_(NFS)_</td><td>_(Storage)_</td><td>_(Size)_</td><td>_(Free)_</td></tr></thead>
|
||||
<tbody id="shareslist"></tbody>
|
||||
</table>
|
||||
<p><form name="share_form" method="POST" action="<?=htmlspecialchars($path)?>/Share?name=">
|
||||
|
||||
@@ -104,7 +104,20 @@ foreach ($shares as $name => $share) {
|
||||
$share['useCache'] = "no";
|
||||
}
|
||||
}
|
||||
$cache = _(ucfirst($share['useCache'])).($share['useCache']!='no'?' : '.compress(my_disk($share['cachePool'],$display['raw'])):'');
|
||||
switch ($share['useCache']) {
|
||||
case 'no':
|
||||
$cache = "<a class='hand info none' onclick='return false'><i class='fa fa-database fa-fw'></i>"._('Array')."<span>".sprintf(_('Primary storage %s'),_('Array'))."</span></a>";
|
||||
break;
|
||||
case 'yes':
|
||||
$cache = "<a class='hand info none' onclick='return false'><i class='fa fa-bullseye fa-fw'></i>".compress(my_disk($share['cachePool'],$display['raw']))." <i class='fa fa-long-arrow-right fa-fw'></i><i class='fa fa-database fa-fw'></i>"._('Array')."<span>"._('Primary stoage to Secondary storage')."</span></a>";
|
||||
break;
|
||||
case 'prefer':
|
||||
$cache = "<a class='hand info none' onclick='return false'><i class='fa fa-bullseye fa-fw'></i>".compress(my_disk($share['cachePool'],$display['raw']))." <i class='fa fa-long-arrow-left fa-fw'></i><i class='fa fa-database fa-fw'></i>"._('Array')."<span>"._('Secondary stoage to Primary storage')."</span></a>";
|
||||
break;
|
||||
case 'only':
|
||||
$cache = "<a class='hand info none' onclick='return false'><i class='fa fa-bullseye fa-fw'></i>".compress(my_disk($share['cachePool'],$display['raw']))."<span>".sprintf(_('Primary storage %s'),$share['cachePool'])."</span></a>";
|
||||
break;
|
||||
}
|
||||
if (array_key_exists($name, $ssz1)) {
|
||||
echo "<td>$cache</td>";
|
||||
echo "<td>",my_scale($ssz1[$name]['disk.total'], $unit)," $unit</td>";
|
||||
|
||||
Reference in New Issue
Block a user