1
1
<script setup lang="ts">
2
2
import { Head , router , usePoll } from ' @inertiajs/vue3'
3
+ import Badge from ' primevue/badge'
3
4
import Button from ' primevue/button'
4
5
import Card from ' primevue/card'
6
+ import ScrollPanel from ' primevue/scrollpanel'
7
+ import ToggleSwitch from ' primevue/toggleswitch'
5
8
6
9
defineProps <{
7
10
correctValue: number
8
- caches: Array <{ name: string ; result: any }>
11
+ caches: Array <{ name: string ; result: any ; busId : string }>
9
12
state: { bus: boolean ; l2: boolean }
13
+ sentMessages: Array <any >
14
+ receivedMessages: Array <any >
10
15
}>()
11
16
12
17
usePoll (1500 , { async: true })
13
18
14
19
function setCacheValue(name : string , value : any ) {
15
- router .post (' /set' , { name , value })
20
+ router .post (' /set' , { name , value }, { preserveScroll: true })
21
+ }
22
+
23
+ function deleteCacheValue(name : string ) {
24
+ router .post (' /delete' , { name }, { preserveScroll: true })
25
+ }
26
+
27
+ const severities = [' secondary' , ' success' , ' info' , ' warn' , ' danger' , ' contrast' ]
28
+ function getCacheColor(name : string ) {
29
+ return severities [(name .at (- 1 ) as any ) % severities .length ]
16
30
}
17
31
</script >
18
32
@@ -25,27 +39,44 @@ function setCacheValue(name: string, value: any) {
25
39
<template #subtitle >Cache Coherence Simulator</template >
26
40
27
41
<template #content >
28
- <p class =" mt-4 text-sm" >
29
- Correct Value :
30
- {{ correctValue }}
31
- </p >
32
-
33
- <div class =" flex gap-4 mt-4" >
34
- <Button
35
- size =" small"
36
- @click =" router.post('/state', { bus: !state.bus })"
37
- :severity =" state.bus ? 'danger' : 'success'"
38
- >
39
- {{ state.bus ? 'Disable' : 'Enable' }} Bus
40
- </Button >
41
-
42
- <Button
43
- size =" small"
44
- @click =" router.post('/state', { l2: !state.l2 })"
45
- :severity =" state.l2 ? 'danger' : 'success'"
46
- >
47
- {{ state.l2 ? 'Disable' : 'Enable' }} L2
48
- </Button >
42
+ <div class =" grid grid-cols-[200px_200px] items-center gap-4 mt-4" >
43
+ <span >Correct Value :</span >
44
+ <span class =" font-semibold text-2xl" >
45
+ {{ correctValue }}
46
+ </span >
47
+ <div class =" flex items-center gap-2" >
48
+ <span >
49
+ <i
50
+ class =" pi"
51
+ :class =" {
52
+ 'text-green-500 pi-check-circle': state.bus,
53
+ 'text-red-500 pi-times-circle': !state.bus,
54
+ }"
55
+ />
56
+ </span >
57
+ <span >Bus is {{ state.bus ? 'enabled' : 'disabled' }}</span >
58
+ </div >
59
+ <ToggleSwitch
60
+ v-model =" state.bus"
61
+ @change =" router.post('/state', { bus: state.bus }, { preserveScroll: true })"
62
+ />
63
+
64
+ <div class =" flex items-center gap-2" >
65
+ <span >
66
+ <i
67
+ class =" pi"
68
+ :class =" {
69
+ 'text-green-500 pi-check-circle': state.l2,
70
+ 'text-red-500 pi-times-circle': !state.l2,
71
+ }"
72
+ />
73
+ </span >
74
+ <span >L2 is {{ state.l2 ? 'enabled' : 'disabled' }}</span >
75
+ </div >
76
+ <ToggleSwitch
77
+ v-model =" state.l2"
78
+ @change =" router.post('/state', { l2: state.l2 }, { preserveScroll: true })"
79
+ />
49
80
</div >
50
81
</template >
51
82
</Card >
@@ -55,24 +86,84 @@ function setCacheValue(name: string, value: any) {
55
86
<template #title >
56
87
<div class =" flex gap-4 items-center justify-between font-light" >
57
88
<span >Node {{ cache.name }}</span >
58
- <Button
59
- size =" small"
60
- variant =" outlined"
61
- severity =" info"
62
- icon =" pi pi-plus"
63
- @click =" setCacheValue(cache.name, cache.result + 1)"
64
- />
89
+ <div class =" flex gap-2" >
90
+ <Button
91
+ size =" small"
92
+ variant =" outlined"
93
+ severity =" info"
94
+ icon =" pi pi-plus"
95
+ @click =" setCacheValue(cache.name, cache.result + 1)"
96
+ />
97
+ <Button
98
+ size =" small"
99
+ variant =" outlined"
100
+ severity =" danger"
101
+ icon =" pi pi-trash"
102
+ @click =" deleteCacheValue(cache.name)"
103
+ />
104
+ </div >
65
105
</div >
66
106
</template >
67
107
<template #content >
68
108
<div >
69
109
Current Value :
70
110
<span class =" text-lg font-semibold" >{{ cache.result }}</span >
71
111
</div >
72
-
73
112
<div class =" flex gap-2 mt-2" ></div >
74
113
</template >
75
114
</Card >
76
115
</div >
116
+
117
+ <Card class =" mt-4" >
118
+ <template #title >Bus logs</template >
119
+
120
+ <template #content >
121
+ <div class =" grid grid-cols-2 gap-2" >
122
+ <div >
123
+ <p >Sent messages</p >
124
+ <ScrollPanel style =" width : 100% ; height : 300px " >
125
+ <div class =" p-2 grid gap-2" >
126
+ <div v-for =" (log, idx) in sentMessages" :key =" idx" class =" flex items-center gap-2" >
127
+ <Badge size =" small" :severity =" getCacheColor(log.cacheName)" >
128
+ {{ log.cacheName }}
129
+ </Badge >
130
+
131
+ <Badge size =" small" :severity =" log.message.type === 'set' ? 'info' : 'danger'" >
132
+ {{ log.message.type }}
133
+ </Badge >
134
+
135
+ <span >{{ new Date(log.timestamp).toLocaleTimeString() }}</span >
136
+ <span class =" text-xs text-[var(--p-slate-300)]" >{{ log.message }}</span >
137
+ </div >
138
+ </div >
139
+ </ScrollPanel >
140
+ </div >
141
+
142
+ <div >
143
+ <p >Received messages</p >
144
+ <ScrollPanel style =" width : 100% ; height : 300px " >
145
+ <div class =" p-2 grid gap-2" >
146
+ <div
147
+ v-for =" (log, idx) in receivedMessages"
148
+ :key =" idx"
149
+ class =" flex items-center gap-2"
150
+ >
151
+ <Badge size =" small" :severity =" getCacheColor(log.cacheName)" >
152
+ {{ log.cacheName }}
153
+ </Badge >
154
+
155
+ <Badge size =" small" :severity =" log.message.type === 'set' ? 'info' : 'danger'" >
156
+ {{ log.message.type }}
157
+ </Badge >
158
+
159
+ <span >{{ new Date(log.timestamp).toLocaleTimeString() }}</span >
160
+ <span class =" text-xs text-[var(--p-slate-300)]" >{{ log.message }}</span >
161
+ </div >
162
+ </div >
163
+ </ScrollPanel >
164
+ </div >
165
+ </div >
166
+ </template >
167
+ </Card >
77
168
</div >
78
169
</template >
0 commit comments