2525// POSSIBILITY OF SUCH DAMAGE.
2626
2727import { onMounted , onUnmounted } from ' vue'
28+ import { watch } from ' vue'
2829
2930import { storeToRefs } from ' pinia'
3031import { useNodesStore } from ' @/stores/nodes.store.js'
@@ -40,8 +41,54 @@ const { alert } = storeToRefs(alertStore)
4041const authStore = useAuthStore ()
4142
4243const nodesStore = useNodesStore ()
43- const { nodes , nodesU } = storeToRefs (nodesStore)
44- nodesStore .getAll ()
44+
45+ let isUpdating = false
46+
47+ const updatePeriodically = async () => {
48+ if (isUpdating) {
49+ return ;
50+ }
51+
52+ isUpdating = true
53+
54+ try {
55+ await nodesStore .fetchFrame ({
56+ page: authStore .nodesPage ,
57+ itemsPerPage: nodesStore .nodesPerPage ,
58+ sortBy: nodesStore .nodesSortBy ,
59+ search: nodesStore .nodesSearch ,
60+ });
61+
62+ }
63+ catch (error) {
64+ alertStore .error (' Fatal error when updating node list: ' + error .message )
65+ }
66+ finally {
67+ isUpdating = false ;
68+ }
69+ };
70+
71+ watch (
72+ () => [
73+ nodesStore .nodesPage ,
74+ nodesStore .nodesPerPage ,
75+ nodesStore .nodesSortBy ,
76+ nodesStore .nodesSearch ,
77+ ],
78+ () => { updatePeriodically (); },
79+ { immediate: true }
80+ );
81+
82+ let intervalId = null
83+
84+ onMounted (() => {
85+ intervalId = setInterval (updatePeriodically, 5000 );
86+ });
87+
88+ onUnmounted (() => {
89+ clearInterval (intervalId);
90+ });
91+
4592
4693import { useConfirm } from ' vuetify-use-dialog'
4794const confirm = useConfirm ()
@@ -77,104 +124,21 @@ async function resetNode(item) {
77124 nodesStore
78125 .reset (item .id )
79126 .then (() => {
80- updateDataGrid ()
127+ updatePeriodically ()
81128 })
82129 .catch ((error ) => {
83130 alertStore .error (error)
84131 })
85132 }
86133}
87134
88-
89- function filterNodes (value , query , item ) {
90- if (query == null || item == null ) {
91- return false
92- }
93-
94- const i = item .raw
95- if (i == null ) {
96- return false
97- }
98-
99- const q = query .toLocaleUpperCase ()
100-
101- if (
102- i .id .toString ().indexOf (q) !== - 1 ||
103- i .name .toLocaleUpperCase ().indexOf (q) !== - 1 ||
104- i .public_key .toLocaleUpperCase ().indexOf (q) !== - 1 ||
105- (i .round_id != null && i .round_id .toString ().indexOf (q) !== - 1 )
106- ) {
107- return true
108- }
109-
110- return false
111- }
112-
113135function formatRound (roundId ) {
114136 if (roundId == null ) {
115137 return ' --'
116138 }
117139 return roundId .toString ()
118140}
119141
120- let isUpdating = false
121-
122- const updateDataGrid = async () => {
123- if (isUpdating) {
124- return
125- }
126-
127- isUpdating = true
128- try {
129- await nodesStore .getAllU ()
130- if (! nodesU? .loading && ! nodesU? .loading )
131- {
132- const oldData = [... nodes .value ]
133- const newItems = []
134-
135- for (const newItem of nodesU .value ) {
136- const oldItem = nodes .value .find (item => item .id === newItem .id )
137- if (oldItem) {
138- if (JSON .stringify (oldItem) !== JSON .stringify (newItem)) {
139- Object .assign (oldItem, newItem)
140- }
141- }
142- else {
143- newItems .push (newItem)
144- }
145- }
146- nodes .value .unshift (... newItems)
147-
148- for (const oldItem of oldData) {
149- const newItem = nodesU .value .find (item => item .id === oldItem .id )
150- if (! newItem) {
151- const index = nodes .value .indexOf (oldItem)
152- nodes .value .splice (index, 1 )
153- }
154- }
155- }
156- }
157- catch {
158- alertStore .error (' Failed to update nodes list' )
159- }
160- finally {
161- isUpdating = false
162- }
163- }
164-
165- let intervalId = null
166-
167- onMounted (() => {
168- intervalId = setInterval (() => {
169- updateDataGrid ()
170- }, 10000 )
171- })
172-
173- onUnmounted (() => {
174- if (intervalId) {
175- clearInterval (intervalId)
176- }
177- })
178142
179143 </script >
180144
@@ -184,20 +148,20 @@ onUnmounted(() => {
184148 <hr class =" hr" />
185149
186150 <v-card >
187- < v- data- table
188- v- if = " nodes?.length"
189- v- model: items- per- page= " authStore.nodes_per_page"
151+ <v-data-table-server
152+ v-model:items-per-page =" nodesStore.nodesPerPage"
190153 items-per-page-text =" Nodes per page"
191154 page-text =" {0}-{1} of {2}"
192- v - model : page= " authStore.nodes_page "
155+ :page =" nodesStore.nodesPage "
193156 :items-per-page-options =" itemsPerPageOptions"
194157 :headers =" headers"
195- : items= " nodes "
196- : search = " authStore.nodes_search "
197- v - model : sort - by = " authStore.nodes_sort_by "
198- : custom - filter = " filterNodes "
158+ :items =" nodesStore.nodesF "
159+ :itemsLength = " nodesStore.totalNodes "
160+ :search = " nodesStore.nodesSearch "
161+ v-model:sort-by = " nodesStore.nodesSortBy "
199162 item-value =" id"
200163 class =" elevation-1"
164+ @update:options =" nodesStore.fetchNodes"
201165 >
202166 <template v-slot :[` item.roundId ` ]=" { item } " >
203167 {{ formatRound(item['roundId']) }}
@@ -210,23 +174,23 @@ onUnmounted(() => {
210174 <v-tooltip activator =" parent" >Reset</v-tooltip >
211175
212176 </template >
213- < / v- data- table>
177+ </v-data-table-server >
214178 <v-spacer ></v-spacer >
215- < div v- if = " !nodes ?.length" class = " text-center m-5" > No nodes< / div>
216- < div v- if = " nodes?.length " >
179+ <div v-if =" !nodesStore.nodesF ?.length" class =" text-center m-5" >No nodes</div >
180+ <div v-if =" nodesStore.totalNodes " >
217181 <v-text-field
218- v- model= " authStore.nodes_search "
182+ v-model =" nodesStore.nodesSearch "
219183 :append-inner-icon =" mdiMagnify"
220184 label =" Search any node information"
221185 variant =" solo"
222186 hide-details
223187 />
224188 </div >
225189 </v-card >
226- < div v- if = " nodes ?.error" class = " text-center m-5" >
227- < div class = " text-danger" > Failed to load nodes list: {{ nodes .error }}< / div>
190+ <div v-if =" nodesStore.nodesF ?.error" class =" text-center m-5" >
191+ <div class =" text-danger" >Failed to load nodes list: {{ nodesF .error }}</div >
228192 </div >
229- < div v- if = " nodes ?.loading" class = " text-center m-5" >
193+ <div v-if =" nodesStore.nodesF ?.loading" class =" text-center m-5" >
230194 <span class =" spinner-border spinner-border-lg align-center" ></span >
231195 </div >
232196 <div v-if =" alert" class =" alert alert-dismissable mt-3 mb-0" :class =" alert.type" >
0 commit comments