2024-11-04 16:31:04 +00:00
|
|
|
<template>
|
|
|
|
<Loading
|
|
|
|
class="box content"
|
|
|
|
:loading="loading"
|
|
|
|
:message="error"
|
|
|
|
type="danger"
|
|
|
|
>
|
2024-11-05 14:02:06 +00:00
|
|
|
<form @submit.prevent="submit">
|
|
|
|
<div v-if="!container_name" class="field">
|
|
|
|
<label class="label">Name</label>
|
|
|
|
<div class="control has-icons-left">
|
|
|
|
<input
|
|
|
|
v-model="custom_name"
|
|
|
|
class="input"
|
|
|
|
placeholder="loop"
|
|
|
|
required
|
|
|
|
type="text"
|
|
|
|
/>
|
|
|
|
<span class="icon is-small is-left">
|
|
|
|
<i class="fa fa-tag"></i>
|
|
|
|
</span>
|
|
|
|
</div>
|
2024-11-04 16:31:04 +00:00
|
|
|
</div>
|
2024-11-05 14:02:06 +00:00
|
|
|
<div class="field">
|
|
|
|
<label class="label">Image</label>
|
|
|
|
<div class="control has-icons-left">
|
|
|
|
<input
|
|
|
|
v-model="image"
|
|
|
|
class="input"
|
|
|
|
placeholder="ghcr.io/crazy-max/loop:latest"
|
|
|
|
required
|
|
|
|
type="text"
|
|
|
|
/>
|
|
|
|
<span class="icon is-small is-left">
|
|
|
|
<i class="fa fa-image"></i>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
|
|
|
<label class="label">Environment variables</label>
|
|
|
|
<div class="control">
|
|
|
|
<textarea
|
|
|
|
v-model="environment"
|
|
|
|
class="textarea"
|
|
|
|
placeholder="DURATION=60s"
|
|
|
|
></textarea>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field is-grouped">
|
|
|
|
<div class="control">
|
|
|
|
<button class="button is-link" type="submit">Submit</button>
|
|
|
|
</div>
|
|
|
|
<div class="control">
|
|
|
|
<button class="button is-link is-light" @click="$router.back()">
|
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
2024-11-04 16:31:04 +00:00
|
|
|
</Loading>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2024-11-05 14:02:06 +00:00
|
|
|
import axios, { AxiosError } from 'axios'
|
|
|
|
import type { Container } from '../types'
|
2024-11-04 16:31:04 +00:00
|
|
|
import Loading from '../components/Loading.vue'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Update',
|
|
|
|
components: {
|
|
|
|
Loading,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-11-05 14:02:06 +00:00
|
|
|
custom_name: null as string | null,
|
|
|
|
image: null as string | null,
|
2024-11-06 14:17:34 +00:00
|
|
|
environment: '',
|
2024-11-04 16:31:04 +00:00
|
|
|
error: '',
|
|
|
|
loading: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
container_name(): string {
|
|
|
|
return this.$route.params.name as string
|
|
|
|
},
|
|
|
|
},
|
2024-11-05 14:02:06 +00:00
|
|
|
async mounted() {
|
|
|
|
if (!this.container_name) return
|
|
|
|
try {
|
|
|
|
this.loading = true
|
|
|
|
const { data } = await axios.get<Container>(
|
|
|
|
`/api/container/${this.container_name}`,
|
|
|
|
)
|
|
|
|
this.custom_name = data.name
|
|
|
|
this.image = data.image
|
|
|
|
this.environment = data.environment.join('\n')
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
this.error =
|
|
|
|
error instanceof AxiosError
|
|
|
|
? error.message
|
|
|
|
: 'Error performing operation'
|
|
|
|
} finally {
|
|
|
|
this.loading = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async submit() {
|
2024-11-06 14:17:34 +00:00
|
|
|
if (!this.image || !(this.custom_name ?? this.container_name)) return
|
2024-11-05 14:02:06 +00:00
|
|
|
try {
|
|
|
|
this.loading = true
|
|
|
|
const { data } = await axios.post<Container>(
|
|
|
|
`/api/container/${this.custom_name ?? this.container_name}`,
|
|
|
|
{
|
|
|
|
image: this.image,
|
|
|
|
environment: this.environment?.split('\n'),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
this.$router.push(`/show/${data.name}`)
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
this.error =
|
|
|
|
error instanceof AxiosError
|
|
|
|
? error.message
|
|
|
|
: 'Error performing operation'
|
|
|
|
} finally {
|
|
|
|
this.loading = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2024-11-04 16:31:04 +00:00
|
|
|
}
|
|
|
|
</script>
|