Skip to content

Commit

Permalink
feat(update): added loading spinners (#3321)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jan 12, 2025
1 parent 1d3c5d6 commit 29195fb
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 97 deletions.
192 changes: 96 additions & 96 deletions phpmyfaq/admin/assets/src/configuration/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,125 +192,125 @@ export const handleCheckForUpdates = () => {
if (installButton) {
installButton.addEventListener('click', async (event) => {
event.preventDefault();
const spinner = document.getElementById('spinner-install-package');
spinner.classList.remove('d-none');
await createTemporaryBackup();
spinner.classList.add('d-none');
});
}
};

const createTemporaryBackup = async () => {
await fetch('./api/create-temporary-backup', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
})
.then(async (response) => {
const progressBarBackup = document.getElementById('result-backup-package');
const reader = response.body.getReader();

function pump() {
return reader.read().then(({ done, value }) => {
const decodedValue = new TextDecoder().decode(value);

if (done) {
progressBarBackup.style.width = '100%';
progressBarBackup.innerText = '100%';
progressBarBackup.classList.remove('progress-bar-animated');
return;
} else {
progressBarBackup.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
progressBarBackup.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
}

return pump();
});
try {
const response = await fetch('./api/create-temporary-backup', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
});

const progressBarBackup = document.getElementById('result-backup-package');
const reader = response.body.getReader();

async function pump() {
const { done, value } = await reader.read();
const decodedValue = new TextDecoder().decode(value);

if (done) {
progressBarBackup.style.width = '100%';
progressBarBackup.innerText = '100%';
progressBarBackup.classList.remove('progress-bar-animated');
return;
} else {
progressBarBackup.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
progressBarBackup.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
}

return pump();
})
.catch((error) => {
console.error(error);
});
}

await pump();
} catch (error) {
console.error(error);
}

await installPackage();
};

const installPackage = async () => {
await fetch('./api/install-package', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
})
.then(async (response) => {
const progressBarInstallation = document.getElementById('result-install-package');
const reader = response.body.getReader();
const card = document.getElementById('pmf-update-step-install-package');

function pump() {
return reader.read().then(({ done, value }) => {
const decodedValue = new TextDecoder().decode(value);

if (done) {
progressBarInstallation.style.width = '100%';
progressBarInstallation.innerText = '100%';
progressBarInstallation.classList.remove('progress-bar-animated');
return;
} else {
progressBarInstallation.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
progressBarInstallation.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
}

return pump();
});
try {
const response = await fetch('./api/install-package', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
});

const progressBarInstallation = document.getElementById('result-install-package');
const reader = response.body.getReader();
const card = document.getElementById('pmf-update-step-install-package');

async function pump() {
const { done, value } = await reader.read();
const decodedValue = new TextDecoder().decode(value);

if (done) {
progressBarInstallation.style.width = '100%';
progressBarInstallation.innerText = '100%';
progressBarInstallation.classList.remove('progress-bar-animated');
return;
} else {
progressBarInstallation.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
progressBarInstallation.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
}

return pump();
})
.catch((error) => {
console.error(error);
});
}

await pump();
} catch (error) {
console.error(error);
}

await updateDatabase();
};

const updateDatabase = async () => {
await fetch('./api/update-database', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
})
.then(async (response) => {
const progressBarInstallation = document.getElementById('result-update-database');
const reader = response.body.getReader();
const card = document.getElementById('pmf-update-step-install-package');

function pump() {
return reader.read().then(({ done, value }) => {
const decodedValue = new TextDecoder().decode(value);

if (done) {
progressBarInstallation.style.width = '100%';
progressBarInstallation.innerText = '100%';
progressBarInstallation.classList.remove('progress-bar-animated');
card.classList.add('text-bg-success');
return;
} else {
progressBarInstallation.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
progressBarInstallation.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
}

return pump();
});
try {
const response = await fetch('./api/update-database', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
});

const progressBarInstallation = document.getElementById('result-update-database');
const reader = response.body.getReader();
const card = document.getElementById('pmf-update-step-install-package');

async function pump() {
const { done, value } = await reader.read();
const decodedValue = new TextDecoder().decode(value);

if (done) {
progressBarInstallation.style.width = '100%';
progressBarInstallation.innerText = '100%';
progressBarInstallation.classList.remove('progress-bar-animated');
card.classList.add('text-bg-success');
return;
} else {
progressBarInstallation.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
progressBarInstallation.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
}

return pump();
})
.catch((error) => {
console.error(error);
});
}

await pump();
} catch (error) {
console.error(error);
}
};
2 changes: 1 addition & 1 deletion phpmyfaq/assets/templates/admin/configuration/upgrade.twig
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<div>
<button type="button" class="btn btn-primary mb-2" id="pmf-button-install-package">
{{ 'msgInstallDownloadedPackage' | translate }}
<div class="spinner-border spinner-border-sm ms-2 d-none" role="status">
<div class="spinner-border spinner-border-sm ms-2 d-none" id="spinner-install-package" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</button>
Expand Down

0 comments on commit 29195fb

Please sign in to comment.