Initial commit

This commit is contained in:
2025-10-05 13:10:12 +01:00
commit 32ef7401e3
14 changed files with 8442 additions and 0 deletions

981
ui_template_config.py Normal file
View File

@@ -0,0 +1,981 @@
#!/usr/bin/env python3
"""
ui_template_config.py - Configuration Management HTML Template
Contains the configuration interface for managing trading pairs, indicators,
gap filling settings, and system configuration
"""
def get_config_html():
"""Return the configuration management HTML"""
return """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Configuration - Trading Intelligence System</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
color: #e0e0e0;
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
}
.header {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 25px;
margin-bottom: 25px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.header h1 {
font-size: 2.2em;
background: linear-gradient(to right, #4facfe, #00f2fe);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 10px;
}
.nav-tabs {
display: flex;
gap: 15px;
margin-top: 20px;
}
.nav-tab {
padding: 12px 24px;
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 8px;
color: #e0e0e0;
text-decoration: none;
font-weight: 500;
transition: all 0.3s ease;
}
.nav-tab:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
}
.nav-tab.active {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-color: #667eea;
}
.section {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 25px;
margin-bottom: 25px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.section h2 {
font-size: 1.5em;
margin-bottom: 20px;
color: #ffffff;
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
font-size: 0.95em;
display: inline-block;
margin-right: 10px;
margin-bottom: 10px;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.btn-secondary {
background: rgba(255, 255, 255, 0.1);
color: #e0e0e0;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.2);
}
.btn-success {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
color: white;
}
.btn-success:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(56, 239, 125, 0.4);
}
.btn-danger {
background: linear-gradient(135deg, #eb3349 0%, #f45c43 100%);
color: white;
}
.btn-danger:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(235, 51, 73, 0.4);
}
.btn-sm {
padding: 8px 16px;
font-size: 0.85em;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
background: rgba(0, 0, 0, 0.3);
border-radius: 12px;
overflow: hidden;
}
th, td {
padding: 15px;
text-align: left;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
th {
background: rgba(102, 126, 234, 0.3);
font-weight: 600;
color: #ffffff;
}
tr:hover {
background: rgba(255, 255, 255, 0.05);
}
input, select, textarea {
padding: 12px;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.1);
color: #e0e0e0;
font-size: 0.95em;
width: 100%;
margin-bottom: 10px;
}
input:focus, select:focus, textarea:focus {
outline: none;
border-color: #667eea;
background: rgba(255, 255, 255, 0.15);
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #e0e0e0;
}
.indicator-card {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 15px;
margin-bottom: 15px;
transition: all 0.3s ease;
}
.indicator-card:hover {
background: rgba(255, 255, 255, 0.1);
}
.indicator-card.enabled {
border-color: #38ef7d;
background: rgba(56, 239, 125, 0.1);
}
.indicator-card.disabled {
border-color: #eb3349;
background: rgba(235, 51, 73, 0.1);
}
.indicator-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.indicator-name {
font-weight: bold;
font-size: 1.1em;
text-transform: uppercase;
color: #4facfe;
}
.indicator-periods {
font-size: 0.9em;
color: #a0a0a0;
margin-top: 5px;
}
.status-badge {
padding: 5px 15px;
border-radius: 20px;
font-size: 0.85em;
font-weight: 600;
}
.status-enabled {
background: rgba(56, 239, 125, 0.3);
color: #38ef7d;
}
.status-disabled {
background: rgba(235, 51, 73, 0.3);
color: #eb3349;
}
.alert {
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
display: none;
}
.alert-success {
background: rgba(56, 239, 125, 0.2);
border: 1px solid #38ef7d;
color: #38ef7d;
}
.alert-error {
background: rgba(235, 51, 73, 0.2);
border: 1px solid #eb3349;
color: #eb3349;
}
.alert-info {
background: rgba(79, 172, 254, 0.2);
border: 1px solid #4facfe;
color: #4facfe;
}
.config-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
}
.config-item {
background: rgba(0, 0, 0, 0.3);
padding: 15px;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.config-label {
font-weight: 600;
color: #4facfe;
margin-bottom: 8px;
}
.config-value {
font-size: 0.95em;
color: #e0e0e0;
}
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(5px);
}
.modal-content {
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
margin: 5% auto;
padding: 30px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 15px;
width: 90%;
max-width: 600px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: #fff;
}
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.1);
border-radius: 5px;
}
::-webkit-scrollbar-thumb {
background: rgba(102, 126, 234, 0.5);
border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(102, 126, 234, 0.7);
}
</style>
</head>
<body>
<div class="container">
<!-- Header -->
<div class="header">
<h1>⚙️ System Configuration</h1>
<p>Manage trading pairs, indicators, and system settings</p>
<div class="nav-tabs">
<a href="/" class="nav-tab">Dashboard</a>
<a href="/config" class="nav-tab active">Configuration</a>
<a href="/gaps" class="nav-tab">Gaps</a>
</div>
</div>
<!-- Alert Container -->
<div id="alertContainer"></div>
<!-- Trading Pairs Section -->
<div class="section">
<h2>📊 Trading Pairs</h2>
<button class="btn btn-success" onclick="showAddPairModal()">+ Add Trading Pair</button>
<button class="btn btn-primary" onclick="loadConfig()">🔄 Refresh</button>
<table id="pairsTable">
<thead>
<tr>
<th>Symbol</th>
<th>Enabled</th>
<th>Priority</th>
<th>Record From Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="pairsTableBody">
<tr>
<td colspan="5" style="text-align: center; padding: 40px;">Loading...</td>
</tr>
</tbody>
</table>
</div>
<!-- Technical Indicators Section -->
<div class="section">
<h2>📈 Technical Indicators</h2>
<p style="margin-bottom: 20px; color: #a0a0a0;">Enable or disable technical indicators and configure their parameters</p>
<div id="indicatorsSection">
<div style="text-align: center; padding: 40px;">Loading indicators...</div>
</div>
</div>
<!-- Gap Filling Configuration -->
<div class="section">
<h2>🔧 Gap Filling Configuration</h2>
<div id="gapFillingConfig">
<div style="text-align: center; padding: 40px;">Loading gap filling settings...</div>
</div>
</div>
<!-- Collection Settings -->
<div class="section">
<h2>📥 Collection Settings</h2>
<div id="collectionSettings">
<div style="text-align: center; padding: 40px;">Loading collection settings...</div>
</div>
</div>
<!-- Environment Variables Section -->
<div class="section">
<h2>🔧 Environment Variables</h2>
<div style="margin-bottom: 20px;">
<input type="text" id="newEnvKey" placeholder="Key (e.g., DB_HOST)" style="width: 200px; display: inline-block; margin-right: 10px;">
<input type="text" id="newEnvValue" placeholder="Value" style="width: 300px; display: inline-block; margin-right: 10px;">
<button class="btn btn-primary" onclick="addEnvVar()">+ Add Variable</button>
</div>
<table id="envTable">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="envTableBody">
<tr>
<td colspan="3" style="text-align: center; padding: 40px;">Loading...</td>
</tr>
</tbody>
</table>
</div>
<!-- Save Configuration -->
<div class="section">
<h2>💾 Save Configuration</h2>
<p style="margin-bottom: 20px; color: #a0a0a0;">Save all configuration changes to disk</p>
<button class="btn btn-success" onclick="saveAllConfig()">💾 Save All Changes</button>
<button class="btn btn-secondary" onclick="loadConfig()">🔄 Reload Configuration</button>
</div>
</div>
<!-- Add Trading Pair Modal -->
<div id="addPairModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeAddPairModal()">&times;</span>
<h2>Add Trading Pair</h2>
<div class="form-group">
<label for="newPairSymbol">Symbol:</label>
<input type="text" id="newPairSymbol" placeholder="e.g., BTCUSDT" style="text-transform: uppercase;">
</div>
<div class="form-group">
<label for="newPairPriority">Priority:</label>
<select id="newPairPriority">
<option value="1">High (1)</option>
<option value="2">Medium (2)</option>
<option value="3">Low (3)</option>
</select>
</div>
<div class="form-group">
<label for="newPairRecordFrom">Record From Date:</label>
<input type="datetime-local" id="newPairRecordFrom">
<small style="color: #a0a0a0; display: block; margin-top: 5px;">Leave empty to use default (2020-01-01)</small>
</div>
<button class="btn btn-primary" onclick="addTradingPair()">Add Pair</button>
</div>
</div>
<!-- Edit Indicator Modal -->
<div id="editIndicatorModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeEditIndicatorModal()">&times;</span>
<h2>Edit Indicator: <span id="editIndicatorName"></span></h2>
<div class="form-group">
<label for="editIndicatorPeriods">Periods (JSON format):</label>
<textarea id="editIndicatorPeriods" rows="5"></textarea>
<small style="color: #a0a0a0; display: block; margin-top: 5px;">
Examples: [20, 50, 200] for arrays or {"fast": 12, "slow": 26} for objects
</small>
</div>
<button class="btn btn-primary" onclick="saveIndicatorPeriods()">Save Changes</button>
</div>
</div>
<script>
let currentConfig = {};
let currentIndicator = '';
// Load configuration on page load
document.addEventListener('DOMContentLoaded', function() {
loadConfig();
loadEnvVars();
});
// Show alert message
function showAlert(message, type = 'info') {
const container = document.getElementById('alertContainer');
const alert = document.createElement('div');
alert.className = `alert alert-${type}`;
alert.textContent = message;
alert.style.display = 'block';
container.appendChild(alert);
setTimeout(() => {
alert.remove();
}, 5000);
}
// Load configuration
async function loadConfig() {
try {
const response = await fetch('/api/config');
currentConfig = await response.json();
displayTradingPairs(currentConfig.trading_pairs || []);
displayIndicators(currentConfig.technical_indicators || {});
displayGapFillingConfig(currentConfig.gap_filling || {});
displayCollectionSettings(currentConfig.collection || {});
} catch (error) {
console.error('Error loading config:', error);
showAlert('Error loading configuration: ' + error.message, 'error');
}
}
// Display trading pairs
function displayTradingPairs(pairs) {
const tbody = document.getElementById('pairsTableBody');
if (!pairs || pairs.length === 0) {
tbody.innerHTML = '<tr><td colspan="5" style="text-align: center;">No trading pairs configured</td></tr>';
return;
}
tbody.innerHTML = pairs.map(pair => `
<tr>
<td><strong>${pair.symbol}</strong></td>
<td>
<span class="status-badge ${pair.enabled ? 'status-enabled' : 'status-disabled'}">
${pair.enabled ? '✅ Enabled' : '❌ Disabled'}
</span>
</td>
<td>${pair.priority}</td>
<td>${pair.record_from_date || 'Not set'}</td>
<td>
<button class="btn btn-sm ${pair.enabled ? 'btn-danger' : 'btn-success'}"
onclick="togglePair('${pair.symbol}', ${!pair.enabled})">
${pair.enabled ? 'Disable' : 'Enable'}
</button>
<button class="btn btn-sm btn-danger" onclick="removePair('${pair.symbol}')">
Delete
</button>
</td>
</tr>
`).join('');
}
// Display technical indicators
function displayIndicators(indicators) {
const container = document.getElementById('indicatorsSection');
if (!indicators || !indicators.enabled || !indicators.periods) {
container.innerHTML = '<div style="text-align: center; color: #a0a0a0;">No indicators configured</div>';
return;
}
const enabledList = indicators.enabled || [];
const periods = indicators.periods || {};
// Get all available indicators from periods
const allIndicators = Object.keys(periods);
container.innerHTML = allIndicators.map(indicator => {
const isEnabled = enabledList.includes(indicator);
const periodValue = periods[indicator];
// Format period display
let periodDisplay = '';
if (Array.isArray(periodValue)) {
periodDisplay = `Periods: ${periodValue.join(', ')}`;
} else if (typeof periodValue === 'object') {
periodDisplay = `Config: ${JSON.stringify(periodValue)}`;
} else {
periodDisplay = `Period: ${periodValue}`;
}
return `
<div class="indicator-card ${isEnabled ? 'enabled' : 'disabled'}">
<div class="indicator-header">
<div>
<div class="indicator-name">${indicator.toUpperCase()}</div>
<div class="indicator-periods">${periodDisplay}</div>
</div>
<div>
<button class="btn btn-sm ${isEnabled ? 'btn-danger' : 'btn-success'}"
onclick="toggleIndicator('${indicator}')">
${isEnabled ? 'Disable' : 'Enable'}
</button>
<button class="btn btn-sm btn-primary" onclick="editIndicator('${indicator}')">
Edit
</button>
</div>
</div>
</div>
`;
}).join('');
// Show calculation intervals
if (indicators.calculation_intervals) {
container.innerHTML += `
<div style="margin-top: 20px; padding: 15px; background: rgba(79, 172, 254, 0.1); border-radius: 8px; border: 1px solid rgba(79, 172, 254, 0.3);">
<strong style="color: #4facfe;">Calculation Intervals:</strong>
<div style="margin-top: 10px; color: #e0e0e0;">
${indicators.calculation_intervals.join(', ')}
</div>
</div>
`;
}
}
// Display gap filling configuration
function displayGapFillingConfig(gapConfig) {
const container = document.getElementById('gapFillingConfig');
container.innerHTML = `
<div class="config-grid">
<div class="config-item">
<div class="config-label">Auto Gap Filling</div>
<div class="config-value">${gapConfig.enable_auto_gap_filling ? '✅ Enabled' : '❌ Disabled'}</div>
</div>
<div class="config-item">
<div class="config-label">Schedule (hours)</div>
<div class="config-value">${gapConfig.auto_fill_schedule_hours || 24} hours</div>
</div>
<div class="config-item">
<div class="config-label">Max Gap Size</div>
<div class="config-value">${gapConfig.max_gap_size_candles || 1000} candles</div>
</div>
<div class="config-item">
<div class="config-label">Min Gap Size</div>
<div class="config-value">${gapConfig.min_gap_size_candles || 2} candles</div>
</div>
<div class="config-item">
<div class="config-label">Intelligent Averaging</div>
<div class="config-value">${gapConfig.enable_intelligent_averaging ? '✅ Enabled' : '❌ Disabled'}</div>
</div>
<div class="config-item">
<div class="config-label">Lookback Candles</div>
<div class="config-value">${gapConfig.averaging_lookback_candles || 10} candles</div>
</div>
<div class="config-item">
<div class="config-label">Max Consecutive Empty</div>
<div class="config-value">${gapConfig.max_consecutive_empty_candles || 5} candles</div>
</div>
<div class="config-item">
<div class="config-label">Monitored Intervals</div>
<div class="config-value">${gapConfig.intervals_to_monitor ? gapConfig.intervals_to_monitor.join(', ') : 'Not set'}</div>
</div>
</div>
`;
}
// Display collection settings
function displayCollectionSettings(collectionConfig) {
const container = document.getElementById('collectionSettings');
container.innerHTML = `
<div class="config-grid">
<div class="config-item">
<div class="config-label">Bulk Chunk Size</div>
<div class="config-value">${collectionConfig.bulk_chunk_size || 1000} records</div>
</div>
<div class="config-item">
<div class="config-label">Tick Batch Size</div>
<div class="config-value">${collectionConfig.tick_batch_size || 100} ticks</div>
</div>
<div class="config-item">
<div class="config-label">WebSocket Reconnect Delay</div>
<div class="config-value">${collectionConfig.websocket_reconnect_delay || 5} seconds</div>
</div>
<div class="config-item">
<div class="config-label">Max Retries</div>
<div class="config-value">${collectionConfig.max_retries || 3} attempts</div>
</div>
<div class="config-item">
<div class="config-label">Rate Limit</div>
<div class="config-value">${collectionConfig.rate_limit_requests_per_minute || 2000} req/min</div>
</div>
<div class="config-item">
<div class="config-label">Default Record From Date</div>
<div class="config-value">${collectionConfig.default_record_from_date || 'Not set'}</div>
</div>
<div class="config-item">
<div class="config-label">Candle Intervals</div>
<div class="config-value">${collectionConfig.candle_intervals ? collectionConfig.candle_intervals.join(', ') : 'Not set'}</div>
</div>
</div>
`;
}
// Toggle trading pair
async function togglePair(symbol, enabled) {
try {
const response = await fetch(`/api/trading-pairs/${symbol}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled })
});
const data = await response.json();
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
if (data.status === 'success') {
loadConfig();
}
} catch (error) {
showAlert('Error toggling pair: ' + error.message, 'error');
}
}
// Remove trading pair
async function removePair(symbol) {
if (!confirm(`Are you sure you want to remove ${symbol}?`)) {
return;
}
try {
const response = await fetch(`/api/trading-pairs/${symbol}`, {
method: 'DELETE'
});
const data = await response.json();
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
if (data.status === 'success') {
loadConfig();
}
} catch (error) {
showAlert('Error removing pair: ' + error.message, 'error');
}
}
// Add trading pair modal
function showAddPairModal() {
document.getElementById('addPairModal').style.display = 'block';
}
function closeAddPairModal() {
document.getElementById('addPairModal').style.display = 'none';
}
async function addTradingPair() {
const symbol = document.getElementById('newPairSymbol').value.toUpperCase();
const priority = parseInt(document.getElementById('newPairPriority').value);
const recordFrom = document.getElementById('newPairRecordFrom').value;
if (!symbol) {
showAlert('Please enter a symbol', 'error');
return;
}
try {
const body = { symbol, priority };
if (recordFrom) {
body.record_from_date = recordFrom + ':00Z';
}
const response = await fetch('/api/trading-pairs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
const data = await response.json();
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
if (data.status === 'success') {
closeAddPairModal();
loadConfig();
}
} catch (error) {
showAlert('Error adding pair: ' + error.message, 'error');
}
}
// Toggle indicator
async function toggleIndicator(indicator) {
try {
const response = await fetch(`/api/indicators/toggle/${indicator}`, {
method: 'POST'
});
const data = await response.json();
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
if (data.status === 'success') {
loadConfig();
}
} catch (error) {
showAlert('Error toggling indicator: ' + error.message, 'error');
}
}
// Edit indicator
function editIndicator(indicator) {
currentIndicator = indicator;
document.getElementById('editIndicatorName').textContent = indicator.toUpperCase();
const periods = currentConfig.technical_indicators.periods[indicator];
document.getElementById('editIndicatorPeriods').value = JSON.stringify(periods, null, 2);
document.getElementById('editIndicatorModal').style.display = 'block';
}
function closeEditIndicatorModal() {
document.getElementById('editIndicatorModal').style.display = 'none';
}
async function saveIndicatorPeriods() {
try {
const periodsText = document.getElementById('editIndicatorPeriods').value;
const periods = JSON.parse(periodsText);
const response = await fetch(`/api/indicators/${currentIndicator}/periods`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ periods })
});
const data = await response.json();
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
if (data.status === 'success') {
closeEditIndicatorModal();
loadConfig();
}
} catch (error) {
showAlert('Error saving indicator: ' + error.message, 'error');
}
}
// Environment variables
async function loadEnvVars() {
try {
const response = await fetch('/api/env');
const envVars = await response.json();
const tbody = document.getElementById('envTableBody');
if (Object.keys(envVars).length === 0) {
tbody.innerHTML = '<tr><td colspan="3" style="text-align: center;">No environment variables</td></tr>';
return;
}
tbody.innerHTML = Object.entries(envVars).map(([key, value]) => `
<tr>
<td><strong>${key}</strong></td>
<td><code>${value}</code></td>
<td>
<button class="btn btn-sm btn-danger" onclick="deleteEnvVar('${key}')">Delete</button>
</td>
</tr>
`).join('');
} catch (error) {
console.error('Error loading env vars:', error);
}
}
async function addEnvVar() {
const key = document.getElementById('newEnvKey').value.trim();
const value = document.getElementById('newEnvValue').value.trim();
if (!key || !value) {
showAlert('Please enter both key and value', 'error');
return;
}
try {
const response = await fetch('/api/env', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key, value })
});
const data = await response.json();
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
if (data.status === 'success') {
document.getElementById('newEnvKey').value = '';
document.getElementById('newEnvValue').value = '';
loadEnvVars();
}
} catch (error) {
showAlert('Error adding env var: ' + error.message, 'error');
}
}
async function deleteEnvVar(key) {
if (!confirm(`Delete environment variable ${key}?`)) {
return;
}
try {
const response = await fetch(`/api/env/${key}`, {
method: 'DELETE'
});
const data = await response.json();
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
if (data.status === 'success') {
loadEnvVars();
}
} catch (error) {
showAlert('Error deleting env var: ' + error.message, 'error');
}
}
// Save all configuration
async function saveAllConfig() {
if (!confirm('Save all configuration changes?')) {
return;
}
try {
const response = await fetch('/api/config', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(currentConfig)
});
const data = await response.json();
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
} catch (error) {
showAlert('Error saving config: ' + error.message, 'error');
}
}
// Close modals on outside click
window.onclick = function(event) {
if (event.target.classList.contains('modal')) {
event.target.style.display = 'none';
}
}
</script>
</body>
</html>
"""