Feat: Add status page countdown to refresh

pull/2878/head
Nelson Chan 2 years ago
parent 94c3861608
commit 193a273557

@ -306,6 +306,11 @@
<p v-if="config.showPoweredBy"> <p v-if="config.showPoweredBy">
{{ $t("Powered by") }} <a target="_blank" rel="noopener noreferrer" href="https://github.com/louislam/uptime-kuma">{{ $t("Uptime Kuma" ) }}</a> {{ $t("Powered by") }} <a target="_blank" rel="noopener noreferrer" href="https://github.com/louislam/uptime-kuma">{{ $t("Uptime Kuma" ) }}</a>
</p> </p>
<div class="refresh-info mb-2">
<div>{{ $t("last update") }}: <date-time :value="lastUpdateTime" /></div>
<div>{{ $t("refresh in") }}: {{ updateCountdownText }}</div>
</div>
</footer> </footer>
</div> </div>
@ -322,6 +327,7 @@
<script> <script>
import axios from "axios"; import axios from "axios";
import dayjs from "dayjs"; import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import Favico from "favico.js"; import Favico from "favico.js";
// import highlighting library (you can use any library you want just return html string) // import highlighting library (you can use any library you want just return html string)
import { highlight, languages } from "prismjs/components/prism-core"; import { highlight, languages } from "prismjs/components/prism-core";
@ -337,10 +343,12 @@ import DOMPurify from "dompurify";
import Confirm from "../components/Confirm.vue"; import Confirm from "../components/Confirm.vue";
import PublicGroupList from "../components/PublicGroupList.vue"; import PublicGroupList from "../components/PublicGroupList.vue";
import MaintenanceTime from "../components/MaintenanceTime.vue"; import MaintenanceTime from "../components/MaintenanceTime.vue";
import DateTime from "../components/Datetime.vue";
import { getResBaseURL } from "../util-frontend"; import { getResBaseURL } from "../util-frontend";
import { STATUS_PAGE_ALL_DOWN, STATUS_PAGE_ALL_UP, STATUS_PAGE_MAINTENANCE, STATUS_PAGE_PARTIAL_DOWN, UP, MAINTENANCE } from "../util.ts"; import { STATUS_PAGE_ALL_DOWN, STATUS_PAGE_ALL_UP, STATUS_PAGE_MAINTENANCE, STATUS_PAGE_PARTIAL_DOWN, UP, MAINTENANCE } from "../util.ts";
const toast = useToast(); const toast = useToast();
dayjs.extend(duration);
const leavePageMsg = "Do you really want to leave? you have unsaved changes!"; const leavePageMsg = "Do you really want to leave? you have unsaved changes!";
@ -359,6 +367,7 @@ export default {
Confirm, Confirm,
PrismEditor, PrismEditor,
MaintenanceTime, MaintenanceTime,
DateTime,
}, },
// Leave Page for vue route change // Leave Page for vue route change
@ -400,6 +409,10 @@ export default {
baseURL: "", baseURL: "",
clickedEditButton: false, clickedEditButton: false,
maintenanceList: [], maintenanceList: [],
autoRefreshInterval: 5,
lastUpdateTime: dayjs(),
updateCountdown: null,
updateCountdownText: null,
}; };
}, },
computed: { computed: {
@ -637,11 +650,13 @@ export default {
console.log(error); console.log(error);
}); });
// 5mins a loop // Configure auto-refresh loop
this.updateHeartbeatList(); this.updateHeartbeatList();
feedInterval = setInterval(() => { feedInterval = setInterval(() => {
this.updateHeartbeatList(); this.updateHeartbeatList();
}, (300 + 10) * 1000); }, (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
@ -700,10 +715,29 @@ export default {
favicon.badge(downMonitors); favicon.badge(downMonitors);
this.loadedData = true; this.loadedData = true;
this.lastUpdateTime = dayjs();
this.updateUpdateTimer();
}); });
} }
}, },
/**
* Setup timer to display countdown to refresh
* @returns {void}
*/
updateUpdateTimer() {
clearInterval(this.updateCountdown);
this.updateCountdown = setInterval(() => {
const countdown = dayjs.duration(this.lastUpdateTime.add(this.autoRefreshInterval, "minutes").add(10, "seconds").diff(dayjs()));
if (countdown.as("seconds") < 0) {
clearInterval(this.updateCountdown);
} else {
this.updateCountdownText = countdown.format("mm:ss");
}
}, 1000);
},
/** Enable editing mode */ /** Enable editing mode */
edit() { edit() {
if (this.hasToken) { if (this.hasToken) {
@ -1118,4 +1152,8 @@ footer {
} }
} }
.refresh-info {
opacity: 0.7;
}
</style> </style>

Loading…
Cancel
Save