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>
|
|
|
|
|
2020-11-03 19:10:30 +01:00
|
|
|
<b-row
|
|
|
|
v-for="(value, prop) in info" :key="prop"
|
|
|
|
no-gutters class="row-line"
|
|
|
|
>
|
2020-11-25 16:20:59 +01:00
|
|
|
<b-col cols="auto" md="3">
|
2020-11-03 19:10:30 +01:00
|
|
|
<strong>{{ $t('logs_' + prop) }}</strong>
|
|
|
|
</b-col>
|
|
|
|
<b-col>
|
|
|
|
<span v-if="prop.endsWith('_at')">{{ value | readableDate }}</span>
|
|
|
|
<div v-else-if="prop === 'suboperations'">
|
|
|
|
<div v-for="operation in value" :key="operation.name">
|
|
|
|
<icon v-if="!operation.success" iname="times" class="text-danger" />
|
|
|
|
<b-link :to="{ name: 'tool-log', params: { name: operation.name } }">
|
|
|
|
{{ operation.description }}
|
|
|
|
</b-link>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<span v-else>{{ value }}</span>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
2020-08-30 17:12:15 +02:00
|
|
|
</b-card>
|
|
|
|
|
2020-11-03 19:10:30 +01:00
|
|
|
<b-alert
|
|
|
|
v-if="info.error" variant="danger" show
|
|
|
|
class="my-5"
|
|
|
|
>
|
|
|
|
<icon iname="exclamation-circle" /> <span v-html="$t('operation_failed_explanation')" />
|
2020-08-30 17:12:15 +02:00
|
|
|
</b-alert>
|
|
|
|
|
|
|
|
<!-- LOGS CARD -->
|
|
|
|
<b-card class="log">
|
|
|
|
<template v-slot:header>
|
|
|
|
<div class="d-sm-flex justify-content-sm-between">
|
2020-11-03 19:10:30 +01:00
|
|
|
<h2><icon iname="file-text" /> {{ $t('logs') }}</h2>
|
2020-11-25 16:20:59 +01:00
|
|
|
<b-button @click="shareLogs" variant="success">
|
2020-08-30 17:12:15 +02:00
|
|
|
<icon iname="cloud-upload" /> {{ $t('logs_share_with_yunopaste') }}
|
|
|
|
</b-button>
|
|
|
|
</div>
|
|
|
|
</template>
|
2020-11-25 16:20:59 +01:00
|
|
|
|
2020-08-30 17:12:15 +02:00
|
|
|
<b-button
|
|
|
|
v-if="moreLogsAvailable"
|
2020-11-25 16:20:59 +01:00
|
|
|
variant="white" class="w-100 rounded-0"
|
2020-08-30 17:12:15 +02:00
|
|
|
@click="fetchData"
|
|
|
|
>
|
|
|
|
<icon iname="plus" /> {{ $t('logs_more') }}
|
|
|
|
</b-button>
|
2020-11-25 16:20:59 +01:00
|
|
|
|
2020-08-30 17:12:15 +02:00
|
|
|
<pre><code v-html="logs" /></pre>
|
2020-11-25 16:20:59 +01:00
|
|
|
|
|
|
|
<b-button @click="shareLogs" variant="success" class="w-100 rounded-0">
|
|
|
|
<icon iname="cloud-upload" /> {{ $t('logs_share_with_yunopaste') }}
|
|
|
|
</b-button>
|
2020-08-30 17:12:15 +02:00
|
|
|
</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: '',
|
2020-11-03 19:10:30 +01:00
|
|
|
info: {},
|
2020-08-30 17:12:15 +02:00
|
|
|
logs: '',
|
|
|
|
// Logs line display
|
2020-11-03 19:10:30 +01:00
|
|
|
numberOfLines: 25,
|
2020-08-30 17:12:15 +02:00
|
|
|
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: '',
|
2020-11-03 19:10:30 +01:00
|
|
|
with_suboperations: '',
|
2020-08-30 17:12:15 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
const levels = ['ERROR', 'WARNING', 'SUCCESS', 'INFO']
|
|
|
|
this.logs = log.logs.map(line => {
|
|
|
|
for (const level of levels) {
|
|
|
|
if (line.includes(level + ' -')) {
|
2020-11-03 19:10:30 +01:00
|
|
|
return `<span class="alert-${level === 'ERROR'
|
|
|
|
? 'danger'
|
|
|
|
: level.toLowerCase()}">${line}</span>`
|
2020-08-30 17:12:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return line
|
|
|
|
}).join('\n')
|
2020-11-03 19:10:30 +01:00
|
|
|
|
|
|
|
const { started_at, ended_at, error, success, suboperations } = log.metadata
|
|
|
|
const info = { path: log.log_path, started_at, ended_at }
|
|
|
|
if (!success) info.error = error
|
|
|
|
if (suboperations) info.suboperations = suboperations
|
|
|
|
this.info = info
|
2020-08-30 17:12:15 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
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>
|