|
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: [number, string][] = [ |
| 9 | + [0, "Off"], |
| 10 | + [5000, "Every 5 seconds"], |
| 11 | + [15000, "Every 15 seconds"], |
| 12 | + [30000, "Every 30 seconds"], |
| 13 | + [60000, "Every 1 minute"], |
| 14 | + [600000, "Every 10 minute"], |
| 15 | + [1800000, "Every 30 minute"], |
| 16 | + [3600000, "Every 1 hour"], |
| 17 | +]; |
10 | 18 |
|
11 |
| -const emit = defineEmits<{ change: [newValue: number | null]; manualRefresh: [] }>(); |
| 19 | +function extracted() { |
| 20 | + const item = autoRefreshOptionsText.find((item) => item[0] === model.value); |
12 | 21 |
|
13 |
| -const autoRefresh = ref(props.initialTimeout != null); |
14 |
| -const refreshTimeout = ref(props.initialTimeout ?? 5); |
| 22 | + if (item) { |
| 23 | + return item[1]; |
| 24 | + } |
15 | 25 |
|
16 |
| -function toggleRefresh() { |
17 |
| - autoRefresh.value = !autoRefresh.value; |
18 |
| - updateTimeout(); |
| 26 | + return "Off"; |
19 | 27 | }
|
20 | 28 |
|
21 |
| -function updateTimeout() { |
22 |
| - validateTimeout(); |
23 |
| - emit("change", autoRefresh.value ? refreshTimeout.value * 1000 : null); |
24 |
| -} |
| 29 | +const selectValue = extracted(); |
| 30 | +
|
| 31 | +const selectedRefresh = ref<string>(selectValue); |
| 32 | +
|
| 33 | +watch(selectedRefresh, (newValue) => { |
| 34 | + const item = autoRefreshOptionsText.find((item) => item[1] === newValue); |
25 | 35 |
|
26 |
| -function validateTimeout() { |
27 |
| - refreshTimeout.value = Math.max(1, Math.min(600, refreshTimeout.value)); |
| 36 | + if (item) { |
| 37 | + if (item[0] === 0) { |
| 38 | + model.value = null; |
| 39 | + } else { |
| 40 | + model.value = item[0]; |
| 41 | + } |
| 42 | + } |
| 43 | +}); |
| 44 | +const showSpinning = ref(false); |
| 45 | +watch( |
| 46 | + () => props.isLoading, |
| 47 | + (newValue) => { |
| 48 | + if (newValue) { |
| 49 | + showSpinning.value = true; |
| 50 | + window.setTimeout(() => { |
| 51 | + showSpinning.value = false; |
| 52 | + }, 1000); |
| 53 | + } |
| 54 | + } |
| 55 | +); |
| 56 | +async function refresh() { |
| 57 | + await emit("manualRefresh"); |
28 | 58 | }
|
29 | 59 | </script>
|
30 | 60 |
|
31 | 61 | <template>
|
32 | 62 | <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" /> |
| 63 | + <button class="btn btn-sm" title="refresh" @click="refresh"><i class="fa fa-refresh" :class="{ spinning: showSpinning }" /> Refresh List</button> |
| 64 | + <div class="filter"> |
| 65 | + <div class="filter-label">Auto-Refresh:</div> |
| 66 | + <div class="filter-component"> |
| 67 | + <ListFilterSelector :items="autoRefreshOptionsText.map((i) => i[1])" v-model="selectedRefresh" item-name="result" :can-clear="false" :show-clear="false" :show-filter="false" /> |
| 68 | + </div> |
40 | 69 | </div>
|
41 |
| - <input type="number" v-model="refreshTimeout" min="1" max="600" v-on:change="updateTimeout" /> |
42 |
| - <span class="unit">s</span> |
43 | 70 | </div>
|
44 | 71 | </template>
|
45 | 72 |
|
46 | 73 | <style scoped>
|
47 | 74 | .refresh-config {
|
48 | 75 | display: flex;
|
49 | 76 | align-items: center;
|
50 |
| - gap: 0.5em; |
51 |
| -} |
52 |
| -
|
53 |
| -.refresh-config .unit { |
54 |
| - margin-left: -0.45em; |
| 77 | + gap: 1em; |
| 78 | + margin-bottom: 0.5em; |
55 | 79 | }
|
56 | 80 |
|
57 |
| -.refresh-config label { |
58 |
| - margin: 0; |
59 |
| -} |
60 |
| -
|
61 |
| -.refresh-config input { |
62 |
| - width: 3.5em; |
| 81 | +.filter { |
| 82 | + display: flex; |
| 83 | + align-items: center; |
63 | 84 | }
|
64 | 85 |
|
65 |
| -.refresh-config button { |
66 |
| - background: none; |
67 |
| - border: none; |
68 |
| - width: 2em; |
| 86 | +.filter-label { |
| 87 | + font-weight: bold; |
69 | 88 | }
|
70 | 89 |
|
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; |
| 90 | +@keyframes spin { |
| 91 | + from { |
| 92 | + transform: rotate(0deg); |
| 93 | + } |
| 94 | + to { |
| 95 | + transform: rotate(360deg); |
| 96 | + } |
75 | 97 | }
|
76 | 98 |
|
77 |
| -.refresh-config button:hover .fa { |
78 |
| - color: #00a3c4; |
79 |
| - transform: scale(1.1); |
| 99 | +.fa-refresh { |
| 100 | + display: inline-block; |
80 | 101 | }
|
81 | 102 |
|
82 |
| -.refresh-config button:active .fa { |
83 |
| - transform: rotate(25deg); |
84 |
| - text-shadow: #929e9e 0.25px 0.25px; |
| 103 | +/* You can add this class dynamically when needed */ |
| 104 | +.fa-refresh.spinning { |
| 105 | + animation: spin 1s linear infinite; |
85 | 106 | }
|
86 | 107 | </style>
|
0 commit comments