797797<script setup lang="js">
798798import { ref , watch } from ' vue'
799799import { useRuntimeConfig } from ' #imports'
800+ import { getItemWithExpiry } from ' @/lib/encrypter'
800801
801802const props = defineProps ({
802803 gpuData: {
@@ -813,6 +814,17 @@ const props = defineProps({
813814 }
814815})
815816
817+ const emit = defineEmits ([' data-refreshed' ])
818+
819+ // Helper function to get the authentication token
820+ const getAuthToken = () => {
821+ const token = getItemWithExpiry (' encryptedJWTPDB' )
822+ if (! token) {
823+ console .warn (' [GpuForm] No authentication token found. User may need to log in again.' )
824+ }
825+ return token || null
826+ }
827+
816828const successMessage = ref (' ' )
817829const errorMessage = ref (' ' )
818830const isProcessorsExpanded = ref (true )
@@ -1099,7 +1111,13 @@ const redirectPage = (data) => {
10991111
11001112// Cores functionality
11011113const cores = computed(() => {
1102- return props.gpuData?.cores || []
1114+ const coresData = props.gpuData?.cores || []
1115+ // #region agent log
1116+ if (typeof fetch !== 'undefined') {
1117+ fetch('http://127.0.0.1:7242/ingest/a2e5b876-28c3-4b64-9549-c4e9792dd0b0',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'GpuForm.vue:1101',message:'Cores computed',data:{hasGpuData:!!props.gpuData,coresCount:coresData.length,coresIsArray:Array.isArray(coresData),coresData:coresData},timestamp:Date.now(),sessionId:'debug-session',runId:'run1',hypothesisId:'F'})}).catch(()=>{});
1118+ }
1119+ // #endregion
1120+ return coresData
11031121})
11041122
11051123const showAddCoreForm = ref(false)
@@ -1163,7 +1181,7 @@ const submitCore = async () => {
11631181 method,
11641182 headers: {
11651183 'Content-Type': 'application/json',
1166- 'Authorization': ` Bearer ${localStorage . getItem ( ' token ' )}`
1184+ 'Authorization': ` Bearer ${getAuthToken ( )}`
11671185 },
11681186 body: JSON.stringify({
11691187 core_name: coreForm.value.core_name,
@@ -1176,10 +1194,11 @@ const submitCore = async () => {
11761194 if (response.ok) {
11771195 successMessage.value = ` Core ${editingCore .value ? ' updated' : ' added' } successfully! `
11781196 cancelCoreForm()
1179- // Refresh page to reload cores
11801197 setTimeout(() => {
1181- window.location.reload()
1182- }, 1000)
1198+ successMessage.value = ''
1199+ }, 3000)
1200+ // Emit event to refresh data without page reload
1201+ emit('data-refreshed')
11831202 } else {
11841203 const errorData = await response.json()
11851204 errorMessage.value = errorData.error || 'Failed to save core'
@@ -1203,16 +1222,17 @@ const deleteCore = async (coreId) => {
12031222 const response = await fetch(` ${useRuntimeConfig ().public .backendUrl }/ gpus/ ${gpuId}/ cores/ ${coreId}` , {
12041223 method: 'DELETE',
12051224 headers: {
1206- 'Authorization': ` Bearer ${localStorage . getItem ( ' token ' )}`
1225+ 'Authorization': ` Bearer ${getAuthToken ( )}`
12071226 }
12081227 })
12091228
12101229 if (response.ok) {
12111230 successMessage.value = 'Core deleted successfully!'
1212- // Refresh page to reload cores
12131231 setTimeout(() => {
1214- window.location.reload()
1215- }, 1000)
1232+ successMessage.value = ''
1233+ }, 3000)
1234+ // Emit event to refresh data without page reload
1235+ emit('data-refreshed')
12161236 } else {
12171237 const errorData = await response.json()
12181238 errorMessage.value = errorData.error || 'Failed to delete core'
0 commit comments