Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read and Write shares not working. #1970

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 80 additions & 46 deletions emhttp/plugins/dynamix/ShareEdit.page
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,26 @@ if ((! $share['cachePool']) && ($share['cachePool2'])) {
$share['cachePool2'] = "";
}

/* Correct a situation in previous Unraid versions where an array only share has a useCache defined. */
if ((!$poolsOnly) && ($share['useCache'] == "no")) {
$share['cachePool'] = "";
}

/* Check for non existent pool device. */
if ($share['cachePool'] && !in_array($share['cachePool'], $pools)) {
$poolDefined = false;
if (($share['cachePool'] && !in_array($share['cachePool'], $pools))) {
$share['useCache'] = $share['cachePool2'] ? "yes" : ($poolsOnly ? "no" : "yes");
$poolDefined = false;
} else {
$share['useCache'] = $share['useCache'] ?: ($poolsOnly ? "only" : "no");
$poolDefined = true;
}

/* Check for pool 2 (or array) being defined. */
$poolDefined2 = true;
if ((($share['useCache'] == "yes") || ($share['useCache'] == "prefer")) && ($poolsOnly) && (!$share['cachePool2'])) {
$poolDefined2 = true;
$share['useCache'] = "only";
} else if ($share['cachePool2']) {
$poolDefined2 = in_array($share['cachePool2'], $pools);
} else {
$poolDefined2 = true;
}

$cachePoolCapitalized = compress(my_disk($share['cachePool'],$display['raw']));
Expand Down Expand Up @@ -457,7 +460,7 @@ _(Excluded disk(s))_:
</div>

</div>
<div markdown="1" class="shade-<?=$display['theme']?>">
<div markdown="1" id="secondaryStorage" class="shade-<?=$display['theme']?>">
_(Secondary storage)_:
: <select id="secondary" onchange="updateScreen(z(4),'slow')">
<?=mk_option(secondary(),'0',_('None'))?>
Expand Down Expand Up @@ -516,7 +519,7 @@ _(Excluded disk(s))_:
</div>

</div>
<div markdown="1" class="shade-<?=$display['theme']?>">
<div markdown="1" id="moverAction" class="shade-<?=$display['theme']?>">
<div markdown="1" id="moverDirection1">
_(Mover action)_:
: <span class="input"><select id="direction" onchange="updateScreen(z(3),'slow')">
Expand All @@ -541,20 +544,19 @@ _(Mover action)_:
&nbsp;
: <input type="submit" name="cmdEditShare" value="_(Add Share)_" onclick="this.value='Add Share'"><input type="button" value="_(Done)_" onclick="done()">
<?else:?>
<div markdown="1" class="empty">
_(Delete)_<input type="checkbox" name="confirmDelete" onchange="chkDelete(this.form, document.getElementById('cmdEditShare'));">
<div markdown="1">
<label id="deleteLabel" title="">_(Delete)_</label><input type="checkbox" name="confirmDelete" onchange="chkDelete(this.form, document.getElementById('cmdEditShare'));" title="" disabled>
: <input type="submit" id="cmdEditShare" name="cmdEditShare" value="_(Apply)_" onclick="if (this.value=='_(Delete)_') this.value='Delete'; else this.value='Apply'; return handleDeleteClick(this)" disabled><input type="button" value="_(Done)_" onclick="done()">
</div>
<div markdown="1" class="full">
&nbsp;
: <input type="submit" name="cmdEditShare" value="_(Apply)_" onclick="this.value='Apply'" disabled><input type="button" value="_(Done)_" onclick="done()">
</div>
<?endif;?>
</form>

<script>
let form = document.share_edit;

/* Global flag to skip prepareEdit. */
let skipPrepareEdit = false;

/* Primary variables to check for valid selection of missing pool. */
let changeMadePrimary = false;
let checkRequiredPrimary = false;
Expand Down Expand Up @@ -633,7 +635,7 @@ function updateScreen(cache, slow) {
const moverNoActionText = "<?= addslashes(_('Mover takes no action')) ?>";
const moverAction1Text = "<?= addslashes(_('Mover transfers files from Primary storage to Secondary storage')) ?>";
const moverAction2Text = "<?= addslashes(_('Mover transfers files from Secondary storage to Primary storage')) ?>";

switch (cache) {
case 'no':
$('#primary option:eq(' + z(0) + ')').prop('selected', true);
Expand Down Expand Up @@ -762,9 +764,18 @@ function updateScreen(cache, slow) {
break;
}

/* If primary is "Array", remove secondary storage selection as it does not apply when primary is array. */
if (primaryDropdown.selectedIndex === 0) {
$('#secondaryStorage').hide(slow);
$('#moverAction').hide(slow);
} else {
$('#secondaryStorage').show(slow);
$('#moverAction').show(slow);
}

/* Check secondary dropdown index and show/hide moreSettings2 */
if (secondaryDropdown.selectedIndex === 1) {
$('#moreSettings2').show('slow');
$('#moreSettings2').show(slow);
} else {
$('#moreSettings2').hide(slow);
}
Expand Down Expand Up @@ -910,6 +921,15 @@ function parseDiskSize(sizeStr) {

/* Compose input fields. */
function prepareEdit() {
/* Skip the function if readShare() filled the values */
if (skipPrepareEdit) {
/* Reset the flag. */
skipPrepareEdit = false;

/* Allow the form to submit. */
return true;
}

/* Declare variables at the function scope */
let share, reserved, pools;

Expand Down Expand Up @@ -1010,38 +1030,39 @@ function prepareEdit() {
}

function readShare() {
/* Declare variables at the function scope */
var name, data, disk, include, exclude, i, j;

name = $('select[name="readshare"]').val();
initDropdown(true);

$.get('/webGui/include/ShareData.php', { name: name }, function(json) {
data = $.parseJSON(json);
form.shareAllocator.value = data.allocator;
form.shareFloor.value = data.floor;
form.shareSplitLevel.value = data.splitLevel;
form.shareInclude.value = data.include;
form.shareExclude.value = data.exclude;
form.shareUseCache.value = data.useCache;
form.shareCOW.value = data.cow;

for (i = 0; (disk = data.include.split(',')[i]); i++) {
for (j = 0; (include = form.shareInclude.options[j]); j++) {
if (include.value == disk) include.selected = true;
}
let name, data;

name = $('select[name="readshare"]').val();

$.get('/webGui/include/ShareData.php', { name: name }, function(json) {
data = $.parseJSON(json);
let form = document.forms['share_edit'];

/* Fill in the form values */
form.shareAllocator.value = data.allocator;
form.shareFloor.value = data.floor;
form.shareSplitLevel.value = data.splitLevel;
form.shareInclude.value = data.include;
form.shareExclude.value = data.exclude;
form.shareUseCache.value = data.useCache;
form.shareCachePool2.value = data.cachePool2;
form.shareCOW.value = data.cow;

/* Populate the primary storage field (shareCachePool) */
let primaryField = document.getElementById('primary');
if (primaryField) {
/* Set to retrieved value or default. */
primaryField.value = data.cachePool || '';
}

for (i = 0; (disk = data.exclude.split(',')[i]); i++) {
for (j = 0; (exclude = form.shareExclude.options[j]); j++) {
if (exclude.value == disk) exclude.selected = true;
}
}
/* Set flag to skip prepareEdit */
skipPrepareEdit = true;

initDropdown(false);
});

$(form).find('select').trigger('change');
/* Enable and trigger the submit button */
const submitButton = document.getElementById('cmdEditShare');
submitButton.disabled = false;
submitButton.click();
});
}

function writeShare(data, n, i) {
Expand Down Expand Up @@ -1073,6 +1094,8 @@ function writeShare(data, n, i) {
newData[i]['shareInclude'] = '<?=addslashes(htmlspecialchars($share['include']))?>';
newData[i]['shareExclude'] = '<?=addslashes(htmlspecialchars($share['exclude']))?>';
newData[i]['shareUseCache'] = '<?=addslashes(htmlspecialchars($share['useCache']))?>';
newData[i]['shareCachePool'] = '<?=addslashes(htmlspecialchars($share['cachePool']))?>';
newData[i]['shareCachePool2'] = '<?=addslashes(htmlspecialchars($share['cachePool2']))?>';
newData[i]['cmdEditShare'] = 'Apply';
i++;
}
Expand Down Expand Up @@ -1131,7 +1154,7 @@ document.addEventListener('DOMContentLoaded', function() {

let cachePoolOption = document.getElementById('cachePoolOption');
let messageSpan = document.getElementById('cachePoolMessage');
messageSpan.textContent = `${_('Warning: Configured Pool')} '${cachePoolCapitalized}' ${_('is missing')}.`;
messageSpan.textContent = `${_('Warning: Configured Pool')} '${cachePoolCapitalized || _('Array')}' ${_('is missing')}.`;
messageSpan.style.display = 'inline';
cachePoolOption.selected = true;

Expand Down Expand Up @@ -1297,19 +1320,30 @@ function handleDeleteClick(button) {

$(function() {
<?if ($name):?>
<?
$tooltip_enabled = _('Share is empty and is safe to delete');
$tooltip_disabled = _('Share must be empty to be deleted');
?>

$.post('/webGui/include/ShareList.php', { scan: "<?=$name?>" }, function(e) {
if (e == 1) {
$('.empty').show();
$('.full').hide();
/* Enable delete checkbox and update tooltip. */
$('input[name="confirmDelete"]').prop('disabled', false).attr('title', '<?= $tooltip_enabled ?>');
$('#deleteLabel').attr('title', '<?= $tooltip_enabled ?>');
} else {
$('.full1').hide();
$('.full2').show();
/* Disable delete checkbox and update tooltip. */
$('input[name="confirmDelete"]').prop('disabled', true).attr('title', '<?= $tooltip_disabled ?>');
$('#deleteLabel').attr('title', '<?= $tooltip_disabled ?>');
}
});
<?endif;?>
initDropdown(true);
<?if ($tabbed):?>
$('#tab1').bind({
$('#tab1').on({
click: function() {
initDropdown(true);
}
Expand Down