Make auto refresh interval customizable (#4260)

Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
Laurent Aupse 2024-05-19 21:56:55 +02:00 committed by GitHub
parent 4e24e96dab
commit e856cb6007
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 8 deletions

View file

@ -0,0 +1,12 @@
exports.up = function (knex) {
return knex.schema
.alterTable("status_page", function (table) {
table.integer("auto_refresh_interval").defaultTo(300).unsigned();
});
};
exports.down = function (knex) {
return knex.schema.alterTable("status_page", function (table) {
table.dropColumn("auto_refresh_interval");
});
};

View file

@ -238,6 +238,7 @@ class StatusPage extends BeanModel {
description: this.description, description: this.description,
icon: this.getIcon(), icon: this.getIcon(),
theme: this.theme, theme: this.theme,
autoRefreshInterval: this.autoRefreshInterval,
published: !!this.published, published: !!this.published,
showTags: !!this.show_tags, showTags: !!this.show_tags,
domainNameList: this.getDomainNameList(), domainNameList: this.getDomainNameList(),
@ -260,6 +261,7 @@ class StatusPage extends BeanModel {
title: this.title, title: this.title,
description: this.description, description: this.description,
icon: this.getIcon(), icon: this.getIcon(),
autoRefreshInterval: this.autoRefreshInterval,
theme: this.theme, theme: this.theme,
published: !!this.published, published: !!this.published,
showTags: !!this.show_tags, showTags: !!this.show_tags,

View file

@ -155,6 +155,7 @@ module.exports.statusPageSocketHandler = (socket) => {
statusPage.title = config.title; statusPage.title = config.title;
statusPage.description = config.description; statusPage.description = config.description;
statusPage.icon = config.logo; statusPage.icon = config.logo;
statusPage.autoRefreshInterval = config.autoRefreshInterval,
statusPage.theme = config.theme; statusPage.theme = config.theme;
//statusPage.published = ; //statusPage.published = ;
//statusPage.search_engine_index = ; //statusPage.search_engine_index = ;
@ -280,6 +281,7 @@ module.exports.statusPageSocketHandler = (socket) => {
statusPage.title = title; statusPage.title = title;
statusPage.theme = "auto"; statusPage.theme = "auto";
statusPage.icon = ""; statusPage.icon = "";
statusPage.autoRefreshInterval = 300;
await R.store(statusPage); await R.store(statusPage);
callback({ callback({

View file

@ -361,6 +361,8 @@
"Proxy": "Proxy", "Proxy": "Proxy",
"Date Created": "Date Created", "Date Created": "Date Created",
"Footer Text": "Footer Text", "Footer Text": "Footer Text",
"Refresh Interval": "Refresh Interval",
"Refresh Interval Description": "The status page will do a full site refresh every {0} seconds",
"Show Powered By": "Show Powered By", "Show Powered By": "Show Powered By",
"Domain Names": "Domain Names", "Domain Names": "Domain Names",
"signedInDisp": "Signed in as {0}", "signedInDisp": "Signed in as {0}",

View file

@ -34,6 +34,14 @@
</div> </div>
</div> </div>
<div class="my-3">
<label for="auto-refresh-interval" class="form-label">{{ $t("Refresh Interval") }}</label>
<input id="auto-refresh-interval" v-model="config.autoRefreshInterval" type="number" class="form-control" :min="5">
<div class="form-text">
{{ $t("Refresh Interval Description", [config.autoRefreshInterval]) }}
</div>
</div>
<div class="my-3"> <div class="my-3">
<label for="switch-theme" class="form-label">{{ $t("Theme") }}</label> <label for="switch-theme" class="form-label">{{ $t("Theme") }}</label>
<select id="switch-theme" v-model="config.theme" class="form-select"> <select id="switch-theme" v-model="config.theme" class="form-select">
@ -438,7 +446,6 @@ export default {
baseURL: "", baseURL: "",
clickedEditButton: false, clickedEditButton: false,
maintenanceList: [], maintenanceList: [],
autoRefreshInterval: 5,
lastUpdateTime: dayjs(), lastUpdateTime: dayjs(),
updateCountdown: null, updateCountdown: null,
updateCountdownText: null, updateCountdownText: null,
@ -708,6 +715,13 @@ export default {
this.$root.publicGroupList = res.data.publicGroupList; this.$root.publicGroupList = res.data.publicGroupList;
this.loading = false; this.loading = false;
// Configure auto-refresh loop
feedInterval = setInterval(() => {
this.updateHeartbeatList();
}, (this.config.autoRefreshInterval + 10) * 1000);
this.updateUpdateTimer();
}).catch( function (error) { }).catch( function (error) {
if (error.response.status === 404) { if (error.response.status === 404) {
location.href = "/page-not-found"; location.href = "/page-not-found";
@ -715,13 +729,7 @@ export default {
console.log(error); console.log(error);
}); });
// Configure auto-refresh loop
this.updateHeartbeatList(); this.updateHeartbeatList();
feedInterval = setInterval(() => {
this.updateHeartbeatList();
}, (this.autoRefreshInterval * 60 + 10) * 1000);
this.updateUpdateTimer();
// Go to edit page if ?edit present // Go to edit page if ?edit present
// null means ?edit present, but no value // null means ?edit present, but no value
@ -797,7 +805,7 @@ export default {
clearInterval(this.updateCountdown); clearInterval(this.updateCountdown);
this.updateCountdown = setInterval(() => { this.updateCountdown = setInterval(() => {
const countdown = dayjs.duration(this.lastUpdateTime.add(this.autoRefreshInterval, "minutes").add(10, "seconds").diff(dayjs())); const countdown = dayjs.duration(this.lastUpdateTime.add(this.config.autoRefreshInterval, "seconds").add(10, "seconds").diff(dayjs()));
if (countdown.as("seconds") < 0) { if (countdown.as("seconds") < 0) {
clearInterval(this.updateCountdown); clearInterval(this.updateCountdown);
} else { } else {