mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 23:50:48 +02:00
- Added functionality to allow users to select and reorder job configurations in both new and edit job forms. - Introduced JavaScript logic to handle the display and ordering of selected configurations, including move up/down buttons. - Updated backend to process and store the order of configurations when creating or updating jobs. - Enhanced logging for job creation and update processes to include configuration order details.
804 lines
35 KiB
Templ
804 lines
35 KiB
Templ
package components
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/starfleetcptn/gomft/internal/db"
|
|
"context"
|
|
)
|
|
|
|
type JobFormData struct {
|
|
Job *db.Job
|
|
Configs []db.TransferConfig
|
|
IsNew bool
|
|
}
|
|
|
|
func getJobFormTitle(isNew bool) string {
|
|
if isNew {
|
|
return "New Job"
|
|
}
|
|
return "Edit Job"
|
|
}
|
|
|
|
func getJobTitle(isNew bool) string {
|
|
if isNew {
|
|
return "Create New Job"
|
|
}
|
|
return "Edit Job"
|
|
}
|
|
|
|
// configSelected checks if a config ID is selected for a job
|
|
func configSelected(job *db.Job, configID uint) bool {
|
|
if job.ConfigIDs != "" {
|
|
// If ConfigIDs is populated, only check against those IDs
|
|
for _, id := range job.GetConfigIDsList() {
|
|
if id == configID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
} else {
|
|
// If ConfigIDs is empty, fall back to checking the primary ConfigID
|
|
return job.ConfigID == configID
|
|
}
|
|
}
|
|
|
|
templ configSearchScript() {
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// Handle search for new job form
|
|
const configSearch = document.getElementById('config-search');
|
|
if (configSearch) {
|
|
configSearch.addEventListener('input', (e) => {
|
|
const searchTerm = e.target.value.toLowerCase();
|
|
const configItems = document.querySelectorAll('#config-list .config-item');
|
|
|
|
configItems.forEach(item => {
|
|
const name = item.getAttribute('data-name').toLowerCase();
|
|
item.style.display = name.includes(searchTerm) ? 'flex' : 'none';
|
|
});
|
|
});
|
|
}
|
|
|
|
// Handle search for edit job form
|
|
const configSearchEdit = document.getElementById('config-search-edit');
|
|
if (configSearchEdit) {
|
|
configSearchEdit.addEventListener('input', (e) => {
|
|
const searchTerm = e.target.value.toLowerCase();
|
|
const configItems = document.querySelectorAll('#config-list-edit .config-item');
|
|
|
|
configItems.forEach(item => {
|
|
const name = item.getAttribute('data-name').toLowerCase();
|
|
item.style.display = name.includes(searchTerm) ? 'flex' : 'none';
|
|
});
|
|
});
|
|
}
|
|
|
|
// Handle job ordering
|
|
const setupJobOrdering = (configListId, selectedListId, formId, savedOrder) => {
|
|
const configList = document.getElementById(configListId);
|
|
const selectedList = document.getElementById(selectedListId);
|
|
const form = document.getElementById(formId);
|
|
|
|
if (!configList || !selectedList || !form) return;
|
|
|
|
// Get saved order if available
|
|
const orderedIds = savedOrder ? savedOrder.split(',').map(id => id.trim()) : [];
|
|
console.log('Initial saved order:', orderedIds);
|
|
|
|
// Initialize selected items from checked checkboxes
|
|
const updateSelectedItems = (initialLoad = false) => {
|
|
// Clear current list
|
|
selectedList.innerHTML = '';
|
|
|
|
// Get all checked checkboxes
|
|
const checkedItems = configList.querySelectorAll('input[type="checkbox"]:checked');
|
|
|
|
if (checkedItems.length === 0) {
|
|
selectedList.innerHTML = '<div class="text-center py-4 text-secondary-500 dark:text-secondary-400">No configurations selected</div>';
|
|
return;
|
|
}
|
|
|
|
// Create a map of config items for easy access
|
|
const configItems = {};
|
|
checkedItems.forEach(checkbox => {
|
|
configItems[checkbox.value] = {
|
|
checkbox: checkbox,
|
|
configId: checkbox.value,
|
|
configName: checkbox.nextElementSibling.textContent.trim()
|
|
};
|
|
});
|
|
|
|
// If we have a saved order and this is the initial load, use that order
|
|
let itemsToShow = [];
|
|
if (initialLoad && orderedIds.length > 0) {
|
|
// First add items in the saved order
|
|
orderedIds.forEach(id => {
|
|
if (configItems[id]) {
|
|
itemsToShow.push(configItems[id]);
|
|
delete configItems[id]; // Remove from map to avoid duplicates
|
|
}
|
|
});
|
|
|
|
// Then add any remaining checked items not in the saved order
|
|
Object.values(configItems).forEach(item => {
|
|
itemsToShow.push(item);
|
|
});
|
|
} else {
|
|
// Just add all checked items in their current order
|
|
itemsToShow = Object.values(configItems);
|
|
}
|
|
|
|
// Add each item to the selected list
|
|
itemsToShow.forEach((item, index) => {
|
|
const configId = item.configId;
|
|
const configName = item.configName;
|
|
|
|
const listItem = document.createElement('div');
|
|
listItem.className = 'flex items-center justify-between p-2 mb-2 bg-white dark:bg-secondary-800 border border-secondary-200 dark:border-secondary-700 rounded-lg';
|
|
listItem.setAttribute('data-id', configId);
|
|
|
|
listItem.innerHTML = `
|
|
<div class="flex items-center">
|
|
<span class="inline-flex items-center justify-center h-6 w-6 rounded-full bg-primary-100 dark:bg-primary-900 mr-2 text-primary-700 dark:text-primary-300 text-sm">${index + 1}</span>
|
|
<span class="font-medium text-secondary-700 dark:text-secondary-300">${configName}</span>
|
|
</div>
|
|
<div class="flex space-x-1">
|
|
<button type="button" class="move-up p-1 rounded hover:bg-secondary-100 dark:hover:bg-secondary-700" title="Move up">
|
|
<i class="fas fa-arrow-up text-secondary-500"></i>
|
|
</button>
|
|
<button type="button" class="move-down p-1 rounded hover:bg-secondary-100 dark:hover:bg-secondary-700" title="Move down">
|
|
<i class="fas fa-arrow-down text-secondary-500"></i>
|
|
</button>
|
|
</div>
|
|
`;
|
|
|
|
selectedList.appendChild(listItem);
|
|
});
|
|
|
|
// Update hidden order inputs
|
|
updateOrderInputs();
|
|
};
|
|
|
|
// Update hidden inputs with the current order
|
|
const updateOrderInputs = () => {
|
|
const items = selectedList.querySelectorAll('.flex.items-center.justify-between');
|
|
if (items.length === 0) return;
|
|
|
|
// Remove any existing order input to avoid duplicates
|
|
const existingOrderInput = form.querySelector('input[name="config_order"]');
|
|
if (existingOrderInput) {
|
|
existingOrderInput.remove();
|
|
}
|
|
|
|
// Create a new input with the current order
|
|
const orderedIds = Array.from(items).map(item => item.getAttribute('data-id'));
|
|
|
|
// Create a hidden input to store the order
|
|
const configOrderInput = document.createElement('input');
|
|
configOrderInput.type = 'hidden';
|
|
configOrderInput.name = 'config_order';
|
|
configOrderInput.value = orderedIds.join(',');
|
|
|
|
// Add the input to the form
|
|
form.appendChild(configOrderInput);
|
|
|
|
// Update the visible order numbers
|
|
items.forEach((item, index) => {
|
|
const orderNum = index + 1;
|
|
const orderSpan = item.querySelector('span.rounded-full');
|
|
if (orderSpan) {
|
|
orderSpan.textContent = orderNum;
|
|
}
|
|
});
|
|
|
|
console.log('Updated order input:', configOrderInput.value);
|
|
};
|
|
|
|
// Initialize the selected list with saved order if available
|
|
updateSelectedItems(true);
|
|
|
|
// Handle checkbox changes
|
|
configList.addEventListener('change', (e) => {
|
|
if (e.target.matches('input[type="checkbox"]')) {
|
|
updateSelectedItems(false);
|
|
}
|
|
});
|
|
|
|
// Handle reordering
|
|
selectedList.addEventListener('click', (e) => {
|
|
const listItem = e.target.closest('.flex.items-center.justify-between');
|
|
if (!listItem) return;
|
|
|
|
if (e.target.closest('.move-up')) {
|
|
const prev = listItem.previousElementSibling;
|
|
if (prev) {
|
|
selectedList.insertBefore(listItem, prev);
|
|
updateOrderInputs();
|
|
}
|
|
} else if (e.target.closest('.move-down')) {
|
|
const next = listItem.nextElementSibling;
|
|
if (next) {
|
|
selectedList.insertBefore(next, listItem);
|
|
updateOrderInputs();
|
|
}
|
|
}
|
|
});
|
|
|
|
// Ensure the order input is updated before submission
|
|
form.addEventListener('submit', function(e) {
|
|
updateOrderInputs();
|
|
console.log('Form submitted with order:', form.querySelector('input[name="config_order"]')?.value);
|
|
});
|
|
};
|
|
|
|
// Setup ordering for new job form
|
|
setupJobOrdering('config-list', 'selected-configs', 'new-job-form', null);
|
|
|
|
// Setup ordering for edit job form
|
|
const editJobForm = document.getElementById('edit-job-form');
|
|
const savedOrderEdit = editJobForm ? editJobForm.getAttribute('data-config-order') : null;
|
|
setupJobOrdering('config-list-edit', 'selected-configs-edit', 'edit-job-form', savedOrderEdit);
|
|
});
|
|
</script>
|
|
}
|
|
|
|
templ JobForm(ctx context.Context, data JobFormData) {
|
|
@LayoutWithContext(getJobFormTitle(data.IsNew), ctx) {
|
|
@configSearchScript()
|
|
<div class="min-h-[calc(100vh-4rem)] flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8 bg-secondary-50 dark:bg-secondary-900">
|
|
<div class="max-w-3xl w-full">
|
|
<div class="card overflow-hidden shadow-lg">
|
|
<div class="p-8">
|
|
<div class="text-center mb-8">
|
|
<div class="inline-flex items-center justify-center w-20 h-20 rounded-full bg-primary-100 dark:bg-primary-900 mb-4">
|
|
<i class="fas fa-calendar-alt text-primary-600 dark:text-primary-400 text-3xl"></i>
|
|
</div>
|
|
<h2 class="text-3xl font-bold text-secondary-900 dark:text-secondary-100">
|
|
{ getJobTitle(data.IsNew) }
|
|
</h2>
|
|
<p class="mt-2 text-secondary-600 dark:text-secondary-400">Configure your scheduled transfer job</p>
|
|
</div>
|
|
|
|
if data.IsNew {
|
|
<form
|
|
id="new-job-form"
|
|
class="space-y-6"
|
|
hx-post="/jobs"
|
|
hx-target="body"
|
|
hx-boost="true">
|
|
<div class="space-y-6">
|
|
<div>
|
|
<label for="name" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">Job Name</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-tag text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="text"
|
|
name="name"
|
|
id="name"
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder="Daily Production Backup"/>
|
|
</div>
|
|
<p class="mt-2 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Descriptive name for this job (optional). If not provided, the config name will be used.
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">Transfer Configurations</label>
|
|
<div class="mt-2 border border-secondary-300 dark:border-secondary-700 rounded-md overflow-hidden">
|
|
<!-- Search box -->
|
|
<div class="px-3 py-2 border-b border-secondary-200 dark:border-secondary-700 bg-secondary-50 dark:bg-secondary-800">
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-search text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="text"
|
|
id="config-search"
|
|
placeholder="Search configurations..."
|
|
class="block w-full pl-10 pr-3 py-2 border border-secondary-300 dark:border-secondary-600 rounded-md leading-5 bg-white dark:bg-secondary-800 text-secondary-900 dark:text-secondary-100 placeholder-secondary-500 dark:placeholder-secondary-400 focus:outline-none focus:ring-primary-500 focus:border-primary-500 sm:text-sm" />
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Configuration checkboxes -->
|
|
<div class="max-h-48 overflow-y-auto py-2 px-3 bg-white dark:bg-secondary-900 divide-y divide-secondary-200 dark:divide-secondary-700" id="config-list">
|
|
if len(data.Configs) > 0 {
|
|
for _, config := range data.Configs {
|
|
<div class="config-item py-2 flex items-center" data-name={ config.Name }>
|
|
<input
|
|
type="checkbox"
|
|
name="config_ids[]"
|
|
id={ fmt.Sprintf("config_%d", config.ID) }
|
|
value={ fmt.Sprint(config.ID) }
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded"
|
|
/>
|
|
<label for={ fmt.Sprintf("config_%d", config.ID) } class="ml-3 block font-medium text-secondary-700 dark:text-secondary-300 w-full cursor-pointer">
|
|
{ config.Name }
|
|
</label>
|
|
</div>
|
|
}
|
|
} else {
|
|
<div class="text-center py-4 text-secondary-500 dark:text-secondary-400">
|
|
No configurations available. <a href="/configs/new" class="text-primary-600 hover:text-primary-500">Create one</a>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Selected Configurations Order List -->
|
|
<div class="mt-4">
|
|
<label class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-2">
|
|
<i class="fas fa-sort-amount-down mr-1"></i> Execution Order
|
|
</label>
|
|
<div id="selected-configs" class="border border-secondary-300 dark:border-secondary-700 rounded-md p-3 min-h-20 bg-secondary-50 dark:bg-secondary-900">
|
|
<!-- Selected items will be populated by JavaScript -->
|
|
</div>
|
|
<p class="mt-2 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Use the arrows to change the order in which configurations will execute.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="schedule" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">Schedule (Cron Expression)</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-clock text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="text"
|
|
name="schedule"
|
|
id="schedule"
|
|
required
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder="*/15 * * * *"/>
|
|
</div>
|
|
<p class="mt-2 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Use standard cron expression format. Example: */15 * * * * (every 15 minutes)
|
|
</p>
|
|
</div>
|
|
|
|
<div class="bg-secondary-50 dark:bg-secondary-800 p-4 rounded-lg border border-secondary-200 dark:border-secondary-700">
|
|
<div class="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id="enabled"
|
|
name="enabled"
|
|
value="true"
|
|
if data.Job.GetEnabled() {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded" />
|
|
<label for="enabled" class="ml-2 block text-sm font-medium text-secondary-700 dark:text-secondary-300">Enable this job</label>
|
|
</div>
|
|
<p class="mt-1 text-sm text-secondary-500 dark:text-secondary-400">
|
|
Jobs that are not enabled will not run automatically on schedule.
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Webhook Notification Settings -->
|
|
<div class="border-t border-secondary-200 dark:border-secondary-700 pt-6 mt-6">
|
|
<h3 class="text-lg font-medium text-secondary-900 dark:text-secondary-100 mb-4">
|
|
<i class="fas fa-bell mr-2 text-primary-500"></i>
|
|
Webhook Notifications
|
|
</h3>
|
|
|
|
<div class="space-y-4">
|
|
<div class="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id="webhook_enabled"
|
|
name="webhook_enabled"
|
|
value="true"
|
|
if data.Job.GetWebhookEnabled() {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded" />
|
|
<label for="webhook_enabled" class="ml-2 block text-sm font-medium text-secondary-700 dark:text-secondary-300">
|
|
Send webhook notification on completion
|
|
</label>
|
|
</div>
|
|
|
|
<div class="pl-6 space-y-4">
|
|
<div>
|
|
<label for="webhook_url" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">Webhook URL</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-link text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="url"
|
|
name="webhook_url"
|
|
id="webhook_url"
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder="https://example.com/webhook"/>
|
|
</div>
|
|
<p class="mt-1 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
The URL where notifications will be sent when jobs run
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="webhook_secret" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">
|
|
Webhook Secret <span class="text-secondary-500 dark:text-secondary-400">(optional)</span>
|
|
</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-key text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="password"
|
|
name="webhook_secret"
|
|
id="webhook_secret"
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder="Secret token for signing requests"/>
|
|
</div>
|
|
<p class="mt-1 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Used to sign webhook payloads (X-Hub-Signature-256 header)
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="webhook_headers" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">
|
|
Custom Headers <span class="text-secondary-500 dark:text-secondary-400">(optional)</span>
|
|
</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-code text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="text"
|
|
name="webhook_headers"
|
|
id="webhook_headers"
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder='{"X-Custom-Header": "value"}'/>
|
|
</div>
|
|
<p class="mt-1 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Additional HTTP headers as JSON
|
|
</p>
|
|
</div>
|
|
|
|
<div class="space-y-2">
|
|
<div class="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id="notify_on_success"
|
|
name="notify_on_success"
|
|
value="true"
|
|
if data.Job.GetNotifyOnSuccess() {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded"/>
|
|
<label for="notify_on_success" class="ml-2 block text-sm font-medium text-secondary-700 dark:text-secondary-300">
|
|
Notify on successful jobs
|
|
</label>
|
|
</div>
|
|
|
|
<div class="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id="notify_on_failure"
|
|
name="notify_on_failure"
|
|
value="true"
|
|
if data.Job.GetNotifyOnFailure() {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded"/>
|
|
<label for="notify_on_failure" class="ml-2 block text-sm font-medium text-secondary-700 dark:text-secondary-300">
|
|
Notify on failed jobs
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="pt-5 flex justify-end space-x-3">
|
|
<a href="/jobs" class="btn-secondary flex items-center justify-center px-4 py-2">
|
|
<i class="fas fa-times mr-2"></i>
|
|
Cancel
|
|
</a>
|
|
<button
|
|
type="submit"
|
|
class="btn-primary flex items-center justify-center px-4 py-2">
|
|
<i class="fas fa-plus mr-2"></i>
|
|
Create Job
|
|
</button>
|
|
</div>
|
|
</form>
|
|
} else {
|
|
<form
|
|
id="edit-job-form"
|
|
class="space-y-6"
|
|
hx-post={ fmt.Sprintf("/jobs/%d", data.Job.ID) }
|
|
hx-target="body"
|
|
hx-boost="true"
|
|
data-config-order={ data.Job.ConfigIDs }>
|
|
<div class="space-y-6">
|
|
<div>
|
|
<label for="name" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">Job Name</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-tag text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="text"
|
|
name="name"
|
|
id="name"
|
|
value={ data.Job.Name }
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder="Daily Production Backup"/>
|
|
</div>
|
|
<p class="mt-2 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Descriptive name for this job (optional). If not provided, the config name will be used.
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">Transfer Configurations</label>
|
|
<div class="mt-2 border border-secondary-300 dark:border-secondary-700 rounded-md overflow-hidden">
|
|
<!-- Search box -->
|
|
<div class="px-3 py-2 border-b border-secondary-200 dark:border-secondary-700 bg-secondary-50 dark:bg-secondary-800">
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-search text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="text"
|
|
id="config-search-edit"
|
|
placeholder="Search configurations..."
|
|
class="block w-full pl-10 pr-3 py-2 border border-secondary-300 dark:border-secondary-600 rounded-md leading-5 bg-white dark:bg-secondary-800 text-secondary-900 dark:text-secondary-100 placeholder-secondary-500 dark:placeholder-secondary-400 focus:outline-none focus:ring-primary-500 focus:border-primary-500 sm:text-sm" />
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Configuration checkboxes -->
|
|
<div class="max-h-48 overflow-y-auto py-2 px-3 bg-white dark:bg-secondary-900 divide-y divide-secondary-200 dark:divide-secondary-700" id="config-list-edit">
|
|
if len(data.Configs) > 0 {
|
|
for _, config := range data.Configs {
|
|
<div class="config-item py-2 flex items-center" data-name={ config.Name }>
|
|
<input
|
|
type="checkbox"
|
|
name="config_ids[]"
|
|
id={ fmt.Sprintf("config_edit_%d", config.ID) }
|
|
value={ fmt.Sprint(config.ID) }
|
|
if configSelected(data.Job, config.ID) {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded"
|
|
/>
|
|
<label for={ fmt.Sprintf("config_edit_%d", config.ID) } class="ml-3 block font-medium text-secondary-700 dark:text-secondary-300 w-full cursor-pointer">
|
|
{ config.Name }
|
|
</label>
|
|
</div>
|
|
}
|
|
} else {
|
|
<div class="text-center py-4 text-secondary-500 dark:text-secondary-400">
|
|
No configurations available. <a href="/configs/new" class="text-primary-600 hover:text-primary-500">Create one</a>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Selected Configurations Order List for edit -->
|
|
<div class="mt-4">
|
|
<label class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-2">
|
|
<i class="fas fa-sort-amount-down mr-1"></i> Execution Order
|
|
</label>
|
|
<div id="selected-configs-edit" class="border border-secondary-300 dark:border-secondary-700 rounded-md p-3 min-h-20 bg-secondary-50 dark:bg-secondary-900">
|
|
<!-- Selected items will be populated by JavaScript -->
|
|
</div>
|
|
<p class="mt-2 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Use the arrows to change the order in which configurations will execute.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="schedule" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">Schedule (Cron Expression)</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-clock text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="text"
|
|
name="schedule"
|
|
id="schedule"
|
|
value={ data.Job.Schedule }
|
|
required
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder="*/15 * * * *"/>
|
|
</div>
|
|
<p class="mt-2 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Use standard cron expression format. Example: */15 * * * * (every 15 minutes)
|
|
</p>
|
|
</div>
|
|
|
|
<div class="bg-secondary-50 dark:bg-secondary-800 p-4 rounded-lg border border-secondary-200 dark:border-secondary-700">
|
|
<div class="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id="enabled"
|
|
name="enabled"
|
|
value="true"
|
|
if data.Job.GetEnabled() {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded" />
|
|
<label for="enabled" class="ml-2 block text-sm font-medium text-secondary-700 dark:text-secondary-300">Enable this job</label>
|
|
</div>
|
|
<p class="mt-1 text-sm text-secondary-500 dark:text-secondary-400">
|
|
Jobs that are not enabled will not run automatically on schedule.
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Webhook Notification Settings -->
|
|
<div class="border-t border-secondary-200 dark:border-secondary-700 pt-6 mt-6">
|
|
<h3 class="text-lg font-medium text-secondary-900 dark:text-secondary-100 mb-4">
|
|
<i class="fas fa-bell mr-2 text-primary-500"></i>
|
|
Webhook Notifications
|
|
</h3>
|
|
|
|
<div class="space-y-4">
|
|
<div class="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id="webhook_enabled"
|
|
name="webhook_enabled"
|
|
value="true"
|
|
if data.Job.GetWebhookEnabled() {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded" />
|
|
<label for="webhook_enabled" class="ml-2 block text-sm font-medium text-secondary-700 dark:text-secondary-300">
|
|
Send webhook notification on completion
|
|
</label>
|
|
</div>
|
|
|
|
<div class="pl-6 space-y-4">
|
|
<div>
|
|
<label for="webhook_url" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">Webhook URL</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-link text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="url"
|
|
name="webhook_url"
|
|
id="webhook_url"
|
|
value={ data.Job.WebhookURL }
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder="https://example.com/webhook"/>
|
|
</div>
|
|
<p class="mt-1 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
The URL where notifications will be sent when jobs run
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="webhook_secret" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">
|
|
Webhook Secret <span class="text-secondary-500 dark:text-secondary-400">(optional)</span>
|
|
</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-key text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="password"
|
|
name="webhook_secret"
|
|
id="webhook_secret"
|
|
value={ data.Job.WebhookSecret }
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder="Secret token for signing requests"/>
|
|
</div>
|
|
<p class="mt-1 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Used to sign webhook payloads (X-Hub-Signature-256 header)
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="webhook_headers" class="block text-sm font-medium text-secondary-700 dark:text-secondary-300 mb-1">
|
|
Custom Headers <span class="text-secondary-500 dark:text-secondary-400">(optional)</span>
|
|
</label>
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
<i class="fas fa-code text-secondary-400 dark:text-secondary-600"></i>
|
|
</div>
|
|
<input
|
|
type="text"
|
|
name="webhook_headers"
|
|
id="webhook_headers"
|
|
value={ data.Job.WebhookHeaders }
|
|
class="form-input pl-10 w-full rounded-lg border-secondary-300 dark:border-secondary-700 dark:bg-secondary-800 dark:text-secondary-100 focus:ring-primary-500 focus:border-primary-500"
|
|
placeholder='{"X-Custom-Header": "value"}'/>
|
|
</div>
|
|
<p class="mt-1 text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Additional HTTP headers as JSON
|
|
</p>
|
|
</div>
|
|
|
|
<div class="space-y-2">
|
|
<div class="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id="notify_on_success"
|
|
name="notify_on_success"
|
|
value="true"
|
|
if data.Job.GetNotifyOnSuccess() {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded"/>
|
|
<label for="notify_on_success" class="ml-2 block text-sm font-medium text-secondary-700 dark:text-secondary-300">
|
|
Notify on successful jobs
|
|
</label>
|
|
</div>
|
|
|
|
<div class="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id="notify_on_failure"
|
|
name="notify_on_failure"
|
|
value="true"
|
|
if data.Job.GetNotifyOnFailure() {
|
|
checked
|
|
}
|
|
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-secondary-300 dark:border-secondary-700 rounded"/>
|
|
<label for="notify_on_failure" class="ml-2 block text-sm font-medium text-secondary-700 dark:text-secondary-300">
|
|
Notify on failed jobs
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="pt-5 flex justify-end space-x-3">
|
|
<a href="/jobs" class="btn-secondary flex items-center justify-center px-4 py-2">
|
|
<i class="fas fa-times mr-2"></i>
|
|
Cancel
|
|
</a>
|
|
<button
|
|
type="submit"
|
|
class="btn-primary flex items-center justify-center px-4 py-2">
|
|
<i class="fas fa-save mr-2"></i>
|
|
Save Changes
|
|
</button>
|
|
</div>
|
|
</form>
|
|
}
|
|
</div>
|
|
|
|
<div class="px-8 py-4 bg-secondary-50 dark:bg-secondary-800 border-t border-secondary-200 dark:border-secondary-700 text-center">
|
|
<p class="text-sm text-secondary-600 dark:text-secondary-400">
|
|
<i class="fas fa-info-circle mr-1"></i>
|
|
Jobs will run according to their schedule and execute the selected transfer configurations in the order specified
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Help Notice -->
|
|
<div class="mt-8 text-center">
|
|
<div class="inline-flex items-center text-sm text-secondary-500 dark:text-secondary-400">
|
|
<i class="fas fa-question-circle mr-2 text-primary-500"></i>
|
|
<span>Need help with cron expressions? Try <a href="https://crontab.guru/" target="_blank" class="text-primary-600 hover:text-primary-500 dark:text-primary-400 dark:hover:text-primary-300">crontab.guru</a></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
} |