diff --git a/apps/pusher_app/appserver/static/git_pusher.js b/apps/pusher_app/appserver/static/git_pusher.js index ddb5ff7f..ce7e161b 100755 --- a/apps/pusher_app/appserver/static/git_pusher.js +++ b/apps/pusher_app/appserver/static/git_pusher.js @@ -99,6 +99,9 @@ function initScript() { // Charger les applications loadAvailableApps(); + // Charger les credentials sauvegardés + loadSavedCredentials(); + // Attacher les event listeners au bouton const pushBtn = document.getElementById('push-btn'); if (pushBtn) { @@ -111,6 +114,85 @@ function initScript() { } else { console.warn("Push button not found"); } + + // Attacher l'event listener pour sauvegarder les credentials + const saveCheckbox = document.getElementById('save-credentials'); + if (saveCheckbox) { + saveCheckbox.addEventListener('change', function() { + if (this.checked) { + saveCredentials(); + } else { + clearSavedCredentials(); + } + }); + } +} + +function loadSavedCredentials() { + console.log("Loading saved credentials..."); + + try { + const savedUrl = localStorage.getItem('git_pusher_url'); + const savedToken = localStorage.getItem('git_pusher_token'); + const savedBranch = localStorage.getItem('git_pusher_branch'); + + if (savedUrl) { + document.getElementById('git-url').value = savedUrl; + console.log("Loaded saved URL"); + } + + if (savedToken) { + document.getElementById('git-token').value = savedToken; + console.log("Loaded saved token"); + } + + if (savedBranch) { + document.getElementById('git-branch').value = savedBranch; + } + + if (savedUrl && savedToken) { + document.getElementById('save-credentials').checked = true; + } + } catch (e) { + console.warn("Could not load saved credentials:", e); + } +} + +function saveCredentials() { + console.log("Saving credentials..."); + + try { + const gitUrl = document.getElementById('git-url').value; + const gitToken = document.getElementById('git-token').value; + const gitBranch = document.getElementById('git-branch').value; + + if (gitUrl && gitToken) { + localStorage.setItem('git_pusher_url', gitUrl); + localStorage.setItem('git_pusher_token', gitToken); + localStorage.setItem('git_pusher_branch', gitBranch); + console.log("Credentials saved successfully"); + showSuccess("Credentials saved locally"); + } else { + showError("Please fill in URL and Token before saving"); + } + } catch (e) { + console.error("Error saving credentials:", e); + showError("Could not save credentials"); + } +} + +function clearSavedCredentials() { + console.log("Clearing saved credentials..."); + + try { + localStorage.removeItem('git_pusher_url'); + localStorage.removeItem('git_pusher_token'); + localStorage.removeItem('git_pusher_branch'); + console.log("Credentials cleared"); + showSuccess("Credentials cleared"); + } catch (e) { + console.error("Error clearing credentials:", e); + } } if (document.readyState === 'loading') { @@ -303,6 +385,18 @@ function pushDashboards() { document.getElementById('error-msg').style.display = 'none'; document.getElementById('push-btn').disabled = true; + // Sauvegarder les credentials si la case est cochée + if (document.getElementById('save-credentials').checked) { + try { + localStorage.setItem('git_pusher_url', gitUrl); + localStorage.setItem('git_pusher_token', gitToken); + localStorage.setItem('git_pusher_branch', gitBranch); + console.log("Credentials auto-saved"); + } catch (e) { + console.warn("Could not auto-save credentials:", e); + } + } + // Préparer les données - passer les apps au lieu des dashboards const payload = { git_url: gitUrl, @@ -403,4 +497,13 @@ function resetForm() { document.getElementById('git-token').value = ''; document.getElementById('commit-message').value = ''; document.querySelectorAll('#dashboard-list input[type="checkbox"]').forEach(cb => cb.checked = false); + + // Demander si l'utilisateur veut aussi effacer les credentials sauvegardés + if (document.getElementById('save-credentials').checked) { + const confirmClear = confirm('Do you want to clear saved credentials?'); + if (confirmClear) { + clearSavedCredentials(); + document.getElementById('save-credentials').checked = false; + } + } } \ No newline at end of file diff --git a/apps/pusher_app/local/data/ui/views/git_pusher_-_push_applications_to_git.xml b/apps/pusher_app/local/data/ui/views/git_pusher_-_push_applications_to_git.xml index fe239894..78cc7b42 100644 --- a/apps/pusher_app/local/data/ui/views/git_pusher_-_push_applications_to_git.xml +++ b/apps/pusher_app/local/data/ui/views/git_pusher_-_push_applications_to_git.xml @@ -190,6 +190,11 @@ + +
+ + +
diff --git a/apps/pusher_app/metadata/local.meta b/apps/pusher_app/metadata/local.meta index c4b43f70..e657d329 100644 --- a/apps/pusher_app/metadata/local.meta +++ b/apps/pusher_app/metadata/local.meta @@ -16,4 +16,4 @@ modtime = 1769276443.812957000 [views/git_pusher_-_push_applications_to_git] owner = admin version = 10.0.2 -modtime = 1769292908.163699000 +modtime = 1769294522.256010000