mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 15:41:20 +02:00
- Implemented pagination for user notifications, allowing users to navigate through their notifications more efficiently. - Updated the notifications page to display the total count of notifications and provide controls for adjusting the number of notifications shown per page. - Added backend support for fetching paginated notifications and counting total notifications for users. - Improved the user interface for notifications, including a new layout and additional help sections to guide users on managing their notifications.
470 lines
30 KiB
Templ
470 lines
30 KiB
Templ
package components
|
|
|
|
import (
|
|
"fmt"
|
|
"context"
|
|
)
|
|
|
|
type NotificationService struct {
|
|
ID uint
|
|
Name string
|
|
Type string // "email", "webhook", etc.
|
|
IsEnabled bool
|
|
Config map[string]string
|
|
Description string
|
|
EventTriggers []string
|
|
PayloadTemplate string
|
|
SecretKey string
|
|
RetryPolicy string
|
|
SuccessCount int
|
|
FailureCount int
|
|
}
|
|
|
|
type SettingsData struct {
|
|
NotificationServices []NotificationService
|
|
ErrorMessage string
|
|
SuccessMessage string
|
|
}
|
|
|
|
templ Settings(ctx context.Context, data SettingsData) {
|
|
@LayoutWithContext("Application Settings", ctx) {
|
|
<div class="p-4 md:p-6 2xl:p-10">
|
|
<div class="mb-6">
|
|
<h1 class="text-2xl font-bold text-gray-900 dark:text-white flex items-center">
|
|
<i class="fas fa-cog w-6 h-6 mr-2 text-blue-500"></i>
|
|
Application Settings
|
|
</h1>
|
|
<p class="mt-1 text-sm text-gray-500 dark:text-gray-400">
|
|
Configure global settings for your GoMFT instance.
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Success Message -->
|
|
if data.SuccessMessage != "" {
|
|
<div class="p-4 mb-6 text-sm text-green-800 rounded-lg bg-green-50 dark:bg-green-900 dark:text-green-400" role="alert">
|
|
<div class="flex items-center">
|
|
<i class="fas fa-check-circle mr-2"></i>
|
|
<span>{ data.SuccessMessage }</span>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
<!-- Error Message -->
|
|
if data.ErrorMessage != "" {
|
|
<div class="p-4 mb-6 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-red-900 dark:text-red-400" role="alert">
|
|
<div class="flex items-center">
|
|
<i class="fas fa-exclamation-circle mr-2"></i>
|
|
<span>{ data.ErrorMessage }</span>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
<!-- Tabs -->
|
|
<div class="mb-4 border-b border-gray-200 dark:border-gray-700">
|
|
<ul class="flex flex-wrap -mb-px text-sm font-medium text-center" id="settingsTabs" role="tablist">
|
|
<li class="mr-2" role="presentation">
|
|
<button class="inline-block p-4 border-b-2 rounded-t-lg border-blue-600 text-blue-600 dark:text-blue-500 dark:border-blue-500" id="notifications-tab" data-tabs-target="#notifications" type="button" role="tab" aria-controls="notifications" aria-selected="true">
|
|
<i class="fas fa-bell mr-2"></i>Notifications
|
|
</button>
|
|
</li>
|
|
<li class="mr-2" role="presentation">
|
|
<button class="inline-block p-4 border-b-2 border-transparent rounded-t-lg hover:border-gray-300 hover:text-gray-600 dark:hover:text-gray-300" id="general-tab" data-tabs-target="#general" type="button" role="tab" aria-controls="general" aria-selected="false">
|
|
<i class="fas fa-sliders-h mr-2"></i>General
|
|
</button>
|
|
</li>
|
|
<li role="presentation">
|
|
<button class="inline-block p-4 border-b-2 border-transparent rounded-t-lg hover:border-gray-300 hover:text-gray-600 dark:hover:text-gray-300" id="security-tab" data-tabs-target="#security" type="button" role="tab" aria-controls="security" aria-selected="false">
|
|
<i class="fas fa-shield-alt mr-2"></i>Security
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<!-- Tab Content -->
|
|
<div id="settingsTabContent">
|
|
<!-- Notifications Tab -->
|
|
<div class="block p-4 rounded-lg bg-white dark:bg-gray-800" id="notifications" role="tabpanel" aria-labelledby="notifications-tab">
|
|
<div class="flex justify-between items-center mb-4">
|
|
<h2 class="text-xl font-semibold text-gray-900 dark:text-white">Notification Services</h2>
|
|
</div>
|
|
|
|
<!-- Add Notification Service Form -->
|
|
<div class="mb-6 p-6 border border-gray-200 rounded-lg shadow-sm dark:border-gray-700">
|
|
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">
|
|
Add Notification Service
|
|
</h3>
|
|
<form id="add-notification-form" hx-post="/admin/settings/notifications" hx-target="body">
|
|
<div class="mb-6">
|
|
<label for="notification_type" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Notification Type</label>
|
|
<select id="notification_type" name="type" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
|
<option value="">Select a type</option>
|
|
<option value="webhook">Webhook</option>
|
|
<option value="email" disabled>Email (Coming Soon)</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-6 hidden common-fields">
|
|
<label for="notification_name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Name</label>
|
|
<input type="text" id="notification_name" name="name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="My Notification Service" required />
|
|
</div>
|
|
<div class="mb-6 hidden common-fields">
|
|
<label for="notification_description" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Description</label>
|
|
<textarea id="notification_description" name="description" rows="3" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Description for this notification service"></textarea>
|
|
</div>
|
|
|
|
<!-- Dynamic fields based on notification type -->
|
|
<div id="email_fields" class="hidden notification-fields">
|
|
<div class="mb-6">
|
|
<label for="smtp_host" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">SMTP Host</label>
|
|
<input type="text" id="smtp_host" name="smtp_host" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="smtp.example.com" />
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="smtp_port" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">SMTP Port</label>
|
|
<input type="number" id="smtp_port" name="smtp_port" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="587" />
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="smtp_username" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">SMTP Username</label>
|
|
<input type="text" id="smtp_username" name="smtp_username" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="user@example.com" />
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="smtp_password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">SMTP Password</label>
|
|
<input type="password" id="smtp_password" name="smtp_password" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" />
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="from_email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">From Email</label>
|
|
<input type="email" id="from_email" name="from_email" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="notifications@example.com" />
|
|
</div>
|
|
</div>
|
|
|
|
<div id="webhook_fields" class="hidden notification-fields">
|
|
<div class="mb-6">
|
|
<label for="webhook_url" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Webhook URL</label>
|
|
<input type="url" id="webhook_url" name="webhook_url" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="https://api.example.com/webhook" />
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="method" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">HTTP Method</label>
|
|
<select id="method" name="method" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
|
<option value="POST">POST</option>
|
|
<option value="PUT">PUT</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="headers" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Headers (JSON)</label>
|
|
<textarea id="headers" name="headers" rows="3" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder='{"Content-Type": "application/json", "Authorization": "Bearer token"}'></textarea>
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="payload_template" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Payload Template (JSON)</label>
|
|
<textarea id="payload_template" name="payload_template" rows="5" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder='{
|
|
"event": "{{job.event}}",
|
|
"job": {
|
|
"id": "{{job.id}}",
|
|
"name": "{{job.name}}",
|
|
"status": "{{job.status}}",
|
|
"message": "{{job.message}}",
|
|
"started_at": "{{job.started_at}}",
|
|
"completed_at": "{{job.completed_at}}",
|
|
"duration_seconds": {{job.duration_seconds}},
|
|
"config_id": "{{job.config_id}}",
|
|
"config_name": "{{job.config_name}}",
|
|
"transfer_bytes": {{job.transfer_bytes}},
|
|
"file_count": {{job.file_count}}
|
|
},
|
|
"instance": {
|
|
"id": "{{instance.id}}",
|
|
"name": "{{instance.name}}",
|
|
"version": "{{instance.version}}",
|
|
"environment": "{{instance.environment}}"
|
|
},
|
|
"timestamp": "{{timestamp}}",
|
|
"notification_id": "{{notification.id}}"
|
|
}'></textarea>
|
|
<p class="mt-1 text-sm text-gray-500 dark:text-gray-400">Use {`variable`} placeholders for dynamic values. Available variables: job.*, instance.*, timestamp, notification.*</p>
|
|
</div>
|
|
<div class="mb-6">
|
|
<label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Event Triggers</label>
|
|
<div class="space-y-2">
|
|
<div class="flex items-center">
|
|
<input id="trigger_job_start" name="trigger_job_start" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800" checked />
|
|
<label for="trigger_job_start" class="ml-2 text-sm font-medium text-gray-900 dark:text-white">Job Start</label>
|
|
</div>
|
|
<div class="flex items-center">
|
|
<input id="trigger_job_complete" name="trigger_job_complete" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800" checked />
|
|
<label for="trigger_job_complete" class="ml-2 text-sm font-medium text-gray-900 dark:text-white">Job Complete</label>
|
|
</div>
|
|
<div class="flex items-center">
|
|
<input id="trigger_job_error" name="trigger_job_error" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800" checked />
|
|
<label for="trigger_job_error" class="ml-2 text-sm font-medium text-gray-900 dark:text-white">Job Error</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="secret_key" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Secret Key (for signature verification)</label>
|
|
<input type="text" id="secret_key" name="secret_key" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Optional signature verification key" />
|
|
<p class="mt-1 text-sm text-gray-500 dark:text-gray-400">If provided, all webhooks will include an X-GoMFT-Signature header</p>
|
|
</div>
|
|
<div class="mb-6">
|
|
<label for="retry_policy" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Retry Policy</label>
|
|
<select id="retry_policy" name="retry_policy" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
|
<option value="none">No retries</option>
|
|
<option value="simple" selected>Simple (3 retries)</option>
|
|
<option value="exponential">Exponential backoff</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Test notification button -->
|
|
<div class="mb-6 p-4 bg-gray-50 border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600">
|
|
<div class="flex items-center justify-between mb-2">
|
|
<h4 class="text-base font-medium text-gray-900 dark:text-white">Test Configuration</h4>
|
|
<button
|
|
type="button"
|
|
id="test-webhook-btn" hx-post="/admin/settings/notifications/test" hx-trigger="click" hx-target="#test-notification-result" hx-swap="outerHTML"
|
|
class="px-3 py-2 text-xs font-medium text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 rounded-lg dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800"
|
|
>
|
|
<i class="fas fa-paper-plane mr-1"></i>
|
|
Send Test Notification
|
|
</button>
|
|
</div>
|
|
<p class="text-sm text-gray-500 dark:text-gray-400">
|
|
Send a test notification to verify your configuration works correctly before saving.
|
|
</p>
|
|
<div id="test-notification-result" class="mt-3 hidden">
|
|
<!-- Result will be shown here -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex items-start mb-6 hidden common-fields">
|
|
<div class="flex items-center h-5">
|
|
<input id="is_enabled" name="is_enabled" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800" checked />
|
|
</div>
|
|
<div class="ml-3 text-sm">
|
|
<label for="is_enabled" class="font-medium text-gray-900 dark:text-white">Enable this notification service</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hidden common-fields">
|
|
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Add Service</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
if len(data.NotificationServices) == 0 {
|
|
<div class="text-center py-8">
|
|
<div class="inline-flex items-center justify-center w-16 h-16 rounded-full bg-blue-100 dark:bg-blue-900 mb-4">
|
|
<i class="fas fa-bell text-2xl text-blue-600 dark:text-blue-400"></i>
|
|
</div>
|
|
<h3 class="mb-2 text-lg font-semibold text-gray-900 dark:text-white">No notification services configured</h3>
|
|
<p class="text-gray-500 dark:text-gray-400 mb-4">Use the form above to add your first notification service.</p>
|
|
</div>
|
|
} else {
|
|
<div class="bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 dark:bg-gray-800 overflow-hidden">
|
|
<ul class="divide-y divide-gray-200 dark:divide-gray-700">
|
|
for _, service := range data.NotificationServices {
|
|
<li>
|
|
<div class="block hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
|
|
<div class="px-4 py-4 sm:px-6">
|
|
<div class="flex items-center justify-between">
|
|
<div class="flex items-center">
|
|
if service.Type == "email" {
|
|
<div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center text-blue-600 dark:bg-blue-900 dark:text-blue-400 mr-3">
|
|
<i class="fas fa-envelope"></i>
|
|
</div>
|
|
} else if service.Type == "webhook" {
|
|
<div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center text-green-600 dark:bg-green-900 dark:text-green-400 mr-3">
|
|
<i class="fas fa-code"></i>
|
|
</div>
|
|
} else {
|
|
<div class="w-10 h-10 rounded-full bg-gray-100 flex items-center justify-center text-gray-600 dark:bg-gray-700 dark:text-gray-400 mr-3">
|
|
<i class="fas fa-bell"></i>
|
|
</div>
|
|
}
|
|
<div>
|
|
<p class="text-sm font-medium text-blue-600 dark:text-blue-400 truncate">
|
|
{ service.Name }
|
|
</p>
|
|
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">
|
|
{ service.Description }
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="ml-2 flex-shrink-0 flex space-x-2">
|
|
<button
|
|
type="button"
|
|
class="text-gray-500 bg-white focus:outline-none hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 rounded-lg text-sm p-2 mr-1 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
|
|
data-modal-target="edit-notification-modal"
|
|
data-modal-toggle="edit-notification-modal"
|
|
data-service-id={ fmt.Sprint(service.ID) }
|
|
>
|
|
<i class="fas fa-edit"></i>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="text-red-500 bg-white focus:outline-none hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 rounded-lg text-sm p-2 dark:bg-gray-800 dark:text-red-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
|
|
hx-delete={ "/admin/settings/notifications/" + fmt.Sprint(service.ID) }
|
|
hx-confirm="Are you sure you want to delete this notification service? This cannot be undone."
|
|
hx-target="body"
|
|
>
|
|
<i class="fas fa-trash-alt"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="mt-3 sm:flex sm:justify-between">
|
|
<div class="sm:flex flex-col md:flex-row gap-2 md:gap-6">
|
|
<div class="flex items-center">
|
|
<span class={ "px-2 py-1 text-xs font-medium rounded-full",
|
|
templ.KV("bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300", service.IsEnabled),
|
|
templ.KV("bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300", !service.IsEnabled) }>
|
|
if service.IsEnabled {
|
|
Active
|
|
} else {
|
|
Disabled
|
|
}
|
|
</span>
|
|
<span class="ml-2 px-2 py-1 text-xs font-medium bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300 rounded-full">
|
|
{ service.Type }
|
|
</span>
|
|
if len(service.EventTriggers) > 0 && service.Type == "webhook" {
|
|
<span class="ml-2 px-2 py-1 text-xs font-medium bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-300 rounded-full">
|
|
{ fmt.Sprintf("%d triggers", len(service.EventTriggers)) }
|
|
</span>
|
|
}
|
|
if service.SuccessCount > 0 || service.FailureCount > 0 {
|
|
<span class="ml-2 px-2 py-1 text-xs font-medium bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300 rounded-full">
|
|
{ fmt.Sprintf("%d/%d", service.SuccessCount, service.SuccessCount + service.FailureCount) }
|
|
</span>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
if service.Type == "webhook" {
|
|
<div class="mt-2 md:mt-0 flex items-center space-x-4">
|
|
<div class="text-xs">
|
|
<span class="text-gray-500 dark:text-gray-400">Events:</span>
|
|
<span class="ml-1 text-gray-900 dark:text-gray-300">
|
|
if len(service.EventTriggers) == 0 {
|
|
None
|
|
} else {
|
|
for i, trigger := range service.EventTriggers {
|
|
if i > 0 {
|
|
<span>, </span>
|
|
}
|
|
{ trigger }
|
|
}
|
|
}
|
|
</span>
|
|
</div>
|
|
<div class="text-xs">
|
|
<span class="text-gray-500 dark:text-gray-400">Retry:</span>
|
|
<span class="ml-1 text-gray-900 dark:text-gray-300">
|
|
if service.RetryPolicy == "" {
|
|
Default
|
|
} else {
|
|
{ service.RetryPolicy }
|
|
}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
} else {
|
|
<div class="mt-2 md:mt-0 flex items-center text-sm text-gray-500 dark:text-gray-400">
|
|
<i class="far fa-clock w-4 h-4 mr-1.5 text-gray-400 dark:text-gray-500"></i>
|
|
<p>Last sent:
|
|
if service.SuccessCount > 0 {
|
|
"Recently"
|
|
} else {
|
|
"Never"
|
|
}
|
|
</p>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
}
|
|
</ul>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<!-- General Tab -->
|
|
<div class="hidden p-4 rounded-lg bg-white dark:bg-gray-800" id="general" role="tabpanel" aria-labelledby="general-tab">
|
|
<h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">General Settings</h2>
|
|
<form class="space-y-6" action="/settings/general" method="POST">
|
|
<div class="grid gap-6 mb-6 md:grid-cols-2">
|
|
<div>
|
|
<label for="app_name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Application Name</label>
|
|
<input type="text" id="app_name" name="app_name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" value="GoMFT" />
|
|
</div>
|
|
<div>
|
|
<label for="base_url" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Base URL</label>
|
|
<input type="url" id="base_url" name="base_url" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" value="http://localhost:8080" />
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Save Settings</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Security Tab -->
|
|
<div class="hidden p-4 rounded-lg bg-white dark:bg-gray-800" id="security" role="tabpanel" aria-labelledby="security-tab">
|
|
<h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">Security Settings</h2>
|
|
<form class="space-y-6" action="/settings/security" method="POST">
|
|
<div class="grid gap-6 mb-6 md:grid-cols-2">
|
|
<div>
|
|
<label for="session_timeout" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Session Timeout (minutes)</label>
|
|
<input type="number" id="session_timeout" name="session_timeout" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" value="60" min="5" max="1440" />
|
|
</div>
|
|
<div>
|
|
<label for="password_policy" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Password Policy</label>
|
|
<select id="password_policy" name="password_policy" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
|
<option value="standard">Standard (8+ chars, 1 uppercase, 1 number)</option>
|
|
<option value="strong">Strong (12+ chars, uppercase, number, symbol)</option>
|
|
<option value="very_strong">Very Strong (16+ chars, uppercase, number, symbol)</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="flex items-start mb-6">
|
|
<div class="flex items-center h-5">
|
|
<input id="enable_2fa" name="enable_2fa" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800" checked />
|
|
</div>
|
|
<div class="ml-3 text-sm">
|
|
<label for="enable_2fa" class="font-medium text-gray-900 dark:text-white">Enable Two-Factor Authentication</label>
|
|
<p class="text-xs font-normal text-gray-500 dark:text-gray-400">Require 2FA for all admin users</p>
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Save Settings</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
@toggleNotificationFields()
|
|
}
|
|
|
|
script toggleNotificationFields() {
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const typeSelector = document.getElementById('notification_type');
|
|
const allFields = document.querySelectorAll('.notification-fields');
|
|
const commonFields = document.querySelectorAll('.common-fields');
|
|
|
|
typeSelector.addEventListener('change', function() {
|
|
// Hide all fields first
|
|
allFields.forEach(field => field.classList.add('hidden'));
|
|
|
|
// Show/hide common fields based on selection
|
|
const selectedType = this.value;
|
|
if (selectedType) {
|
|
// Show common fields (name, description)
|
|
commonFields.forEach(field => field.classList.remove('hidden'));
|
|
|
|
// Show the selected type's specific fields
|
|
const fieldsToShow = document.getElementById(`${selectedType}_fields`);
|
|
if (fieldsToShow) {
|
|
fieldsToShow.classList.remove('hidden');
|
|
}
|
|
} else {
|
|
// Hide common fields if no type selected
|
|
commonFields.forEach(field => field.classList.add('hidden'));
|
|
}
|
|
});
|
|
});
|
|
}
|