Skip to content

Commit f5c5937

Browse files
config-dev-view: Allow user to download system logs
1 parent 417fcdd commit f5c5937

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/views/ConfigurationDevelopmentView.vue

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,63 @@
1313
step="1"
1414
thumb-label="always"
1515
/>
16+
<v-data-table :items="systemLogsData" :headers="headers" class="max-w-[80%] max-h-[60%]">
17+
<template #item.actions="{ item }">
18+
<div class="text-center cursor-pointer icon-btn mdi mdi-download" @click="downloadLog(item.name)" />
19+
</template>
20+
</v-data-table>
1621
</template>
1722
</BaseConfigurationView>
1823
</template>
1924

2025
<script setup lang="ts">
26+
// @ts-nocheck
27+
// TODO: As of now Vuetify does not export the necessary types for VDataTable, so we can't fix the type error.
28+
29+
import { saveAs } from 'file-saver'
30+
import { onBeforeMount } from 'vue'
31+
import { ref } from 'vue'
32+
33+
import { type SystemLog, cockpitSytemLogsDB } from '@/libs/system-logging'
2134
import { useDevelopmentStore } from '@/stores/development'
2235
2336
import BaseConfigurationView from './BaseConfigurationView.vue'
24-
2537
const devStore = useDevelopmentStore()
38+
39+
/* eslint-disable jsdoc/require-jsdoc */
40+
interface SystemLogsData {
41+
name: string
42+
initialTime: string
43+
initialDate: string
44+
nEvents: number
45+
}
46+
/* eslint-enable jsdoc/require-jsdoc */
47+
48+
const systemLogsData = ref<SystemLogsData[]>([])
49+
50+
const headers = [
51+
{ title: 'Name', value: 'name' },
52+
{ title: 'Time (initial)', value: 'initialTime' },
53+
{ title: 'Date (initial)', value: 'initialDate' },
54+
{ title: 'N. events', value: 'nEvents' },
55+
{ title: 'Download', value: 'actions' },
56+
]
57+
58+
onBeforeMount(async () => {
59+
await cockpitSytemLogsDB.iterate((log: SystemLog, logName) => {
60+
systemLogsData.value.push({
61+
name: logName,
62+
initialTime: log.initialTime,
63+
initialDate: log.initialDate,
64+
nEvents: log.events.length,
65+
})
66+
})
67+
})
68+
69+
const downloadLog = async (logName: string): Promise<void> => {
70+
const log = await cockpitSytemLogsDB.getItem(logName)
71+
const logParts = JSON.stringify(log, null, 2)
72+
const logBlob = new Blob([logParts], { type: 'application/json' })
73+
saveAs(logBlob, logName)
74+
}
2675
</script>

0 commit comments

Comments
 (0)