Skip to content

Commit bb18ac8

Browse files
committed
feat: add auto-refresh functionality for environment list with configurable interval
1 parent 46d2629 commit bb18ac8

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

api/cluster/environment.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ func GetEnvironmentList(c *gin.Context) {
4848

4949
core.SetTransformer(func(m *model.Environment) any {
5050
return analytic.GetNode(m)
51-
}).PagingList()
51+
})
52+
53+
data, ok := core.ListAllData()
54+
if !ok {
55+
return
56+
}
57+
58+
c.JSON(http.StatusOK, model.DataList{
59+
Data: data,
60+
})
5261
}
5362

5463
func GetAllEnabledEnvironment(c *gin.Context) {

app/src/views/environments/list/Environment.vue

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,54 @@ const loadingFromSettings = ref(false)
1313
const loadingReload = ref(false)
1414
const loadingRestart = ref(false)
1515
16+
// Auto refresh logic
17+
const isAutoRefresh = ref(true)
18+
const autoRefreshInterval = ref(5) // seconds
19+
const autoRefreshTimer = ref<NodeJS.Timeout | null>(null)
20+
21+
function startAutoRefresh() {
22+
if (autoRefreshTimer.value) {
23+
clearInterval(autoRefreshTimer.value)
24+
}
25+
26+
autoRefreshTimer.value = setInterval(() => {
27+
if (curd.value) {
28+
curd.value.refresh()
29+
}
30+
}, autoRefreshInterval.value * 1000)
31+
}
32+
33+
function stopAutoRefresh() {
34+
if (autoRefreshTimer.value) {
35+
clearInterval(autoRefreshTimer.value)
36+
autoRefreshTimer.value = null
37+
}
38+
}
39+
40+
// Watch for auto refresh state changes
41+
watch(isAutoRefresh, newValue => {
42+
if (newValue) {
43+
startAutoRefresh()
44+
message.success($gettext('Auto refresh enabled'))
45+
}
46+
else {
47+
stopAutoRefresh()
48+
message.success($gettext('Auto refresh disabled'))
49+
}
50+
})
51+
52+
// Initialize auto refresh on mount if enabled
53+
onMounted(() => {
54+
if (isAutoRefresh.value) {
55+
startAutoRefresh()
56+
}
57+
})
58+
59+
// Clean up timer on component unmount
60+
onBeforeUnmount(() => {
61+
stopAutoRefresh()
62+
})
63+
1664
function loadFromSettings() {
1765
loadingFromSettings.value = true
1866
environment.load_from_settings().then(() => {
@@ -78,6 +126,7 @@ const inTrash = computed(() => {
78126
disabled: !record.status,
79127
}),
80128
},
129+
pagination: false,
81130
}"
82131
:title="$gettext('Environments')"
83132
:api="environment"
@@ -89,6 +138,37 @@ const inTrash = computed(() => {
89138
{{ $gettext('Load from settings') }}
90139
</AButton>
91140
</template>
141+
142+
<template #afterListActions>
143+
<div class="flex items-center gap-2">
144+
<ASelect
145+
v-model:value="autoRefreshInterval"
146+
size="small"
147+
class="w-16"
148+
:disabled="isAutoRefresh"
149+
@change="isAutoRefresh && startAutoRefresh()"
150+
>
151+
<ASelectOption :value="5">
152+
5s
153+
</ASelectOption>
154+
<ASelectOption :value="10">
155+
10s
156+
</ASelectOption>
157+
<ASelectOption :value="30">
158+
30s
159+
</ASelectOption>
160+
<ASelectOption :value="60">
161+
60s
162+
</ASelectOption>
163+
</ASelect>
164+
165+
<span>{{ $gettext('Auto Refresh') }}</span>
166+
<ASwitch
167+
v-model:checked="isAutoRefresh"
168+
size="small"
169+
/>
170+
</div>
171+
</template>
92172
</StdCurd>
93173

94174
<BatchUpgrader ref="refUpgrader" @success="curd.refresh()" />

0 commit comments

Comments
 (0)