2021-01-27 18:25:37 -05:00
< template >
2025-08-14 09:15:34 -04:00
< div class = "dashboard-container bg-background" >
< div class = "container mx-auto px-4 py-8 max-w-7xl" >
2025-08-19 07:32:04 -04:00
< div class = "mb-6" >
2025-08-14 09:15:34 -04:00
< div class = "flex items-center justify-between mb-6" >
< div >
2025-11-16 21:33:26 +01:00
< h1 class = "text-4xl font-bold tracking-tight" >{{ dashboardHeading }}</ h1 >
< p class = "text-muted-foreground mt-2" >{{ dashboardSubheading }}</ p >
2025-08-14 09:15:34 -04:00
</ div >
< div class = "flex items-center gap-4" >
< Button
variant = "ghost"
size = "icon"
@click ="toggleShowAverageResponseTime"
: title = "showAverageResponseTime ? 'Show min-max response time' : 'Show average response time'"
>
< Activity v-if = "showAverageResponseTime" class="h-5 w-5" />
< Timer v-else class = "h-5 w-5" />
</ Button >
< Button variant = "ghost" size = "icon" @click ="refreshData" title = "Refresh data" >
< RefreshCw class = "h-5 w-5" />
</ Button >
</ div >
</ div >
2025-11-07 19:35:39 -05:00
<!-- Announcement Banner ( Active Announcements ) -->
< AnnouncementBanner :announcements = "activeAnnouncements" />
2025-08-19 07:32:04 -04:00
<!-- Search bar -->
2025-08-14 09:15:34 -04:00
< SearchBar
@search ="handleSearch"
@ update : showOnlyFailing = "showOnlyFailing = $event"
@ update : showRecentFailures = "showRecentFailures = $event"
@ update : groupByGroup = "groupByGroup = $event"
@ update : sortBy = "sortBy = $event"
@initializeCollapsedGroups ="initializeCollapsedGroups"
/>
</ div >
< div v-if = "loading" class="flex items-center justify-center py-20" >
< Loading size = "lg" />
</ div >
2025-09-05 15:39:12 -04:00
< div v-else-if = "filteredEndpoints.length === 0 && filteredSuites.length === 0" class="text-center py-20" >
2025-08-14 09:15:34 -04:00
< AlertCircle class = "h-12 w-12 text-muted-foreground mx-auto mb-4" />
2025-09-05 15:39:12 -04:00
< h3 class = "text-lg font-semibold mb-2" > No endpoints or suites found </ h3 >
2025-08-14 09:15:34 -04:00
< p class = "text-muted-foreground" >
{{ searchQuery || showOnlyFailing || showRecentFailures
? 'Try adjusting your filters'
2025-09-05 15:39:12 -04:00
: 'No endpoints or suites are configured' }}
2025-08-14 09:15:34 -04:00
</ p >
</ div >
< div v-else >
<!-- Grouped view -- >
< div v-if = "groupByGroup" class="space-y-6" >
2025-09-05 15:39:12 -04:00
< div v-for = "(items, group) in combinedGroups" :key="group" class="endpoint-group border rounded-lg overflow-hidden" >
2025-08-14 09:15:34 -04:00
<!-- Group Header -- >
< div
@click ="toggleGroupCollapse(group)"
class = "endpoint-group-header flex items-center justify-between p-4 bg-card border-b cursor-pointer hover:bg-accent/50 transition-colors"
>
< div class = "flex items-center gap-3" >
2025-08-19 10:15:35 -04:00
< ChevronDown v-if = "uncollapsedGroups.has(group)" class="h-5 w-5 text-muted-foreground" />
2025-08-14 09:15:34 -04:00
< ChevronUp v-else class = "h-5 w-5 text-muted-foreground" />
< h2 class = "text-xl font-semibold text-foreground" >{{ group }}</ h2 >
</ div >
< div class = "flex items-center gap-2" >
2025-09-05 15:39:12 -04:00
< span v-if = "calculateUnhealthyCount(items.endpoints) + calculateFailingSuitesCount(items.suites) > 0"
2025-08-14 09:15:34 -04:00
class = "bg-red-600 text-white px-2 py-1 rounded-full text-sm font-medium" >
2025-09-05 15:39:12 -04:00
{{ calculateUnhealthyCount ( items . endpoints ) + calculateFailingSuitesCount ( items . suites ) }}
2025-08-14 09:15:34 -04:00
</ span >
< CheckCircle v-else class = "h-6 w-6 text-green-600" />
</ div >
</ div >
<!-- Group Content -->
2025-08-19 10:15:35 -04:00
< div v-if = "uncollapsedGroups.has(group)" class="endpoint-group-content p-4" >
2025-09-05 15:39:12 -04:00
<!-- Suites Section -- >
< div v-if = "items.suites.length > 0" class="mb-4" >
< h3 class = "text-sm font-semibold text-muted-foreground uppercase tracking-wider mb-3" > Suites </ h3 >
< div class = "grid gap-3 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3" >
< SuiteCard
v-for = "suite in items.suites"
:key = "suite.key"
:suite = "suite"
2025-11-29 01:05:39 +01:00
:maxResults = "resultPageSize"
2025-09-05 15:39:12 -04:00
@showTooltip ="showTooltip"
/>
</ div >
</ div >
<!-- Endpoints Section -->
< div v-if = "items.endpoints.length > 0" >
< h3 v-if = "items.suites.length > 0" class="text-sm font-semibold text-muted-foreground uppercase tracking-wider mb-3" > Endpoints </ h3 >
< div class = "grid gap-3 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3" >
< EndpointCard
v-for = "endpoint in items.endpoints"
:key = "endpoint.key"
:endpoint = "endpoint"
2025-11-29 01:05:39 +01:00
:maxResults = "resultPageSize"
2025-09-05 15:39:12 -04:00
:showAverageResponseTime = "showAverageResponseTime"
@showTooltip ="showTooltip"
/>
</ div >
2025-08-14 09:15:34 -04:00
</ div >
</ div >
</ div >
</ div >
<!-- Regular view -->
2025-09-05 15:39:12 -04:00
< div v-else >
<!-- Suites Section -- >
< div v-if = "filteredSuites.length > 0" class="mb-6" >
< h2 class = "text-lg font-semibold text-foreground mb-3" > Suites </ h2 >
< div class = "grid gap-3 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3" >
< SuiteCard
v-for = "suite in paginatedSuites"
:key = "suite.key"
:suite = "suite"
2025-11-29 01:05:39 +01:00
:maxResults = "resultPageSize"
2025-09-05 15:39:12 -04:00
@showTooltip ="showTooltip"
/>
</ div >
</ div >
<!-- Endpoints Section -->
< div v-if = "filteredEndpoints.length > 0" >
< h2 v-if = "filteredSuites.length > 0" class="text-lg font-semibold text-foreground mb-3" > Endpoints </ h2 >
< div class = "grid gap-3 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3" >
< EndpointCard
v-for = "endpoint in paginatedEndpoints"
:key = "endpoint.key"
:endpoint = "endpoint"
2025-11-29 01:05:39 +01:00
:maxResults = "resultPageSize"
2025-09-05 15:39:12 -04:00
:showAverageResponseTime = "showAverageResponseTime"
@showTooltip ="showTooltip"
/>
</ div >
</ div >
2025-08-14 09:15:34 -04:00
</ div >
< div v-if = "!groupByGroup && totalPages > 1" class="mt-8 flex items-center justify-center gap-2" >
< Button
variant = "outline"
size = "icon"
: disabled = "currentPage === 1"
@click ="goToPage(currentPage - 1)"
>
< ChevronLeft class = "h-4 w-4" />
</ Button >
< div class = "flex gap-1" >
< Button
v-for = "page in visiblePages"
:key = "page"
: variant = "page === currentPage ? 'default' : 'outline'"
size = "sm"
@click ="goToPage(page)"
>
{{ page }}
</ Button >
</ div >
< Button
variant = "outline"
size = "icon"
: disabled = "currentPage === totalPages"
@click ="goToPage(currentPage + 1)"
>
< ChevronRight class = "h-4 w-4" />
</ Button >
</ div >
</ div >
2025-11-07 19:35:39 -05:00
<!-- Past Announcements Section -->
< div v-if = "archivedAnnouncements.length > 0" class="mt-12 pb-8" >
< PastAnnouncements :announcements = "archivedAnnouncements" />
</ div >
2025-08-14 09:15:34 -04:00
</ div >
< Settings @refreshData ="fetchData" />
</ div >
2021-01-27 18:25:37 -05:00
</ template >
2025-08-14 09:15:34 -04:00
< script setup >
/* eslint-disable no-undef */
import { ref , computed , onMounted } from 'vue'
import { Activity , Timer , RefreshCw , AlertCircle , ChevronLeft , ChevronRight , ChevronDown , ChevronUp , CheckCircle } from 'lucide-vue-next'
import { Button } from '@/components/ui/button'
import EndpointCard from '@/components/EndpointCard.vue'
2025-09-05 15:39:12 -04:00
import SuiteCard from '@/components/SuiteCard.vue'
2025-08-14 09:15:34 -04:00
import SearchBar from '@/components/SearchBar.vue'
2021-01-27 18:25:37 -05:00
import Settings from '@/components/Settings.vue'
2025-08-14 09:15:34 -04:00
import Loading from '@/components/Loading.vue'
2025-08-16 09:54:50 -04:00
import AnnouncementBanner from '@/components/AnnouncementBanner.vue'
2025-11-07 19:35:39 -05:00
import PastAnnouncements from '@/components/PastAnnouncements.vue'
2025-08-14 09:15:34 -04:00
import { SERVER_URL } from '@/main.js'
2025-08-16 09:54:50 -04:00
const props = defineProps ({
announcements : {
type : Array ,
default : () => []
}
})
2025-11-07 19:35:39 -05:00
// Computed properties for active and archived announcements
const activeAnnouncements = computed (() => {
return props . announcements ? props . announcements . filter ( a => ! a . archived ) : []
})
const archivedAnnouncements = computed (() => {
return props . announcements ? props . announcements . filter ( a => a . archived ) : []
})
2025-08-14 09:15:34 -04:00
const emit = defineEmits ([ 'showTooltip' ])
const endpointStatuses = ref ([])
2025-09-05 15:39:12 -04:00
const suiteStatuses = ref ([])
2025-08-14 09:15:34 -04:00
const loading = ref ( false )
const currentPage = ref ( 1 )
const itemsPerPage = 96
const searchQuery = ref ( '' )
const showOnlyFailing = ref ( false )
const showRecentFailures = ref ( false )
const showAverageResponseTime = ref ( true )
const groupByGroup = ref ( false )
const sortBy = ref ( localStorage . getItem ( 'gatus:sort-by' ) || 'name' )
2025-08-19 10:15:35 -04:00
const uncollapsedGroups = ref ( new Set ())
2025-11-29 01:05:39 +01:00
const resultPageSize = 50
2025-08-14 09:15:34 -04:00
const filteredEndpoints = computed (() => {
let filtered = [... endpointStatuses . value ]
if ( searchQuery . value ) {
const query = searchQuery . value . toLowerCase ()
filtered = filtered . filter ( endpoint =>
endpoint . name . toLowerCase (). includes ( query ) ||
( endpoint . group && endpoint . group . toLowerCase (). includes ( query ))
)
}
if ( showOnlyFailing . value ) {
filtered = filtered . filter ( endpoint => {
if ( ! endpoint . results || endpoint . results . length === 0 ) return false
const latestResult = endpoint . results [ endpoint . results . length - 1 ]
return ! latestResult . success
})
}
if ( showRecentFailures . value ) {
filtered = filtered . filter ( endpoint => {
if ( ! endpoint . results || endpoint . results . length === 0 ) return false
return endpoint . results . some ( result => ! result . success )
})
}
// Sort by health if selected
if ( sortBy . value === 'health' ) {
filtered . sort (( a , b ) => {
const aHealthy = a . results && a . results . length > 0 && a . results [ a . results . length - 1 ]. success
const bHealthy = b . results && b . results . length > 0 && b . results [ b . results . length - 1 ]. success
// Unhealthy first
if ( ! aHealthy && bHealthy ) return - 1
if ( aHealthy && ! bHealthy ) return 1
// Then sort by name
return a . name . localeCompare ( b . name )
})
}
return filtered
})
2025-09-05 15:39:12 -04:00
const filteredSuites = computed (() => {
2025-09-06 06:34:27 -04:00
let filtered = [...( suiteStatuses . value || [])]
2025-09-05 15:39:12 -04:00
if ( searchQuery . value ) {
const query = searchQuery . value . toLowerCase ()
filtered = filtered . filter ( suite =>
suite . name . toLowerCase (). includes ( query ) ||
( suite . group && suite . group . toLowerCase (). includes ( query ))
)
}
if ( showOnlyFailing . value ) {
filtered = filtered . filter ( suite => {
if ( ! suite . results || suite . results . length === 0 ) return false
return ! suite . results [ suite . results . length - 1 ]. success
})
}
if ( showRecentFailures . value ) {
filtered = filtered . filter ( suite => {
if ( ! suite . results || suite . results . length === 0 ) return false
return suite . results . some ( result => ! result . success )
})
}
// Sort by health if selected
if ( sortBy . value === 'health' ) {
filtered . sort (( a , b ) => {
const aHealthy = a . results && a . results . length > 0 && a . results [ a . results . length - 1 ]. success
const bHealthy = b . results && b . results . length > 0 && b . results [ b . results . length - 1 ]. success
// Unhealthy first
if ( ! aHealthy && bHealthy ) return - 1
if ( aHealthy && ! bHealthy ) return 1
// Then sort by name
return a . name . localeCompare ( b . name )
})
}
return filtered
})
2025-08-14 09:15:34 -04:00
const totalPages = computed (() => {
2025-09-05 15:39:12 -04:00
return Math . ceil (( filteredEndpoints . value . length + filteredSuites . value . length ) / itemsPerPage )
2025-08-14 09:15:34 -04:00
})
const groupedEndpoints = computed (() => {
if ( ! groupByGroup . value ) {
return null
}
const grouped = {}
filteredEndpoints . value . forEach ( endpoint => {
const group = endpoint . group || 'No Group'
if ( ! grouped [ group ]) {
grouped [ group ] = []
2021-01-27 18:25:37 -05:00
}
2025-08-14 09:15:34 -04:00
grouped [ group ]. push ( endpoint )
})
// Sort groups alphabetically, with 'No Group' at the end
const sortedGroups = Object . keys ( grouped ). sort (( a , b ) => {
if ( a === 'No Group' ) return 1
if ( b === 'No Group' ) return - 1
return a . localeCompare ( b )
})
const result = {}
sortedGroups . forEach ( group => {
result [ group ] = grouped [ group ]
})
return result
})
2025-09-05 15:39:12 -04:00
const combinedGroups = computed (() => {
if ( ! groupByGroup . value ) {
return null
}
const combined = {}
// Add endpoints
filteredEndpoints . value . forEach ( endpoint => {
const group = endpoint . group || 'No Group'
if ( ! combined [ group ]) {
combined [ group ] = { endpoints : [], suites : [] }
}
combined [ group ]. endpoints . push ( endpoint )
})
// Add suites
filteredSuites . value . forEach ( suite => {
const group = suite . group || 'No Group'
if ( ! combined [ group ]) {
combined [ group ] = { endpoints : [], suites : [] }
}
combined [ group ]. suites . push ( suite )
})
// Sort groups alphabetically, with 'No Group' at the end
const sortedGroups = Object . keys ( combined ). sort (( a , b ) => {
if ( a === 'No Group' ) return 1
if ( b === 'No Group' ) return - 1
return a . localeCompare ( b )
})
const result = {}
sortedGroups . forEach ( group => {
result [ group ] = combined [ group ]
})
return result
})
2025-08-14 09:15:34 -04:00
const paginatedEndpoints = computed (() => {
if ( groupByGroup . value ) {
// When grouping, we don't paginate
return groupedEndpoints . value
2021-01-27 18:25:37 -05:00
}
2025-08-14 09:15:34 -04:00
const start = ( currentPage . value - 1 ) * itemsPerPage
const end = start + itemsPerPage
return filteredEndpoints . value . slice ( start , end )
})
2025-09-05 15:39:12 -04:00
const paginatedSuites = computed (() => {
if ( groupByGroup . value ) {
// When grouping, we don't paginate
return filteredSuites . value
}
const start = ( currentPage . value - 1 ) * itemsPerPage
const end = start + itemsPerPage
return filteredSuites . value . slice ( start , end )
})
2025-08-14 09:15:34 -04:00
const visiblePages = computed (() => {
const pages = []
const maxVisible = 5
let start = Math . max ( 1 , currentPage . value - Math . floor ( maxVisible / 2 ))
let end = Math . min ( totalPages . value , start + maxVisible - 1 )
if ( end - start < maxVisible - 1 ) {
start = Math . max ( 1 , end - maxVisible + 1 )
}
for ( let i = start ; i <= end ; i ++ ) {
pages . push ( i )
}
return pages
})
const fetchData = async () => {
2025-08-18 12:36:16 -04:00
// Don't show loading state on refresh to prevent UI flicker
2025-09-05 15:39:12 -04:00
const isInitialLoad = endpointStatuses . value . length === 0 && suiteStatuses . value . length === 0
2025-08-18 12:36:16 -04:00
if ( isInitialLoad ) {
loading . value = true
}
2025-08-14 09:15:34 -04:00
try {
2025-09-05 15:39:12 -04:00
// Fetch endpoints
2025-11-29 01:05:39 +01:00
const endpointResponse = await fetch ( ` ${ SERVER_URL } /api/v1/endpoints/statuses?page=1&pageSize= ${ resultPageSize } ` , {
2025-08-14 09:15:34 -04:00
credentials : 'include'
})
2025-09-05 15:39:12 -04:00
if ( endpointResponse . status === 200 ) {
const data = await endpointResponse . json ()
endpointStatuses . value = data
2025-08-14 09:15:34 -04:00
} else {
2025-09-05 15:39:12 -04:00
console . error ( '[Home][fetchData] Error fetching endpoints:' , await endpointResponse . text ())
}
// Fetch suites
2025-11-29 01:05:39 +01:00
const suiteResponse = await fetch ( ` ${ SERVER_URL } /api/v1/suites/statuses?page=1&pageSize= ${ resultPageSize } ` , {
2025-09-05 15:39:12 -04:00
credentials : 'include'
})
if ( suiteResponse . status === 200 ) {
const suiteData = await suiteResponse . json ()
2025-09-06 06:34:27 -04:00
suiteStatuses . value = suiteData || []
2025-09-05 15:39:12 -04:00
} else {
console . error ( '[Home][fetchData] Error fetching suites:' , await suiteResponse . text ())
2025-09-06 06:34:27 -04:00
// Ensure suiteStatuses stays as empty array instead of becoming null/undefined
if ( ! suiteStatuses . value ) {
suiteStatuses . value = []
}
2025-08-14 09:15:34 -04:00
}
} catch ( error ) {
console . error ( '[Home][fetchData] Error:' , error )
} finally {
2025-08-18 12:36:16 -04:00
if ( isInitialLoad ) {
loading . value = false
}
2025-08-14 09:15:34 -04:00
}
}
const refreshData = () => {
2025-08-18 12:36:16 -04:00
endpointStatuses . value = [];
2025-09-06 06:34:27 -04:00
suiteStatuses . value = [];
2025-08-14 09:15:34 -04:00
fetchData ()
}
const handleSearch = ( query ) => {
searchQuery . value = query
currentPage . value = 1
}
const goToPage = ( page ) => {
currentPage . value = page
window . scrollTo ({ top : 0 , behavior : 'smooth' })
}
const toggleShowAverageResponseTime = () => {
showAverageResponseTime . value = ! showAverageResponseTime . value
}
2025-10-17 13:09:47 -07:00
const showTooltip = ( result , event , action = 'hover' ) => {
emit ( 'showTooltip' , result , event , action )
2021-01-27 18:25:37 -05:00
}
2025-08-14 09:15:34 -04:00
const calculateUnhealthyCount = ( endpoints ) => {
return endpoints . filter ( endpoint => {
if ( ! endpoint . results || endpoint . results . length === 0 ) return false
const latestResult = endpoint . results [ endpoint . results . length - 1 ]
return ! latestResult . success
}). length
}
2025-09-05 15:39:12 -04:00
const calculateFailingSuitesCount = ( suites ) => {
return suites . filter ( suite => {
if ( ! suite . results || suite . results . length === 0 ) return false
return ! suite . results [ suite . results . length - 1 ]. success
}). length
}
2025-08-14 09:15:34 -04:00
const toggleGroupCollapse = ( groupName ) => {
2025-08-19 10:15:35 -04:00
if ( uncollapsedGroups . value . has ( groupName )) {
uncollapsedGroups . value . delete ( groupName )
2025-08-14 09:15:34 -04:00
} else {
2025-08-19 10:15:35 -04:00
uncollapsedGroups . value . add ( groupName )
2025-08-14 09:15:34 -04:00
}
// Save to localStorage
2025-08-19 10:15:35 -04:00
const uncollapsed = Array . from ( uncollapsedGroups . value )
localStorage . setItem ( 'gatus:uncollapsed-groups' , JSON . stringify ( uncollapsed ))
localStorage . removeItem ( 'gatus:collapsed-groups' ) // Remove old key if it exists
2025-08-14 09:15:34 -04:00
}
const initializeCollapsedGroups = () => {
2025-08-19 10:15:35 -04:00
// Get saved uncollapsed groups from localStorage
2025-08-14 09:15:34 -04:00
try {
2025-08-19 10:15:35 -04:00
const saved = localStorage . getItem ( 'gatus:uncollapsed-groups' )
2025-08-14 09:15:34 -04:00
if ( saved ) {
2025-08-19 10:15:35 -04:00
uncollapsedGroups . value = new Set ( JSON . parse ( saved ))
2025-08-14 09:15:34 -04:00
}
2025-08-19 10:15:35 -04:00
// If no saved state, uncollapsedGroups stays empty (all collapsed by default)
2025-08-14 09:15:34 -04:00
} catch ( e ) {
2025-08-19 10:15:35 -04:00
console . warn ( 'Failed to parse saved uncollapsed groups:' , e )
localStorage . removeItem ( 'gatus:uncollapsed-groups' )
// On error, uncollapsedGroups stays empty (all collapsed by default)
2025-08-14 09:15:34 -04:00
}
}
2025-11-16 21:33:26 +01:00
const dashboardHeading = computed (() => {
return window . config && window . config . dashboardHeading && window . config . dashboardHeading !== '{{ .UI.DashboardHeading }}' ? window . config . dashboardHeading : "Health Dashboard"
})
const dashboardSubheading = computed (() => {
2025-11-27 20:55:30 -05:00
return window . config && window . config . dashboardSubheading && window . config . dashboardSubheading !== '{{ .UI.DashboardSubheading }}' ? window . config . dashboardSubheading : "Monitor the health of your endpoints in real-time"
2025-11-16 21:33:26 +01:00
})
2025-08-14 09:15:34 -04:00
onMounted (() => {
fetchData ()
})
2021-01-27 18:25:37 -05:00
</ script >