upend/ui/src/components/Jobs.vue

72 lines
1.3 KiB
Vue
Raw Normal View History

<template>
<transition-group name="fade">
<div class="job" v-for="job in activeJobs" :key="job.id">
<div class="job-label">{{ job.title }}</div>
2021-03-24 21:03:10 +01:00
<sl-progress-bar :percentage="job.progress"
>{{ Math.round(job.progress) }}%</sl-progress-bar
>
</div>
</transition-group>
</template>
<script lang="ts">
2021-03-24 21:03:10 +01:00
import { Job } from "@/types/base";
import { defineComponent } from "vue";
interface JobWithId extends Job {
id: string;
}
export default defineComponent({
name: "Jobs",
data: () => {
return {
2021-03-24 21:03:10 +01:00
jobs: {} as { [key: string]: Job },
};
},
computed: {
activeJobs(): JobWithId[] {
2021-03-24 21:03:10 +01:00
return Object.entries(this.jobs)
.filter(([_, job]) => job.state == "InProgress")
2021-03-24 21:03:10 +01:00
.map(([id, job]) => {
return { id, ...job };
});
},
},
mounted() {
setInterval(async () => {
let request = await fetch("/api/jobs");
this.jobs = await request.json();
2021-02-21 12:30:41 +01:00
}, 3333);
2021-03-24 21:03:10 +01:00
},
});
</script>
<style scoped lang="scss">
.job {
display: flex;
.job-label {
white-space: nowrap;
margin-right: 2em;
}
sl-progress-bar {
width: 100%;
}
}
</style>
<style lang="scss">
.fade-enter-active,
.fade-leave-active {
transition: all 1s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: translateY(30px);
}
</style>