yunohost-admin/app/src/views/tool/ToolLog.vue

135 lines
3.2 KiB
Vue
Raw Normal View History

2020-08-30 17:12:15 +02:00
<template>
<div class="tool-log">
<!-- INFO CARD -->
2020-09-25 09:20:58 +02:00
<b-card>
2020-08-30 17:12:15 +02:00
<template v-slot:header>
<h2><icon iname="info-circle" /> {{ description }}</h2>
</template>
<dl>
<dt v-t="'logs_path'" />
<dd>{{ log_path }}</dd>
<hr>
<template v-if="metadata.started_at">
<dt v-t="'logs_started_at'" />
<dd>{{ metadata.started_at | readableDate }}</dd>
<hr>
</template>
<template v-if="metadata.ended_at">
<dt v-t="'logs_ended_at'" />
<dd>{{ metadata.ended_at | readableDate }}</dd>
<hr>
</template>
<template v-if="metadata.error">
<dt v-t="'logs_ended_at'" />
<dd>{{ metadata.error }}</dd>
<hr>
</template>
</dl>
</b-card>
<b-alert v-if="metadata.error" variant="danger" show>
<icon iname="exclamation-circle" /> {{ $t('operation_failed_explanation') }}
</b-alert>
<!-- LOGS CARD -->
<b-card class="log">
<template v-slot:header>
<div class="d-sm-flex justify-content-sm-between">
<h2><icon iname="file-text" /> {{ metadata ? $t('logs') : log_path }}</h2>
<b-button @click="shareLogs">
<icon iname="cloud-upload" /> {{ $t('logs_share_with_yunopaste') }}
</b-button>
</div>
</template>
<b-button
v-if="moreLogsAvailable"
variant="info" class="w-100 rounded-0"
@click="fetchData"
>
<icon iname="plus" /> {{ $t('logs_more') }}
</b-button>
<pre><code v-html="logs" /></pre>
</b-card>
</div>
</template>
<script>
2020-10-12 17:36:47 +02:00
import api from '@/api'
import { objectToParams } from '@/helpers/commons'
2020-11-03 16:27:30 +01:00
import { readableDate } from '@/helpers/filters/date'
2020-08-30 17:12:15 +02:00
export default {
name: 'ToolLog',
props: {
name: {
type: String,
required: true
}
},
data () {
return {
// Log data
description: '',
log_path: '',
logs: '',
metadata: {},
// Logs line display
numberOfLines: 50,
moreLogsAvailable: false
}
},
filters: {
readableDate
},
methods: {
fetchData () {
2020-09-10 19:10:37 +02:00
const queryString = objectToParams({
2020-08-30 17:12:15 +02:00
path: this.name,
filter_irrelevant: '',
number: this.numberOfLines
2020-09-10 19:10:37 +02:00
})
2020-08-30 17:12:15 +02:00
2020-09-10 19:10:37 +02:00
api.get('logs/display?' + queryString).then(log => {
2020-08-30 17:12:15 +02:00
if (log.logs.length === this.numberOfLines) {
this.moreLogsAvailable = true
this.numberOfLines *= 10
} else {
this.moreLogsAvailable = false
}
this.description = log.description
this.log_path = log.log_path
this.metadata = log.metadata
const levels = ['ERROR', 'WARNING', 'SUCCESS', 'INFO']
this.logs = log.logs.map(line => {
for (const level of levels) {
if (line.includes(level + ' -')) {
return `<span class="alert-${level === 'ERROR' ? 'danger' : level.toLowerCase()}">${line}</span>`
}
}
return line
}).join('\n')
})
},
shareLogs () {
2020-09-25 09:20:58 +02:00
api.get(`/logs/display?path=${this.name}&share`).then(({ url }) => {
2020-08-30 17:12:15 +02:00
window.open(url, '_blank')
})
}
},
created () {
this.fetchData()
}
}
</script>