104 lines
3.7 KiB
JavaScript
104 lines
3.7 KiB
JavaScript
// Register functions for services management
|
|
bricks.RF.register('add_service', async function(params) {
|
|
try {
|
|
const formData = params.form_data || {};
|
|
|
|
const response = await fetch('/hermes-web-cli/services', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(formData)
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
// Navigate back to services list
|
|
const mainContent = bricks.getWidgetById('app.main-content');
|
|
if (mainContent) {
|
|
mainContent.loadURL(bricks.entire_url('services.ui'));
|
|
}
|
|
bricks.showMessage('Service added successfully', 'success');
|
|
} else {
|
|
bricks.showMessage(result.error || 'Failed to add service', 'error');
|
|
}
|
|
} catch (error) {
|
|
bricks.showMessage('Network error: ' + error.message, 'error');
|
|
}
|
|
});
|
|
|
|
bricks.RF.register('update_service', async function(params) {
|
|
try {
|
|
const formData = params.form_data || {};
|
|
const serviceId = params.service_id;
|
|
|
|
const response = await fetch(`/hermes-web-cli/hermes_services/?id=${serviceId}`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(formData)
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
// Navigate back to services list
|
|
const mainContent = bricks.getWidgetById('app.main-content');
|
|
if (mainContent) {
|
|
mainContent.loadURL(bricks.entire_url('services.ui'));
|
|
}
|
|
bricks.showMessage('Service updated successfully', 'success');
|
|
} else {
|
|
bricks.showMessage(result.error || 'Failed to update service', 'error');
|
|
}
|
|
} catch (error) {
|
|
bricks.showMessage('Network error: ' + error.message, 'error');
|
|
}
|
|
});
|
|
|
|
bricks.RF.register('remove_service', async function(params) {
|
|
try {
|
|
const response = await fetch('/hermes-web-cli/services/remove/?id=' + params.service_id);
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
// Refresh the services list
|
|
const listWidget = bricks.getWidgetById('app.services-list');
|
|
if (listWidget) {
|
|
listWidget.reload();
|
|
}
|
|
bricks.showMessage('Service removed successfully', 'success');
|
|
} else {
|
|
bricks.showMessage(result.error || 'Failed to remove service', 'error');
|
|
}
|
|
} catch (error) {
|
|
bricks.showMessage('Network error: ' + error.message, 'error');
|
|
}
|
|
});
|
|
|
|
bricks.RF.register('test_service_connection', async function(params) {
|
|
try {
|
|
const formData = params.form_data || {};
|
|
const serviceId = params.service_id;
|
|
|
|
// Include API key in the test request
|
|
const response = await fetch('/hermes-web-cli/services/test/?id=' + serviceId, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ apikey: formData.apikey || '' })
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (result.status) {
|
|
// Update the status badge
|
|
// This would require more complex DOM manipulation
|
|
bricks.showMessage('Connection test completed', 'info');
|
|
} else {
|
|
bricks.showMessage(result.error || 'Failed to test connection', 'error');
|
|
}
|
|
} catch (error) {
|
|
bricks.showMessage('Network error: ' + error.message, 'error');
|
|
}
|
|
}); |