mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 15:41:20 +02:00
- Added sorting capabilities to file metadata lists, including SortBy and SortDir fields. - Integrated a toast notification system for user feedback on actions. - Updated templates and JavaScript for improved user interaction and responsiveness. - Refactored file metadata handlers to utilize new sorting features and ensure proper data flow. - Introduced new notification dialog components for better user confirmation on actions.
207 lines
9.6 KiB
Templ
207 lines
9.6 KiB
Templ
package list
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/starfleetcptn/gomft/components"
|
|
"github.com/starfleetcptn/gomft/components/notifications/dialog"
|
|
"github.com/starfleetcptn/gomft/components/notifications/types"
|
|
)
|
|
|
|
// List renders the notification services list page.
|
|
templ List(ctx context.Context, data types.SettingsNotificationsData) {
|
|
@components.LayoutWithContext("Notification Services", ctx) {
|
|
<!-- Status and Error Messages (Handled by shared toast component in layout) -->
|
|
|
|
<div id="notifications-container" class="notifications-page bg-gray-50 dark:bg-gray-900 min-h-screen">
|
|
<div class="pb-8 w-full">
|
|
<!-- Success Message (hidden, used for HTMX responses/toast trigger) -->
|
|
if data.SuccessMessage != "" {
|
|
<div class="hidden success-message">{ data.SuccessMessage }</div>
|
|
}
|
|
<!-- Error Message (hidden, used for HTMX responses/toast trigger) -->
|
|
if data.ErrorMessage != "" {
|
|
<div class="hidden error-message">{ data.ErrorMessage }</div>
|
|
}
|
|
|
|
<div class="mb-6 flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
|
<h1 class="text-2xl font-bold text-gray-900 dark:text-white flex items-center">
|
|
<i class="fas fa-bell w-6 h-6 mr-2 text-blue-500 dark:text-blue-400"></i>
|
|
Notification Services
|
|
</h1>
|
|
<a href="/admin/settings/notifications/new" class="flex items-center justify-center text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg px-5 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">
|
|
<i class="fas fa-plus w-4 h-4 mr-2"></i>
|
|
Add Notification Service
|
|
</a>
|
|
</div>
|
|
|
|
<!-- List of Notification Services -->
|
|
if len(data.NotificationServices) == 0 {
|
|
<div class="text-center py-8 bg-white dark:bg-gray-800 shadow-md rounded-lg">
|
|
<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">Add a notification service to receive alerts for job events.</p>
|
|
<a href="/admin/settings/notifications/new" class="inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">
|
|
<i class="fas fa-plus w-4 h-4 mr-2"></i>
|
|
Add First Notification Service
|
|
</a>
|
|
</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 { // Default icon
|
|
<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">
|
|
<a
|
|
href={ templ.SafeURL(fmt.Sprintf("/admin/settings/notifications/%d/edit", service.ID)) }
|
|
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"
|
|
>
|
|
<i class="fas fa-edit"></i>
|
|
</a>
|
|
<!-- Add notification delete dialog -->
|
|
@dialog.NotificationDialog(
|
|
fmt.Sprintf("delete-notification-dialog-%d", service.ID),
|
|
"Delete Notification Service",
|
|
fmt.Sprintf("Are you sure you want to delete the notification service '%s'? This cannot be undone.", service.Name),
|
|
"text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5 dark:bg-red-600 dark:hover:bg-red-700 focus:outline-none dark:focus:ring-red-800",
|
|
"Delete",
|
|
"delete",
|
|
service.ID,
|
|
service.Name,
|
|
)
|
|
<button
|
|
type="button"
|
|
onclick={ templ.ComponentScript{Call: fmt.Sprintf("showModal('delete-notification-dialog-%d')", service.ID)} }
|
|
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"
|
|
>
|
|
<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>
|
|
}
|
|
|
|
<!-- Help Notice Placeholder -->
|
|
<div class="mt-8 p-4 bg-gray-50 border border-gray-200 rounded-lg dark:bg-gray-800 dark:border-gray-700">
|
|
<div class="flex">
|
|
<div class="flex-shrink-0">
|
|
<i class="fas fa-info-circle text-blue-400 dark:text-blue-400"></i>
|
|
</div>
|
|
<div class="ml-3">
|
|
<p class="text-sm text-blue-700 dark:text-blue-400">
|
|
Notification services allow the system to send alerts for job events such as completion, errors, or when jobs start.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@dialog.DialogScripts()
|
|
|
|
}
|
|
// Script call removed for now
|
|
} |