2022-07-22 15:47:04 +00:00
|
|
|
<template>
|
|
|
|
<form @submit.prevent="submit">
|
|
|
|
<div ref="modal" class="modal fade" tabindex="-1" data-bs-backdrop="static">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 id="exampleModalLabel" class="modal-title">
|
|
|
|
{{ $t("Setup Docker Host") }}
|
|
|
|
</h5>
|
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="docker-name" class="form-label">{{ $t("Friendly Name") }}</label>
|
|
|
|
<input id="docker-name" v-model="dockerHost.name" type="text" class="form-control" required>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="docker-type" class="form-label">{{ $t("Connection Type") }}</label>
|
|
|
|
<select id="docker-type" v-model="dockerHost.dockerType" class="form-select">
|
|
|
|
<option v-for="type in connectionTypes" :key="type" :value="type">{{ $t(type) }}</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="docker-daemon" class="form-label">{{ $t("Docker Daemon") }}</label>
|
|
|
|
<input id="docker-daemon" v-model="dockerHost.dockerDaemon" type="text" class="form-control" required>
|
2022-07-30 11:57:51 +00:00
|
|
|
|
|
|
|
<div class="form-text">
|
|
|
|
{{ $t("Examples") }}:
|
|
|
|
<ul>
|
|
|
|
<li>/var/run/docker.sock</li>
|
2022-10-04 08:19:56 +00:00
|
|
|
<li>http://localhost:2375</li>
|
|
|
|
<li>https://localhost:2376 (TLS)</li>
|
2022-07-30 11:57:51 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
2022-07-22 15:47:04 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button v-if="id" type="button" class="btn btn-danger" :disabled="processing" @click="deleteConfirm">
|
|
|
|
{{ $t("Delete") }}
|
|
|
|
</button>
|
|
|
|
<button type="button" class="btn btn-warning" :disabled="processing" @click="test">
|
|
|
|
{{ $t("Test") }}
|
|
|
|
</button>
|
|
|
|
<button type="submit" class="btn btn-primary" :disabled="processing">
|
|
|
|
<div v-if="processing" class="spinner-border spinner-border-sm me-1"></div>
|
|
|
|
{{ $t("Save") }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<Confirm ref="confirmDelete" btn-style="btn-danger" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="deleteDockerHost">
|
|
|
|
{{ $t("deleteDockerHostMsg") }}
|
|
|
|
</Confirm>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Modal } from "bootstrap";
|
|
|
|
import Confirm from "./Confirm.vue";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Confirm,
|
|
|
|
},
|
|
|
|
props: {},
|
2023-11-03 13:25:28 +00:00
|
|
|
emits: [ "added", "deleted" ],
|
2022-07-22 15:47:04 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2023-01-03 04:16:25 +00:00
|
|
|
modal: null,
|
2022-07-22 15:47:04 +00:00
|
|
|
processing: false,
|
|
|
|
id: null,
|
2022-07-22 15:57:40 +00:00
|
|
|
connectionTypes: [ "socket", "tcp" ],
|
2022-07-22 15:47:04 +00:00
|
|
|
dockerHost: {
|
|
|
|
name: "",
|
|
|
|
dockerDaemon: "",
|
|
|
|
dockerType: "",
|
|
|
|
// Do not set default value here, please scroll to show()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.modal = new Modal(this.$refs.modal);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Confirm deletion of docker host
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-07-22 15:47:04 +00:00
|
|
|
deleteConfirm() {
|
|
|
|
this.modal.hide();
|
|
|
|
this.$refs.confirmDelete.show();
|
|
|
|
},
|
|
|
|
|
2023-01-05 22:55:51 +00:00
|
|
|
/**
|
|
|
|
* Show specified docker host
|
2023-08-11 07:46:41 +00:00
|
|
|
* @param {number} dockerHostID ID of host to show
|
|
|
|
* @returns {void}
|
2023-01-05 22:55:51 +00:00
|
|
|
*/
|
2022-07-22 15:47:04 +00:00
|
|
|
show(dockerHostID) {
|
|
|
|
if (dockerHostID) {
|
2022-07-30 11:48:12 +00:00
|
|
|
let found = false;
|
|
|
|
|
2022-07-22 15:47:04 +00:00
|
|
|
this.id = dockerHostID;
|
|
|
|
|
|
|
|
for (let n of this.$root.dockerHostList) {
|
|
|
|
if (n.id === dockerHostID) {
|
|
|
|
this.dockerHost = n;
|
2022-07-30 11:48:12 +00:00
|
|
|
found = true;
|
2022-07-22 15:47:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-30 11:48:12 +00:00
|
|
|
|
|
|
|
if (!found) {
|
2023-10-14 11:00:27 +00:00
|
|
|
this.$root.toastError("Docker Host not found!");
|
2022-07-30 11:48:12 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 15:47:04 +00:00
|
|
|
} else {
|
|
|
|
this.id = null;
|
|
|
|
this.dockerHost = {
|
|
|
|
name: "",
|
|
|
|
dockerType: "socket",
|
|
|
|
dockerDaemon: "/var/run/docker.sock",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.modal.show();
|
|
|
|
},
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Add docker host
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-07-22 15:47:04 +00:00
|
|
|
submit() {
|
|
|
|
this.processing = true;
|
|
|
|
this.$root.getSocket().emit("addDockerHost", this.dockerHost, this.id, (res) => {
|
|
|
|
this.$root.toastRes(res);
|
|
|
|
this.processing = false;
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
this.modal.hide();
|
|
|
|
|
|
|
|
// Emit added event, doesn't emit edit.
|
|
|
|
if (! this.id) {
|
|
|
|
this.$emit("added", res.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Test the docker host
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-07-22 15:47:04 +00:00
|
|
|
test() {
|
|
|
|
this.processing = true;
|
|
|
|
this.$root.getSocket().emit("testDockerHost", this.dockerHost, (res) => {
|
|
|
|
this.$root.toastRes(res);
|
|
|
|
this.processing = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Delete this docker host
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-07-22 15:47:04 +00:00
|
|
|
deleteDockerHost() {
|
|
|
|
this.processing = true;
|
|
|
|
this.$root.getSocket().emit("deleteDockerHost", this.id, (res) => {
|
|
|
|
this.$root.toastRes(res);
|
|
|
|
this.processing = false;
|
|
|
|
|
|
|
|
if (res.ok) {
|
2023-11-03 13:25:28 +00:00
|
|
|
this.$emit("deleted", this.id);
|
2022-07-22 15:47:04 +00:00
|
|
|
this.modal.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "../assets/vars.scss";
|
|
|
|
|
|
|
|
.dark {
|
|
|
|
.modal-dialog .form-text, .modal-dialog p {
|
|
|
|
color: $dark-font-color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|