mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
refactor: rework async ToolLogs
This commit is contained in:
parent
27f87eeb17
commit
68e6c78c22
2 changed files with 30 additions and 34 deletions
|
@ -244,6 +244,17 @@ export type Firewall = {
|
||||||
|
|
||||||
// LOGS
|
// LOGS
|
||||||
|
|
||||||
|
export type LogList = {
|
||||||
|
operation: {
|
||||||
|
name: string
|
||||||
|
path: string
|
||||||
|
description: string
|
||||||
|
started_at: string
|
||||||
|
success: boolean | '?'
|
||||||
|
parent: string | null
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
export type LogInfo = {
|
export type LogInfo = {
|
||||||
description: string
|
description: string
|
||||||
name: string
|
name: string
|
||||||
|
|
|
@ -1,56 +1,41 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import api from '@/api'
|
||||||
|
|
||||||
import { useInitialQueries } from '@/composables/useInitialQueries'
|
|
||||||
import { useSearch } from '@/composables/useSearch'
|
import { useSearch } from '@/composables/useSearch'
|
||||||
import { distanceToNow, readableDate } from '@/helpers/filters/date'
|
import { distanceToNow, readableDate } from '@/helpers/filters/date'
|
||||||
import type { Obj } from '@/types/commons'
|
import type { Obj } from '@/types/commons'
|
||||||
|
import type { LogList } from '@/types/core/api'
|
||||||
|
|
||||||
const { loading } = useInitialQueries(
|
const operations = await api
|
||||||
[{ uri: `logs?limit=${25}&with_details` }],
|
.fetch<LogList>({ uri: `logs?limit=${25}&with_details` })
|
||||||
{ onQueriesResponse },
|
.then((logs) => {
|
||||||
)
|
const iconAndClass = {
|
||||||
|
'?': { icon: 'question', class: 'text-warning' },
|
||||||
|
true: { icon: 'check', class: 'text-success' },
|
||||||
|
false: { icon: 'close', class: 'text-danger' },
|
||||||
|
} as Obj<{ icon: string; class: string }>
|
||||||
|
return logs.operation.map((log) => ({
|
||||||
|
...log,
|
||||||
|
...iconAndClass[String(log.success) as keyof typeof iconAndClass],
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
const operations = ref<Obj[] | undefined>()
|
|
||||||
const [search, filteredOperations] = useSearch(operations, (s, op) => {
|
const [search, filteredOperations] = useSearch(operations, (s, op) => {
|
||||||
return op.description.toLowerCase().includes(s)
|
return op.description.toLowerCase().includes(s)
|
||||||
})
|
})
|
||||||
|
|
||||||
function onQueriesResponse({ operation }: any) {
|
|
||||||
operation.forEach((log, index) => {
|
|
||||||
if (log.success === '?') {
|
|
||||||
operation[index].icon = 'question'
|
|
||||||
operation[index].class = 'warning'
|
|
||||||
} else if (log.success) {
|
|
||||||
operation[index].icon = 'check'
|
|
||||||
operation[index].class = 'success'
|
|
||||||
} else {
|
|
||||||
operation[index].icon = 'close'
|
|
||||||
operation[index].class = 'danger'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
operations.value = operation
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ViewSearch
|
<ViewSearch v-model="search" :items="filteredOperations" items-name="logs">
|
||||||
v-model="search"
|
|
||||||
:items="filteredOperations"
|
|
||||||
items-name="logs"
|
|
||||||
:loading="loading"
|
|
||||||
skeleton="CardListSkeleton"
|
|
||||||
>
|
|
||||||
<YCard :title="$t('logs_operation')" icon="wrench" no-body>
|
<YCard :title="$t('logs_operation')" icon="wrench" no-body>
|
||||||
<BListGroup flush>
|
<BListGroup flush>
|
||||||
<BListGroupItem
|
<BListGroupItem
|
||||||
v-for="log in filteredOperations"
|
v-for="log in filteredOperations"
|
||||||
:key="log.name"
|
:key="log.name"
|
||||||
:to="{ name: 'tool-log', params: { name: log.name || log.log_path } }"
|
:to="{ name: 'tool-log', params: { name: log.name || log.path } }"
|
||||||
:title="readableDate(log.started_at)"
|
:title="readableDate(log.started_at)"
|
||||||
>
|
>
|
||||||
<small class="me-3">{{ distanceToNow(log.started_at) }} </small>
|
<small class="me-3">{{ distanceToNow(log.started_at) }}</small>
|
||||||
<YIcon :iname="log.icon" :class="'text-' + log.class" />
|
<YIcon :iname="log.icon" :class="log.class" />
|
||||||
{{ log.description }}
|
{{ log.description }}
|
||||||
</BListGroupItem>
|
</BListGroupItem>
|
||||||
</BListGroup>
|
</BListGroup>
|
||||||
|
|
Loading…
Reference in a new issue