mirror of
https://github.com/unraid/api.git
synced 2026-01-04 07:29:48 -06:00
refactor(web): improved downgrade ux
This commit is contained in:
@@ -16,8 +16,9 @@ $check = $notify['unraidos'] ? 0 : 1;
|
||||
$restoreVersion = $restoreBranch = $restoreVersionReleaseDate = 'unknown';
|
||||
$restoreExists = file_exists('/boot/previous/bzroot');
|
||||
$restoreChangelogPath = '/boot/previous/changes.txt';
|
||||
$restoreChangelogContent = file_get_contents($restoreChangelogPath);
|
||||
|
||||
$diagnosticsZip = htmlspecialchars(str_replace(' ', '_', strtolower($var['NAME'])));
|
||||
$serverNameEscaped = htmlspecialchars(str_replace(' ', '_', strtolower($var['NAME'])));
|
||||
|
||||
if (file_exists($restoreChangelogPath)) {
|
||||
exec("head -n4 $restoreChangelogPath", $rows);
|
||||
@@ -37,57 +38,29 @@ if (file_exists($restoreChangelogPath)) {
|
||||
?>
|
||||
|
||||
<script>
|
||||
var diagnosticsFile = "";
|
||||
var nchan_diagnostics = new NchanSubscriber('/sub/diagnostics', { subscriber: 'websocket' });
|
||||
const args = {};
|
||||
const nchan_diagnostics = new NchanSubscriber('/sub/diagnostics', { subscriber: 'websocket' });
|
||||
const reportUrl = new URL('https://forums.unraid.net/bug-reports/');
|
||||
let diagnosticsFile = '';
|
||||
|
||||
nchan_diagnostics.on('message', function(data) {
|
||||
if (data == '_DONE_') {
|
||||
nchan_diagnostics.stop();
|
||||
$('.sweet-alert').hide('fast').removeClass('nchan');
|
||||
swal.close();
|
||||
$('div.spinner').show('slow');
|
||||
location = diagnosticsFile;
|
||||
setTimeout(cleanUp,4000);
|
||||
|
||||
setTimeout(() => {
|
||||
cleanupDiagnostics();
|
||||
reportAfterDiagnosticsDownload();
|
||||
}, 2000);
|
||||
} else if (data) {
|
||||
let box = $('pre#swaltext');
|
||||
box.html(box.html() + '<br>' + data).scrollTop(box[0].scrollHeight);
|
||||
}
|
||||
});
|
||||
|
||||
function downgradeAction() {
|
||||
$.get('/plugins/dynamix.plugin.manager/include/Downgrade.php', { version: '<?=$restoreVersion?>' }, function() { refresh(); });
|
||||
}
|
||||
|
||||
function downgrade() {
|
||||
swal({
|
||||
title: "_(Diagnostics)_",
|
||||
text: "_(Please provide diagnostics when experiencing problems)_<br>_(Post these in the forums)_",
|
||||
html: true,
|
||||
type: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "<?= _('Diagnostics') ?>",
|
||||
cancelButtonText: "<?= _('Restore') ?>",
|
||||
}, function(diag) {
|
||||
if (diag) {
|
||||
// get diagnostics and then downgrade
|
||||
setTimeout(function() {
|
||||
diagnostics(zipfile());
|
||||
}, 250);
|
||||
} else {
|
||||
// downgrade immediately
|
||||
downgradeAction();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (document.hasFocus()) {
|
||||
$.post('/webGui/include/Download.php', { cmd: 'delete', file: diagnosticsFile }, downgradeAction());
|
||||
} else {
|
||||
setTimeout(cleanUp,2000);
|
||||
}
|
||||
}
|
||||
function zipfile() {
|
||||
function downloadDiagnostics() {
|
||||
const tzoffset = (new Date()).getTimezoneOffset() * 60000; // offset in milliseconds
|
||||
const localISOTime = (new Date(Date.now() - tzoffset));
|
||||
const year = localISOTime.getFullYear();
|
||||
@@ -96,12 +69,22 @@ function zipfile() {
|
||||
const hours = String(localISOTime.getHours()).padStart(2, '0');
|
||||
const minutes = String(localISOTime.getMinutes()).padStart(2, '0');
|
||||
const dateOutput = `${year}${month}${day}_${hours}${minutes}`;
|
||||
return '<?=$diagnosticsZip?>-diagnostics-' + dateOutput + '.zip';
|
||||
}
|
||||
function diagnostics(file) {
|
||||
const zipName = '<?=$serverNameEscaped?>-diagnostics-' + dateOutput + '.zip';
|
||||
|
||||
nchan_diagnostics.start();
|
||||
$.post('/webGui/include/Download.php', { cmd:'diag', file: file, anonymize: '' }, function(zip) {
|
||||
if (zip) {
|
||||
|
||||
$.post(
|
||||
'/webGui/include/Download.php',
|
||||
{
|
||||
cmd: 'diag',
|
||||
file: zipName,
|
||||
anonymize: '',
|
||||
},
|
||||
function(zip) {
|
||||
if (!zip) {
|
||||
return nchan_diagnostics.stop();
|
||||
}
|
||||
|
||||
diagnosticsFile = zip;
|
||||
swal({
|
||||
title: "_(Downloading)_...",
|
||||
@@ -112,9 +95,63 @@ function diagnostics(file) {
|
||||
});
|
||||
$('.sweet-alert').addClass('nchan');
|
||||
$('button.confirm').prop('disabled', true);
|
||||
} else {
|
||||
nchan_diagnostics.stop();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function reportAfterDiagnosticsDownload() {
|
||||
$('div.spinner').hide('fast');
|
||||
swal({
|
||||
title: "_(Open a bug report)_",
|
||||
text: "_(Create a bug report on our forums with a description of the issue along with your diagsnotics)_",
|
||||
html: true,
|
||||
type: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "<?= _('Create Bug Report') ?>",
|
||||
cancelButtonText: "<?= _('Close') ?>",
|
||||
}, function(confirm) {
|
||||
if (!confirm) {
|
||||
return false;
|
||||
}
|
||||
window.open(reportUrl, '_blank');
|
||||
});
|
||||
}
|
||||
|
||||
function cleanupDiagnostics() {
|
||||
if (document.hasFocus()) {
|
||||
return $.post('/webGui/include/Download.php', { cmd: 'delete', file: diagnosticsFile });
|
||||
}
|
||||
setTimeout(cleanupDiagnostics, 2000);
|
||||
}
|
||||
|
||||
function startDowngrade() {
|
||||
$('div.spinner').show('slow');
|
||||
|
||||
$.get(
|
||||
'/plugins/dynamix.plugin.manager/include/Downgrade.php',
|
||||
{
|
||||
version: '<?=$restoreVersion?>',
|
||||
},
|
||||
function() {
|
||||
refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function confirmDowngrade() {
|
||||
swal({
|
||||
title: "_(Confirm Downgrade)_",
|
||||
text: "<?= $restoreVersion ?><br>_(A reboot will be required)_",
|
||||
html: true,
|
||||
type: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "<?= _('Confirm') ?>",
|
||||
cancelButtonText: "<?= _('Cancel') ?>",
|
||||
}, function(confirm) {
|
||||
if (!confirm) {
|
||||
return false;
|
||||
}
|
||||
startDowngrade();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -39,7 +39,7 @@ const updateOsActionsStore = useUpdateOsActionsStore();
|
||||
const { rebootType } = storeToRefs(updateOsActionsStore);
|
||||
|
||||
const subtitle = computed(() => {
|
||||
if (rebootType.value === 'downgrade') {
|
||||
if (rebootType.value === 'update') {
|
||||
return t('Please finish the initiated update to enable a downgrade.');
|
||||
}
|
||||
return '';
|
||||
|
||||
@@ -37,7 +37,7 @@ const subtitle = computed(() => {
|
||||
});
|
||||
|
||||
/** when we're not prompting for reboot /Tools/Update will automatically send the user to account.unraid.net/server/update-os */
|
||||
const showLoader = computed(() => window.location.pathname === WEBGUI_TOOLS_UPDATE.pathname && rebootType.value === '')
|
||||
const showLoader = computed(() => window.location.pathname === WEBGUI_TOOLS_UPDATE.pathname && rebootType.value === '');
|
||||
|
||||
onBeforeMount(() => {
|
||||
if (showLoader.value) {
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
import {
|
||||
ArrowTopRightOnSquareIcon,
|
||||
ArrowUturnDownIcon,
|
||||
FolderArrowDownIcon,
|
||||
InformationCircleIcon,
|
||||
LifebuoyIcon,
|
||||
} from '@heroicons/vue/24/solid';
|
||||
import dayjs from 'dayjs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { onBeforeMount, ref } from 'vue';
|
||||
|
||||
import 'tailwindcss/tailwind.css';
|
||||
import '~/assets/main.css';
|
||||
@@ -32,13 +33,27 @@ const {
|
||||
outputDateTimeFormatted: formattedReleaseDate,
|
||||
} = useDateTimeHelper(dateTimeFormat.value, props.t, true, dayjs(props.releaseDate, 'YYYY-MM-DD').valueOf());
|
||||
|
||||
const downgradeButton = ref<UserProfileLink | undefined>({
|
||||
const diagnosticsButton = ref<UserProfileLink | undefined>({
|
||||
click: () => {
|
||||
// @ts-ignore – global function provided by the webgui on the update page
|
||||
downgrade();
|
||||
downloadDiagnostics();
|
||||
},
|
||||
icon: FolderArrowDownIcon,
|
||||
name: 'download-diagnostics',
|
||||
text: props.t('Download Diagnostics'),
|
||||
});
|
||||
|
||||
const downgradeButton = ref<UserProfileLink>({
|
||||
click: () => {
|
||||
// @ts-ignore – global function provided by the webgui on the update page
|
||||
confirmDowngrade();
|
||||
},
|
||||
name: 'downgrade',
|
||||
text: props.t('Begin restore to Unraid {0}', [props.version]),
|
||||
text: props.t('Begin downgrade to {0}', [props.version]),
|
||||
});
|
||||
|
||||
onBeforeMount(() => {
|
||||
console.debug('[props.releaseDate]', props.releaseDate, formattedReleaseDate.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -55,33 +70,43 @@ const downgradeButton = ref<UserProfileLink | undefined>({
|
||||
{{ t('Downgrade Unraid OS to {0}', [version]) }}
|
||||
</span>
|
||||
<span
|
||||
v-if="releaseDate"
|
||||
v-if="releaseDate && formattedReleaseDate !== 'Invalid Date'"
|
||||
class="text-16px opacity-75 shrink"
|
||||
>
|
||||
{{ t('Original release date {0}', [formattedReleaseDate]) }}
|
||||
</span>
|
||||
</span>
|
||||
</h3>
|
||||
<div class="text-16px leading-relaxed opacity-75 whitespace-normal">
|
||||
<p>{{ t('Downgrades are only recommended if you\'re unable to solve a critical issue. In the rare event you need to downgrade we ask that you please provide us with Diagnostics so we can investigate your issue. You will be prompted with the option to download the Diagnostics zip once the downgrade process is started. From there please open a bug report on our forums with a description of the issue and include your diagnostics.') }}</p>
|
||||
<div class="prose text-16px leading-relaxed opacity-75 whitespace-normal">
|
||||
<p>{{ t(`Downgrades are only recommended if you're unable to solve a critical issue.`) }}</p>
|
||||
<p>{{ t('In the rare event you need to downgrade we ask that you please provide us with Diagnostics so we can investigate your issue.') }}</p>
|
||||
<p>{{ t('Download the Diagnostics zip then please open a bug report on our forums with a description of the issue along with your diagnostics.') }} </p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="downgradeButton" class="flex flex-col sm:flex-shrink-0 items-center gap-16px">
|
||||
<BrandButton
|
||||
:btn-style="'underline'"
|
||||
:icon="InformationCircleIcon"
|
||||
:text="t('{0} Release Notes', [version])"
|
||||
@click="updateOsActionsStore.viewReleaseNotes(t('{0} Release Notes', [version]), '/boot/previous/changes.txt')"
|
||||
/>
|
||||
<BrandButton
|
||||
v-if="diagnosticsButton"
|
||||
:btn-style="'gray'"
|
||||
:icon="diagnosticsButton.icon"
|
||||
:name="diagnosticsButton.name"
|
||||
:text="diagnosticsButton.text"
|
||||
@click="diagnosticsButton.click"
|
||||
/>
|
||||
<BrandButton
|
||||
:btn-style="'gray'"
|
||||
:external="true"
|
||||
:href="FORUMS_BUG_REPORT.toString()"
|
||||
:icon="LifebuoyIcon"
|
||||
:icon-right="ArrowTopRightOnSquareIcon"
|
||||
:text="t('Open a bug report')"
|
||||
/>
|
||||
<BrandButton
|
||||
:btn-style="'underline'"
|
||||
:icon="InformationCircleIcon"
|
||||
:text="t('{0} Release Notes', [version])"
|
||||
@click="updateOsActionsStore.viewReleaseNotes(t('{0} Release Notes', [version]), '/boot/previous/changes.txt')"
|
||||
/>
|
||||
<BrandButton
|
||||
:external="downgradeButton?.external"
|
||||
:icon="ArrowUturnDownIcon"
|
||||
|
||||
@@ -223,7 +223,7 @@
|
||||
"Downgrade Unraid OS": "Downgrade Unraid OS",
|
||||
"Downgrade Unraid OS to {0}": "Downgrade Unraid OS to {0}",
|
||||
"No downgrade available": "No downgrade available",
|
||||
"Begin restore to Unraid {0}": "Begin restore to Unraid {0}",
|
||||
"Begin downgrade to {0}": "Begin downgrade to {0}",
|
||||
"Version available for restore {0}": "Version available for restore {0}",
|
||||
"check for OS updates": "check for OS updates",
|
||||
"Check for Prereleases": "Check for Prereleases",
|
||||
@@ -235,7 +235,9 @@
|
||||
"View Changelog & Update": "View Changelog & Update",
|
||||
"{0} Release Notes": "{0} Release Notes",
|
||||
"Unable to open release notes": "Unable to open release notes",
|
||||
"Downgrades are only recommended if you're unable to solve a critical issue. In the rare event you need to downgrade we ask that you please provide us with Diagnostics so we can investigate your issue. You will be prompted with the option to download the Diagnostics zip once the downgrade process is started. From there please open a bug report on our forums with a description of the issue and include your diagnostics.": "Downgrades are only recommended if you're unable to solve a critical issue. In the rare event you need to downgrade we ask that you please provide us with Diagnostics so we can investigate your issue. You will be prompted with the option to download the Diagnostics zip once the downgrade process is started. From there please open a bug report on our forums with a description of the issue and include your diagnostics.",
|
||||
"Downgrades are only recommended if you're unable to solve a critical issue.": "Downgrades are only recommended if you're unable to solve a critical issue.",
|
||||
"In the rare event you need to downgrade we ask that you please provide us with Diagnostics so we can investigate your issue.": "In the rare event you need to downgrade we ask that you please provide us with Diagnostics so we can investigate your issue.",
|
||||
"Download the Diagnostics zip then please open a bug report on our forums with a description of the issue along with your diagnostics.": "Download the Diagnostics zip then please open a bug report on our forums with a description of the issue along with your diagnostics.",
|
||||
"Reboot Now to Downgrade": "Reboot Now to Downgrade",
|
||||
"Reboot Now to Update": "Reboot Now to Update",
|
||||
"Reboot Now to Downgrade to {0}": "Reboot Now to Downgrade to {0}",
|
||||
|
||||
@@ -187,7 +187,6 @@ export const useCallbackStoreGeneric = (
|
||||
).toString();
|
||||
/**
|
||||
* Build and go to url
|
||||
* @note – /Tools/Update redirects to account.unraid.net/server/update-os we need to prevent any callback sends to that url to prevent redirect loops
|
||||
*/
|
||||
const destinationUrl = new URL(url.replace('/Tools/Update', '/Main'));
|
||||
destinationUrl.searchParams.set('data', encodeURI(encryptedMessage));
|
||||
|
||||
Reference in New Issue
Block a user