algo/app/static/status-running.vue
2022-09-16 02:11:28 +05:00

72 lines
1.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<section class="text-center">
<p>Set up usually takes 5-15 minutes</p>
<p>You can close tab and open it again</p>
<p>You can try to
<button type="button" class="btn btn-link stop-button" v-on:click="$emit('submit')">STOP</button>
setup and run it again
</p>
<p>Dont close terminal!</p>
<transition-group name="console" tag="div">
<code class="console-item" v-for="(event, i) in last_n_events" v-bind:key="event.counter">{{ event.stdout }}</code>
</transition-group>
</section>
</template>
<script>
module.exports = {
data: function () {
return {
events: []
}
},
computed: {
last_n_events() {
return this.events.filter(ev => (ev.stdout)).slice(-6);
}
},
created() {
const loop = () => {
this.check()
.then(() => {
setTimeout(loop, 5000);
});
};
setTimeout(loop, 5000);
},
methods: {
check: function () {
return fetch("/playbook")
.then(r => r.json())
.catch(() => {
this.$emit('error');
})
.then(data => {
this.events = data.events;
if (data.status && data.status === 'successful') {
this.$emit('successful');
throw new Error();
}
if (data.status && data.status === 'failed') {
this.$emit('error');
throw new Error();
}
if (!data.status || data.status === 'cancelled') {
this.$emit('cancelled');
throw new Error();
}
});
}
}
}
</script>
<style scoped>
code {
display: block;
text-align: left;
}
.stop-button {
color: red;
text-decoration: underline;
}
</style>