Update start and better volume names
This commit is contained in:
@@ -4,6 +4,7 @@ let editInstanceModal;
|
||||
let addExistingInstanceModal;
|
||||
let authModal;
|
||||
let launchStepsModal;
|
||||
let updateInstanceModal;
|
||||
let currentStep = 1;
|
||||
|
||||
// Update the total number of steps
|
||||
@@ -15,6 +16,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
addExistingInstanceModal = new bootstrap.Modal(document.getElementById('addExistingInstanceModal'));
|
||||
authModal = new bootstrap.Modal(document.getElementById('authModal'));
|
||||
launchStepsModal = new bootstrap.Modal(document.getElementById('launchStepsModal'));
|
||||
updateInstanceModal = new bootstrap.Modal(document.getElementById('updateInstanceModal'));
|
||||
|
||||
// Initialize tooltips
|
||||
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
||||
@@ -1774,4 +1776,168 @@ async function confirmDeleteInstance() {
|
||||
confirmDeleteBtn.className = 'btn btn-danger';
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update Instance Functions
|
||||
function showUpdateInstanceModal(instanceId, stackName, instanceUrl) {
|
||||
document.getElementById('update_instance_id').value = instanceId;
|
||||
document.getElementById('update_stack_name').value = stackName;
|
||||
document.getElementById('update_instance_url').value = instanceUrl;
|
||||
|
||||
// Load repositories for the update modal
|
||||
loadUpdateRepositories();
|
||||
|
||||
updateInstanceModal.show();
|
||||
}
|
||||
|
||||
async function loadUpdateRepositories() {
|
||||
const repoSelect = document.getElementById('updateRepoSelect');
|
||||
const branchSelect = document.getElementById('updateBranchSelect');
|
||||
|
||||
try {
|
||||
// Reset branch select
|
||||
branchSelect.innerHTML = '<option value="">Select a repository first</option>';
|
||||
branchSelect.disabled = true;
|
||||
|
||||
const gitSettings = window.gitSettings || {};
|
||||
if (!gitSettings.url || !gitSettings.token) {
|
||||
throw new Error('No Git settings found. Please configure Git in the settings page.');
|
||||
}
|
||||
|
||||
// Load repositories using the correct existing endpoint
|
||||
const repoResponse = await fetch('/api/admin/list-gitea-repos', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url: gitSettings.url,
|
||||
token: gitSettings.token
|
||||
})
|
||||
});
|
||||
|
||||
if (!repoResponse.ok) {
|
||||
throw new Error('Failed to load repositories');
|
||||
}
|
||||
|
||||
const data = await repoResponse.json();
|
||||
|
||||
if (data.repositories && data.repositories.length > 0) {
|
||||
repoSelect.innerHTML = '<option value="">Select a repository</option>' +
|
||||
data.repositories.map(repo =>
|
||||
`<option value="${repo.full_name}" ${repo.full_name === gitSettings.repo ? 'selected' : ''}>${repo.full_name}</option>`
|
||||
).join('');
|
||||
repoSelect.disabled = false;
|
||||
|
||||
// If we have a saved repository, load its branches
|
||||
if (gitSettings.repo) {
|
||||
loadUpdateBranches(gitSettings.repo);
|
||||
}
|
||||
} else {
|
||||
repoSelect.innerHTML = '<option value="">No repositories found</option>';
|
||||
repoSelect.disabled = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading repositories for update:', error);
|
||||
repoSelect.innerHTML = `<option value="">Error: ${error.message}</option>`;
|
||||
repoSelect.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUpdateBranches(repoId) {
|
||||
const branchSelect = document.getElementById('updateBranchSelect');
|
||||
|
||||
if (!repoId) {
|
||||
branchSelect.innerHTML = '<option value="">Select a repository first</option>';
|
||||
branchSelect.disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const gitSettings = window.gitSettings || {};
|
||||
if (!gitSettings.url || !gitSettings.token) {
|
||||
throw new Error('No Git settings found. Please configure Git in the settings page.');
|
||||
}
|
||||
|
||||
const response = await fetch('/api/admin/list-gitea-branches', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url: gitSettings.url,
|
||||
token: gitSettings.token,
|
||||
repo: repoId
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to load branches');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.branches && data.branches.length > 0) {
|
||||
branchSelect.innerHTML = '<option value="">Select a branch</option>' +
|
||||
data.branches.map(branch =>
|
||||
`<option value="${branch.name}" ${branch.name === 'master' ? 'selected' : ''}>${branch.name}</option>`
|
||||
).join('');
|
||||
branchSelect.disabled = false;
|
||||
} else {
|
||||
branchSelect.innerHTML = '<option value="">No branches found</option>';
|
||||
branchSelect.disabled = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading branches for update:', error);
|
||||
branchSelect.innerHTML = `<option value="">Error: ${error.message}</option>`;
|
||||
branchSelect.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function startInstanceUpdate() {
|
||||
const instanceId = document.getElementById('update_instance_id').value;
|
||||
const stackName = document.getElementById('update_stack_name').value;
|
||||
const instanceUrl = document.getElementById('update_instance_url').value;
|
||||
const repoId = document.getElementById('updateRepoSelect').value;
|
||||
const branch = document.getElementById('updateBranchSelect').value;
|
||||
|
||||
if (!repoId || !branch) {
|
||||
alert('Please select both a repository and a branch.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Store update data in sessionStorage for the launch progress page
|
||||
const updateData = {
|
||||
instanceId: instanceId,
|
||||
stackName: stackName,
|
||||
instanceUrl: instanceUrl,
|
||||
repository: repoId,
|
||||
branch: branch,
|
||||
isUpdate: true
|
||||
};
|
||||
sessionStorage.setItem('instanceUpdateData', JSON.stringify(updateData));
|
||||
|
||||
// Close the modal
|
||||
updateInstanceModal.hide();
|
||||
|
||||
// Redirect to launch progress page with update parameters
|
||||
window.location.href = `/instances/launch-progress?update=true&instance_id=${instanceId}&repo=${repoId}&branch=${encodeURIComponent(branch)}`;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error starting instance update:', error);
|
||||
alert('Error starting update: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Add event listeners for update modal
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const updateRepoSelect = document.getElementById('updateRepoSelect');
|
||||
if (updateRepoSelect) {
|
||||
updateRepoSelect.addEventListener('change', function() {
|
||||
loadUpdateBranches(this.value);
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user