2024-11-02 18:41:13 +00:00
|
|
|
<template>
|
2024-11-04 16:31:04 +00:00
|
|
|
<Loading :loading="loading" :message="error" type="danger">
|
2024-11-03 21:57:12 +00:00
|
|
|
<div class="block">
|
|
|
|
<router-link class="button" to="/new">
|
|
|
|
<Icon name="plus">New container</Icon>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
2024-11-04 15:55:23 +00:00
|
|
|
<div v-if="containers.length" class="box">
|
2024-11-03 21:57:12 +00:00
|
|
|
<ul>
|
|
|
|
<li v-for="container in containers" :key="container.id">
|
2024-11-04 16:31:04 +00:00
|
|
|
<router-link :to="`/show/${container.name}`">
|
|
|
|
<Icon
|
|
|
|
:class="`has-text-${status_icon(container).type} m-2`"
|
|
|
|
:name="status_icon(container).name"
|
|
|
|
>{{ container.name }}</Icon
|
|
|
|
>
|
2024-11-03 21:57:12 +00:00
|
|
|
</router-link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2024-11-03 17:54:42 +00:00
|
|
|
</Loading>
|
2024-11-02 18:41:13 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2024-11-03 18:14:47 +00:00
|
|
|
import axios, { AxiosError } from 'axios'
|
2024-11-03 22:10:21 +00:00
|
|
|
import type { Container } from '../types'
|
|
|
|
import Icon from '../components/Icon.vue'
|
|
|
|
import Loading from '../components/Loading.vue'
|
2024-11-05 22:45:23 +00:00
|
|
|
import { get_status_icon } from '../utils'
|
2024-11-03 17:54:42 +00:00
|
|
|
|
2024-11-02 18:41:13 +00:00
|
|
|
export default {
|
2024-11-03 19:42:55 +00:00
|
|
|
name: 'Home',
|
2024-11-03 17:54:42 +00:00
|
|
|
components: {
|
2024-11-03 21:57:12 +00:00
|
|
|
Icon,
|
2024-11-03 17:54:42 +00:00
|
|
|
Loading,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-11-03 22:10:21 +00:00
|
|
|
containers: [] as Container[],
|
2024-11-03 18:14:47 +00:00
|
|
|
error: '',
|
2024-11-03 17:54:42 +00:00
|
|
|
loading: true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async mounted() {
|
|
|
|
try {
|
2024-11-03 22:10:21 +00:00
|
|
|
const response = await axios.get<Container[]>('/api/containers')
|
2024-11-03 18:14:47 +00:00
|
|
|
this.containers = response.data
|
2024-11-03 17:54:42 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
2024-11-03 18:14:47 +00:00
|
|
|
this.error =
|
|
|
|
error instanceof AxiosError ? error.message : 'Error loading containers'
|
2024-11-03 17:54:42 +00:00
|
|
|
} finally {
|
|
|
|
this.loading = false
|
|
|
|
}
|
|
|
|
},
|
2024-11-04 16:31:04 +00:00
|
|
|
methods: {
|
|
|
|
status_icon(container: Container): { name: string; type: string } {
|
2024-11-05 22:45:23 +00:00
|
|
|
return get_status_icon(container.status)
|
2024-11-04 16:31:04 +00:00
|
|
|
},
|
|
|
|
},
|
2024-11-02 18:41:13 +00:00
|
|
|
}
|
|
|
|
</script>
|