|
1 | 1 | <script setup lang="ts">
|
2 |
| -import { ref } from "vue"; |
3 |
| -import OnOffSwitch from "./OnOffSwitch.vue"; |
| 2 | +import { ref, watch } from "vue"; |
| 3 | +import ListFilterSelector from "@/components/audit/ListFilterSelector.vue"; |
4 | 4 |
|
5 |
| -const props = defineProps<{ |
6 |
| - id: string; |
7 |
| - initialTimeout?: number; |
8 |
| - onManualRefresh: () => void; |
9 |
| -}>(); |
| 5 | +const props = defineProps<{ isLoading: boolean }>(); |
| 6 | +const model = defineModel<number | null>({ required: true }); |
| 7 | +const emit = defineEmits<{ (e: "manualRefresh"): Promise<void> }>(); |
| 8 | +const autoRefreshOptionsText = ["Off", "Every 5 seconds", "Every 15 seconds", "Every 30 seconds"]; |
| 9 | +let selectValue = "Off"; |
10 | 10 |
|
11 |
| -const emit = defineEmits<{ change: [newValue: number | null]; manualRefresh: [] }>(); |
12 |
| -
|
13 |
| -const autoRefresh = ref(props.initialTimeout != null); |
14 |
| -const refreshTimeout = ref(props.initialTimeout ?? 5); |
15 |
| -
|
16 |
| -function toggleRefresh() { |
17 |
| - autoRefresh.value = !autoRefresh.value; |
18 |
| - updateTimeout(); |
| 11 | +if (model.value === 5000) { |
| 12 | + selectValue = "Every 5 seconds"; |
19 | 13 | }
|
20 |
| -
|
21 |
| -function updateTimeout() { |
22 |
| - validateTimeout(); |
23 |
| - emit("change", autoRefresh.value ? refreshTimeout.value * 1000 : null); |
| 14 | +if (model.value === 15000) { |
| 15 | + selectValue = "Every 15 seconds"; |
24 | 16 | }
|
| 17 | +if (model.value === 30000) { |
| 18 | + selectValue = "Every 30 seconds"; |
| 19 | +} |
| 20 | +
|
| 21 | +const selectedRefresh = ref<string>(selectValue); |
| 22 | +
|
| 23 | +watch(selectedRefresh, (newValue) => { |
| 24 | + if (newValue === autoRefreshOptionsText[0]) { |
| 25 | + model.value = null; |
| 26 | + } |
| 27 | + if (newValue === autoRefreshOptionsText[1]) { |
| 28 | + model.value = 5000; |
| 29 | + } |
| 30 | + if (newValue === autoRefreshOptionsText[2]) { |
| 31 | + model.value = 15000; |
| 32 | + } |
| 33 | + if (newValue === autoRefreshOptionsText[3]) { |
| 34 | + model.value = 30000; |
| 35 | + } |
| 36 | +}); |
25 | 37 |
|
26 |
| -function validateTimeout() { |
27 |
| - refreshTimeout.value = Math.max(1, Math.min(600, refreshTimeout.value)); |
| 38 | +async function refresh() { |
| 39 | + await emit("manualRefresh"); |
28 | 40 | }
|
29 | 41 | </script>
|
30 | 42 |
|
31 | 43 | <template>
|
32 | 44 | <div class="refresh-config">
|
33 |
| - <button class="fa" title="refresh" @click="() => emit('manualRefresh')"> |
34 |
| - <i class="fa fa-lg fa-refresh" /> |
35 |
| - </button> |
36 |
| - <span>|</span> |
37 |
| - <label>Auto-Refresh:</label> |
38 |
| - <div> |
39 |
| - <OnOffSwitch :id="id" @toggle="toggleRefresh" :value="autoRefresh" /> |
| 45 | + <button class="btn btn-sm" title="refresh" @click="refresh"><i class="fa fa-refresh" :class="{ spinning: props.isLoading }" /> Refresh List</button> |
| 46 | + <div class="filter"> |
| 47 | + <div class="filter-label">Auto-Refresh:</div> |
| 48 | + <div class="filter-component"> |
| 49 | + <ListFilterSelector :items="autoRefreshOptionsText" v-model="selectedRefresh" item-name="result" :can-clear="false" :show-clear="false" :show-filter="false" /> |
| 50 | + </div> |
40 | 51 | </div>
|
41 |
| - <input type="number" v-model="refreshTimeout" min="1" max="600" v-on:change="updateTimeout" /> |
42 |
| - <span class="unit">s</span> |
43 | 52 | </div>
|
44 | 53 | </template>
|
45 | 54 |
|
46 | 55 | <style scoped>
|
47 | 56 | .refresh-config {
|
48 | 57 | display: flex;
|
49 | 58 | align-items: center;
|
50 |
| - gap: 0.5em; |
| 59 | + gap: 1em; |
| 60 | + margin-bottom: 0.5em; |
51 | 61 | }
|
52 | 62 |
|
53 |
| -.refresh-config .unit { |
54 |
| - margin-left: -0.45em; |
55 |
| -} |
56 |
| -
|
57 |
| -.refresh-config label { |
58 |
| - margin: 0; |
59 |
| -} |
60 |
| -
|
61 |
| -.refresh-config input { |
62 |
| - width: 3.5em; |
| 63 | +.filter { |
| 64 | + display: flex; |
| 65 | + align-items: center; |
63 | 66 | }
|
64 | 67 |
|
65 |
| -.refresh-config button { |
66 |
| - background: none; |
67 |
| - border: none; |
68 |
| - width: 2em; |
| 68 | +.filter-label { |
| 69 | + font-weight: bold; |
69 | 70 | }
|
70 | 71 |
|
71 |
| -.refresh-config button .fa { |
72 |
| - transition: all 0.15s ease-in-out; |
73 |
| - transition: rotate 0.05s ease-in-out; |
74 |
| - transform-origin: center; |
| 72 | +@keyframes spin { |
| 73 | + from { |
| 74 | + transform: rotate(0deg); |
| 75 | + } |
| 76 | + to { |
| 77 | + transform: rotate(360deg); |
| 78 | + } |
75 | 79 | }
|
76 | 80 |
|
77 |
| -.refresh-config button:hover .fa { |
78 |
| - color: #00a3c4; |
79 |
| - transform: scale(1.1); |
| 81 | +.fa-refresh { |
| 82 | + display: inline-block; |
80 | 83 | }
|
81 | 84 |
|
82 |
| -.refresh-config button:active .fa { |
83 |
| - transform: rotate(25deg); |
84 |
| - text-shadow: #929e9e 0.25px 0.25px; |
| 85 | +/* You can add this class dynamically when needed */ |
| 86 | +.fa-refresh.spinning { |
| 87 | + animation: spin 1s linear infinite; |
85 | 88 | }
|
86 | 89 | </style>
|
0 commit comments