initial commit
This commit is contained in:
446
templates/variants.html
Normal file
446
templates/variants.html
Normal file
@@ -0,0 +1,446 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Variant Manager - UM KiCad</title>
|
||||
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 1200px;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
border-bottom: 3px solid #007bff;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.status {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.status.connected {
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
}
|
||||
.status.disconnected {
|
||||
background-color: #dc3545;
|
||||
color: white;
|
||||
}
|
||||
.container {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
margin-top: 20px;
|
||||
}
|
||||
.btn {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
margin: 5px;
|
||||
}
|
||||
.btn:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
.btn.secondary {
|
||||
background-color: #6c757d;
|
||||
}
|
||||
.btn.secondary:hover {
|
||||
background-color: #545b62;
|
||||
}
|
||||
.btn.danger {
|
||||
background-color: #dc3545;
|
||||
}
|
||||
.btn.danger:hover {
|
||||
background-color: #c82333;
|
||||
}
|
||||
.btn.success {
|
||||
background-color: #28a745;
|
||||
}
|
||||
.btn.success:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
.variant-card {
|
||||
border: 2px solid #dee2e6;
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
margin: 10px 0;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
.variant-card.active {
|
||||
border-color: #007bff;
|
||||
background-color: #e7f3ff;
|
||||
}
|
||||
.variant-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.variant-name {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
color: #007bff;
|
||||
}
|
||||
.variant-description {
|
||||
color: #666;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.variant-stats {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background-color: rgba(0,0,0,0.4);
|
||||
}
|
||||
.modal-content {
|
||||
background-color: #fefefe;
|
||||
margin: 10% auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #888;
|
||||
border-radius: 8px;
|
||||
width: 50%;
|
||||
max-width: 500px;
|
||||
}
|
||||
.close {
|
||||
color: #aaa;
|
||||
float: right;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
.close:hover {
|
||||
color: black;
|
||||
}
|
||||
.form-group {
|
||||
margin: 15px 0;
|
||||
}
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group textarea,
|
||||
.form-group select {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.parts-list {
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
background-color: white;
|
||||
}
|
||||
.part-item {
|
||||
padding: 8px;
|
||||
border-bottom: 1px solid #eee;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.part-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.part-item.dnp {
|
||||
background-color: #fff3cd;
|
||||
}
|
||||
.nav-link {
|
||||
display: inline-block;
|
||||
margin: 10px 10px 10px 0;
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
}
|
||||
.nav-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.message {
|
||||
margin-top: 15px;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
display: none;
|
||||
}
|
||||
.message.success {
|
||||
background-color: #d4edda;
|
||||
color: #155724;
|
||||
border: 1px solid #c3e6cb;
|
||||
}
|
||||
.message.error {
|
||||
background-color: #f8d7da;
|
||||
color: #721c24;
|
||||
border: 1px solid #f5c6cb;
|
||||
}
|
||||
.message.info {
|
||||
background-color: #d1ecf1;
|
||||
color: #0c5460;
|
||||
border: 1px solid #bee5eb;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="status" class="status disconnected">Disconnected</div>
|
||||
|
||||
<a href="/" class="nav-link">← Back to Main</a>
|
||||
|
||||
<h1>Variant Manager</h1>
|
||||
|
||||
<div class="container">
|
||||
<h2>Project: <span id="projectName">Loading...</span></h2>
|
||||
<button id="createVariantBtn" class="btn">+ Create New Variant</button>
|
||||
<button id="syncFromSchematicBtn" class="btn secondary">Sync from Schematic</button>
|
||||
<div id="message" class="message"></div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<h2>Variants</h2>
|
||||
<div id="variantsList"></div>
|
||||
</div>
|
||||
|
||||
<!-- Create Variant Modal -->
|
||||
<div id="createModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close" onclick="closeCreateModal()">×</span>
|
||||
<h2>Create New Variant</h2>
|
||||
<div class="form-group">
|
||||
<label for="variantName">Variant Name:</label>
|
||||
<input type="text" id="variantName" placeholder="e.g., low-cost, premium">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="variantDescription">Description:</label>
|
||||
<textarea id="variantDescription" rows="3" placeholder="Description of this variant"></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="basedOn">Based On:</label>
|
||||
<select id="basedOn">
|
||||
<option value="">Empty (no parts DNP)</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn" onclick="createVariant()">Create</button>
|
||||
<button class="btn secondary" onclick="closeCreateModal()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Edit Parts Modal -->
|
||||
<div id="editPartsModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close" onclick="closeEditPartsModal()">×</span>
|
||||
<h2>Edit Parts: <span id="editVariantName"></span></h2>
|
||||
<p>Toggle parts between Fitted and DNP (Do Not Place)</p>
|
||||
<div class="parts-list" id="partsList"></div>
|
||||
<button class="btn" onclick="closeEditPartsModal()">Done</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const socket = io();
|
||||
const statusEl = document.getElementById('status');
|
||||
let currentVariant = '';
|
||||
let allParts = [];
|
||||
|
||||
socket.on('connect', () => {
|
||||
statusEl.textContent = 'Connected';
|
||||
statusEl.className = 'status connected';
|
||||
loadVariants();
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
statusEl.textContent = 'Disconnected';
|
||||
statusEl.className = 'status disconnected';
|
||||
});
|
||||
|
||||
function showMessage(text, type) {
|
||||
const messageEl = document.getElementById('message');
|
||||
messageEl.textContent = text;
|
||||
messageEl.className = 'message ' + type;
|
||||
messageEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
messageEl.style.display = 'none';
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function loadVariants() {
|
||||
socket.emit('get_variants');
|
||||
}
|
||||
|
||||
socket.on('variants_data', (data) => {
|
||||
document.getElementById('projectName').textContent = data.project_name;
|
||||
currentVariant = data.active_variant;
|
||||
allParts = data.all_parts || [];
|
||||
renderVariants(data.variants, data.active_variant);
|
||||
updateBasedOnSelect(data.variants);
|
||||
});
|
||||
|
||||
function renderVariants(variants, activeVariant) {
|
||||
const list = document.getElementById('variantsList');
|
||||
list.innerHTML = '';
|
||||
|
||||
for (const [name, variant] of Object.entries(variants)) {
|
||||
const isActive = name === activeVariant;
|
||||
const card = document.createElement('div');
|
||||
card.className = 'variant-card' + (isActive ? ' active' : '');
|
||||
|
||||
const dnpCount = variant.dnp_parts.length;
|
||||
const fittedCount = allParts.length - dnpCount;
|
||||
|
||||
card.innerHTML = `
|
||||
<div class="variant-header">
|
||||
<div class="variant-name">${variant.name}${isActive ? ' (Active)' : ''}</div>
|
||||
<div>
|
||||
${!isActive ? `<button class="btn success" onclick="activateVariant('${name}')">Activate</button>` : ''}
|
||||
<button class="btn" onclick="editParts('${name}')">Edit Parts</button>
|
||||
${name !== 'default' ? `<button class="btn danger" onclick="deleteVariant('${name}')">Delete</button>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
<div class="variant-description">${variant.description || 'No description'}</div>
|
||||
<div class="variant-stats">
|
||||
Fitted: ${fittedCount} | DNP: ${dnpCount} | Total: ${allParts.length}
|
||||
</div>
|
||||
`;
|
||||
|
||||
list.appendChild(card);
|
||||
}
|
||||
}
|
||||
|
||||
function updateBasedOnSelect(variants) {
|
||||
const select = document.getElementById('basedOn');
|
||||
select.innerHTML = '<option value="">Empty (no parts DNP)</option>';
|
||||
for (const name of Object.keys(variants)) {
|
||||
const option = document.createElement('option');
|
||||
option.value = name;
|
||||
option.textContent = name;
|
||||
select.appendChild(option);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('createVariantBtn').addEventListener('click', () => {
|
||||
document.getElementById('createModal').style.display = 'block';
|
||||
});
|
||||
|
||||
function closeCreateModal() {
|
||||
document.getElementById('createModal').style.display = 'none';
|
||||
document.getElementById('variantName').value = '';
|
||||
document.getElementById('variantDescription').value = '';
|
||||
document.getElementById('basedOn').value = '';
|
||||
}
|
||||
|
||||
function createVariant() {
|
||||
const name = document.getElementById('variantName').value.trim();
|
||||
const description = document.getElementById('variantDescription').value.trim();
|
||||
const basedOn = document.getElementById('basedOn').value;
|
||||
|
||||
if (!name) {
|
||||
alert('Please enter a variant name');
|
||||
return;
|
||||
}
|
||||
|
||||
socket.emit('create_variant', { name, description, based_on: basedOn });
|
||||
closeCreateModal();
|
||||
}
|
||||
|
||||
function deleteVariant(name) {
|
||||
if (confirm(`Are you sure you want to delete variant "${name}"?`)) {
|
||||
socket.emit('delete_variant', { name });
|
||||
}
|
||||
}
|
||||
|
||||
function activateVariant(name) {
|
||||
if (confirm(`Activate variant "${name}"? This will apply DNP settings to the schematic.`)) {
|
||||
socket.emit('activate_variant', { name });
|
||||
}
|
||||
}
|
||||
|
||||
function editParts(variantName) {
|
||||
currentVariant = variantName;
|
||||
document.getElementById('editVariantName').textContent = variantName;
|
||||
socket.emit('get_variant_parts', { variant: variantName });
|
||||
}
|
||||
|
||||
function closeEditPartsModal() {
|
||||
document.getElementById('editPartsModal').style.display = 'none';
|
||||
}
|
||||
|
||||
socket.on('variant_parts_data', (data) => {
|
||||
const list = document.getElementById('partsList');
|
||||
list.innerHTML = '';
|
||||
|
||||
for (const part of data.parts) {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'part-item' + (part.is_dnp ? ' dnp' : '');
|
||||
item.innerHTML = `
|
||||
<div>
|
||||
<strong>${part.reference}</strong> - ${part.value || 'N/A'}
|
||||
${part.is_dnp ? '<span style="color: #856404; margin-left: 10px;">[DNP]</span>' : ''}
|
||||
</div>
|
||||
<button class="btn ${part.is_dnp ? 'success' : 'secondary'}"
|
||||
onclick="togglePartDNP('${part.reference}', ${!part.is_dnp})">
|
||||
${part.is_dnp ? 'Fit' : 'DNP'}
|
||||
</button>
|
||||
`;
|
||||
list.appendChild(item);
|
||||
}
|
||||
|
||||
document.getElementById('editPartsModal').style.display = 'block';
|
||||
});
|
||||
|
||||
function togglePartDNP(reference, isDNP) {
|
||||
socket.emit('set_part_dnp', {
|
||||
variant: currentVariant,
|
||||
reference: reference,
|
||||
is_dnp: isDNP
|
||||
});
|
||||
}
|
||||
|
||||
socket.on('variant_updated', (data) => {
|
||||
showMessage(data.message, 'success');
|
||||
loadVariants();
|
||||
});
|
||||
|
||||
socket.on('variant_error', (data) => {
|
||||
showMessage(data.error, 'error');
|
||||
});
|
||||
|
||||
document.getElementById('syncFromSchematicBtn').addEventListener('click', () => {
|
||||
if (confirm('Sync variant from current schematic state? This will update DNP settings based on the schematic.')) {
|
||||
socket.emit('sync_from_schematic');
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('sync_complete', (data) => {
|
||||
showMessage(data.message, 'success');
|
||||
loadVariants();
|
||||
});
|
||||
|
||||
// Close modals when clicking outside
|
||||
window.onclick = function(event) {
|
||||
if (event.target.className === 'modal') {
|
||||
event.target.style.display = 'none';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user