add branch validation to queue

This commit is contained in:
2025-12-22 14:26:59 +01:00
parent 873e43ed95
commit c581305dcd
8 changed files with 554 additions and 14 deletions

View File

@@ -13,7 +13,7 @@
<div class="job-list">
{% if jobs %}
{% for job in jobs %}
<div class="job-item" data-job-id="{{ job.id }}" onclick="loadJobDetails({{ job.id }})">
<div class="job-item" data-job-id="{{ job.id }}" onclick="loadJobDetails({{ job.id }})" oncontextmenu="showContextMenu(event, {{ job.id }}, '{{ job.status }}')">
<div class="job-status-icon">{{ job.get_status_icon() }}</div>
<div class="job-info">
<h4>Job #{{ job.id }} - {{ job.branch_name }}</h4>
@@ -44,7 +44,48 @@
</div>
</div>
<!-- Context Menu -->
<div id="contextMenu" class="context-menu">
<div class="context-menu-item" onclick="abortJobFromContext()">
<span class="context-menu-icon"></span>
Abort Job
</div>
</div>
<script>
let contextJobId = null;
function showContextMenu(event, jobId, status) {
event.preventDefault();
// Only show context menu for in_progress jobs
if (status !== 'in_progress') {
return;
}
contextJobId = jobId;
const contextMenu = document.getElementById('contextMenu');
contextMenu.style.display = 'block';
contextMenu.style.left = event.pageX + 'px';
contextMenu.style.top = event.pageY + 'px';
// Hide context menu when clicking elsewhere
document.addEventListener('click', hideContextMenu);
}
function hideContextMenu() {
document.getElementById('contextMenu').style.display = 'none';
document.removeEventListener('click', hideContextMenu);
contextJobId = null;
}
function abortJobFromContext() {
if (contextJobId) {
abortJob(contextJobId);
}
hideContextMenu();
}
function loadJobDetails(jobId) {
// Mark job as active
document.querySelectorAll('.job-item').forEach(item => {

View File

@@ -29,7 +29,7 @@
</div>
</div>
<form method="POST" action="{{ url_for('jobs.submit_step1') }}">
<form id="branchForm">
<div class="form-group">
<label for="branch_name">Git Branch Name</label>
<input type="text" id="branch_name" name="branch_name" class="form-control"
@@ -37,12 +37,132 @@
<small style="color: #6b7280; margin-top: 5px; display: block;">
Enter the branch name to analyze available test scenarios
</small>
<div id="branchValidation" class="branch-validation">
<div class="loading-spinner"></div>
<span id="validationMessage">Validating branch...</span>
</div>
</div>
<div class="form-actions">
<a href="{{ url_for('dashboard.index') }}" class="btn" style="background: #6b7280; color: white;">Cancel</a>
<button type="submit" class="btn btn-primary">Next</button>
<button type="submit" id="validateBtn" class="btn btn-primary">Validate Branch</button>
<button type="button" id="nextBtn" class="btn btn-primary" style="display: none;" onclick="proceedToStep2()">Next</button>
</div>
</form>
</div>
<script>
let validatedBranch = null;
let availableScenarios = [];
document.getElementById('branchForm').addEventListener('submit', function(e) {
e.preventDefault();
validateBranch();
});
function validateBranch() {
const branchName = document.getElementById('branch_name').value.trim();
if (!branchName) {
alert('Please enter a branch name');
return;
}
// Show loading state
const validation = document.getElementById('branchValidation');
const message = document.getElementById('validationMessage');
const validateBtn = document.getElementById('validateBtn');
const nextBtn = document.getElementById('nextBtn');
validation.className = 'branch-validation loading';
validation.style.display = 'block';
message.textContent = 'Validating branch...';
validateBtn.disabled = true;
nextBtn.style.display = 'none';
// Make AJAX request
fetch('/jobs/submit/step1', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `branch_name=${encodeURIComponent(branchName)}`
})
.then(response => response.json())
.then(data => {
if (data.success) {
// Success
validation.className = 'branch-validation success';
message.textContent = data.message;
validateBtn.style.display = 'none';
nextBtn.style.display = 'inline-block';
validatedBranch = branchName;
availableScenarios = data.scenarios;
} else {
// Error
validation.className = 'branch-validation error';
message.textContent = data.error;
validateBtn.disabled = false;
nextBtn.style.display = 'none';
validatedBranch = null;
availableScenarios = [];
}
})
.catch(error => {
// Network error
validation.className = 'branch-validation error';
message.textContent = 'Network error. Please try again.';
validateBtn.disabled = false;
nextBtn.style.display = 'none';
validatedBranch = null;
availableScenarios = [];
});
}
function proceedToStep2() {
if (!validatedBranch || !availableScenarios.length) {
alert('Please validate the branch first');
return;
}
// Create form to submit to step 2
const form = document.createElement('form');
form.method = 'POST';
form.action = '/jobs/submit/step2-validated';
const branchInput = document.createElement('input');
branchInput.type = 'hidden';
branchInput.name = 'branch_name';
branchInput.value = validatedBranch;
form.appendChild(branchInput);
const scenariosInput = document.createElement('input');
scenariosInput.type = 'hidden';
scenariosInput.name = 'scenarios';
scenariosInput.value = JSON.stringify(availableScenarios);
form.appendChild(scenariosInput);
document.body.appendChild(form);
form.submit();
}
// Reset validation when branch name changes
document.getElementById('branch_name').addEventListener('input', function() {
const validation = document.getElementById('branchValidation');
const validateBtn = document.getElementById('validateBtn');
const nextBtn = document.getElementById('nextBtn');
validation.style.display = 'none';
validateBtn.style.display = 'inline-block';
validateBtn.disabled = false;
nextBtn.style.display = 'none';
validatedBranch = null;
availableScenarios = [];
});
</script>
{% endblock %}