Skip to content

Commit 0065abb

Browse files
committed
manual/auto refresh control
1 parent 2616724 commit 0065abb

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script setup lang="ts">
2+
import { ref } from "vue";
3+
import OnOffSwitch from "./OnOffSwitch.vue";
4+
5+
const props = defineProps<{
6+
id: string;
7+
initialTimeout?: number;
8+
onChange: (newValue: number | null) => void;
9+
onManualRefresh: () => void;
10+
}>();
11+
12+
const autoRefresh = ref(props.initialTimeout != null);
13+
const refreshTimeout = ref(props.initialTimeout ?? 5);
14+
15+
function toggleRefresh() {
16+
autoRefresh.value = !autoRefresh.value;
17+
updateTimeout();
18+
}
19+
20+
function updateTimeout() {
21+
validateTimeout();
22+
props.onChange(autoRefresh.value ? refreshTimeout.value * 1000 : null);
23+
}
24+
25+
function validateTimeout() {
26+
refreshTimeout.value = Math.max(1, Math.min(600, refreshTimeout.value));
27+
}
28+
</script>
29+
30+
<template>
31+
<div class="refresh-config">
32+
<button class="fa" title="refresh" @click="() => onManualRefresh()">
33+
<i class="fa fa-lg fa-refresh" />
34+
</button>
35+
<span>|</span>
36+
<label>Auto-Refresh:</label>
37+
<div>
38+
<OnOffSwitch :id="id" @toggle="toggleRefresh" :value="autoRefresh" />
39+
</div>
40+
<input type="number" v-model="refreshTimeout" min="1" max="600" v-on:change="updateTimeout" />
41+
<span class="unit">s</span>
42+
</div>
43+
</template>
44+
45+
<style scoped>
46+
.refresh-config {
47+
display: flex;
48+
align-items: center;
49+
gap: 0.5em;
50+
}
51+
52+
.refresh-config .unit {
53+
margin-left: -0.45em;
54+
}
55+
56+
.refresh-config label {
57+
margin: 0;
58+
}
59+
60+
.refresh-config input {
61+
width: 3.5em;
62+
}
63+
64+
.refresh-config button {
65+
background: none;
66+
border: none;
67+
width: 2em;
68+
}
69+
70+
.refresh-config button .fa {
71+
transition: all 0.15s ease-in-out;
72+
transition: rotate 0.05s ease-in-out;
73+
transform-origin: center;
74+
}
75+
76+
.refresh-config button:hover .fa {
77+
color: #00a3c4;
78+
transform: scale(1.1);
79+
}
80+
81+
.refresh-config button:active .fa {
82+
transform: rotate(25deg);
83+
text-shadow: #929e9e 0.25px 0.25px;
84+
}
85+
</style>

src/Frontend/src/components/audit/AuditList.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SortableColumn from "../SortableColumn.vue";
88
import { MessageStatus } from "@/resources/Message";
99
import moment from "moment";
1010
import { useFormatTime } from "@/composables/formatter";
11+
import RefreshConfig from "../RefreshConfig.vue";
1112
1213
const route = useRoute();
1314
const store = useAuditStore();
@@ -64,6 +65,7 @@ function formatDotNetTimespan(timespan: string) {
6465
</script>
6566

6667
<template>
68+
<RefreshConfig id="auditListRefresh" @change="store.updateRefreshTimer" @manual-refresh="store.refresh" />
6769
<section role="table" aria-label="endpoint-instances">
6870
<!--Table headings-->
6971
<div role="row" aria-label="column-headers" class="row table-head-row" :style="{ borderTop: 0 }">

src/Frontend/src/composables/autoRefresh.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { ref } from "vue";
2-
31
/**
42
* Enables refresh functionality, either auto or manual
53
* @param refreshAction The action to perform (by default) when refreshing
64
* @param defaultTimeout The time between refreshes in ms or null if no auto-refresh is desired
75
*/
86
export default function useAutoRefresh(refreshAction: () => Promise<void>, defaultTimeout: number | null, startImmediately = true) {
97
let refreshInterval: number | null = null;
10-
const timeout = ref(defaultTimeout);
8+
const timeout = { value: defaultTimeout };
119

1210
function stopTimer() {
1311
if (refreshInterval !== null) {
@@ -38,7 +36,7 @@ export default function useAutoRefresh(refreshAction: () => Promise<void>, defau
3836
* Updates the timeout interval between refreshes
3937
* @param updatedTimeout The new time between refreshes in ms or null if no auto-refresh is desired
4038
*/
41-
async function updateTimeout(updatedTimeout: number) {
39+
async function updateTimeout(updatedTimeout: number | null) {
4240
timeout.value = updatedTimeout;
4341
await executeAndResetTimer();
4442
}

0 commit comments

Comments
 (0)