This commit is contained in:
ilyastar9999
2025-12-04 14:41:44 +03:00
parent 42aecacced
commit 40bddd1449
2 changed files with 97 additions and 2 deletions

View File

@@ -138,6 +138,33 @@ def api_service_action(service_id):
finally: finally:
loop.close() loop.close()
@app.route('/api/services/<int:service_id>/update', methods=['PATCH'])
@login_required
def api_service_update(service_id):
"""Update service (e.g., alias)"""
updates = request.json
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
async def patch_call():
headers = {"Authorization": f"Bearer {SECRET_TOKEN}"}
async with aiohttp.ClientSession() as session:
async with session.patch(
f"{CONTROLLER_API}/services/{service_id}",
headers=headers,
json=updates
) as resp:
if resp.status == 200:
return await resp.json()
return {"error": f"Status {resp.status}"}
data = loop.run_until_complete(patch_call())
return jsonify(data)
finally:
loop.close()
@app.route('/api/services/<int:service_id>/logs') @app.route('/api/services/<int:service_id>/logs')
@login_required @login_required
def api_service_logs(service_id): def api_service_logs(service_id):

View File

@@ -18,6 +18,7 @@
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Alias</th>
<th>Path</th> <th>Path</th>
<th>Status</th> <th>Status</th>
<th>Last Updated</th> <th>Last Updated</th>
@@ -26,7 +27,7 @@
</thead> </thead>
<tbody id="servicesTable"> <tbody id="servicesTable">
<tr> <tr>
<td colspan="5" class="text-center">Loading...</td> <td colspan="6" class="text-center">Loading...</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -51,6 +52,38 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Edit Alias Modal -->
<div class="modal fade" id="editAliasModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Service Alias</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="editAliasForm">
<input type="hidden" id="editServiceId">
<div class="mb-3">
<label class="form-label">Service Name</label>
<input type="text" class="form-control" id="editServiceName" readonly>
</div>
<div class="mb-3">
<label class="form-label">Alias (Scoreboard Name)</label>
<input type="text" class="form-control" id="editServiceAlias"
placeholder="e.g. test_gevent_service_1">
<small class="form-text text-muted">Enter the service name as it appears on the
scoreboard</small>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" onclick="saveAlias()">Save</button>
</div>
</div>
</div>
</div>
{% endblock %} {% endblock %}
{% block extra_js %} {% block extra_js %}
@@ -64,14 +97,22 @@
? '<span class="badge bg-success">Running</span>' ? '<span class="badge bg-success">Running</span>'
: '<span class="badge bg-secondary">Stopped</span>'; : '<span class="badge bg-secondary">Stopped</span>';
let aliasDisplay = service.alias
? `<code>${service.alias}</code>`
: '<span class="text-muted">Not set</span>';
html += ` html += `
<tr> <tr>
<td><strong>${service.name}</strong></td> <td><strong>${service.name}</strong></td>
<td>${aliasDisplay}</td>
<td><code>${service.path}</code></td> <td><code>${service.path}</code></td>
<td>${statusBadge}</td> <td>${statusBadge}</td>
<td>${new Date(service.last_updated).toLocaleString()}</td> <td>${new Date(service.last_updated).toLocaleString()}</td>
<td> <td>
<div class="btn-group btn-group-sm"> <div class="btn-group btn-group-sm">
<button class="btn btn-primary" onclick="editAlias(${service.id}, '${service.name}', '${service.alias || ''}')">
<i class="bi bi-pencil"></i>
</button>
<button class="btn btn-success" onclick="serviceAction(${service.id}, 'start')"> <button class="btn btn-success" onclick="serviceAction(${service.id}, 'start')">
<i class="bi bi-play-fill"></i> <i class="bi bi-play-fill"></i>
</button> </button>
@@ -91,7 +132,7 @@
}); });
$('#servicesTable').html(html); $('#servicesTable').html(html);
} else { } else {
$('#servicesTable').html('<tr><td colspan="5" class="text-center text-muted">No services registered</td></tr>'); $('#servicesTable').html('<tr><td colspan="6" class="text-center text-muted">No services registered</td></tr>');
} }
}); });
} }
@@ -121,6 +162,33 @@
}); });
} }
function editAlias(serviceId, serviceName, currentAlias) {
$('#editServiceId').val(serviceId);
$('#editServiceName').val(serviceName);
$('#editServiceAlias').val(currentAlias);
new bootstrap.Modal(document.getElementById('editAliasModal')).show();
}
function saveAlias() {
const serviceId = $('#editServiceId').val();
const alias = $('#editServiceAlias').val().trim();
$.ajax({
url: `/api/services/${serviceId}/update`,
method: 'PATCH',
contentType: 'application/json',
data: JSON.stringify({ alias: alias }),
success: function (data) {
alert('Alias updated successfully!');
bootstrap.Modal.getInstance(document.getElementById('editAliasModal')).hide();
loadServices();
},
error: function (xhr) {
alert(`Failed to update alias: ${xhr.responseJSON?.detail || 'Unknown error'}`);
}
});
}
$(document).ready(function () { $(document).ready(function () {
loadServices(); loadServices();
$('#refreshServices').click(loadServices); $('#refreshServices').click(loadServices);