Skip to content

Commit 8e3ff25

Browse files
louislamchakflying
andauthored
Followup #3864, rebase for 1.23.x (#4016)
* Fix: Use ActionSelect Docker Host & validate input * Fix: Handle docker host deleted while editing * UI: Use add for ActionSelect & prevent delete instead --------- Co-authored-by: Nelson Chan <chakflying@hotmail.com>
1 parent 6e80c85 commit 8e3ff25

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-20
lines changed

server/model/monitor.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,6 @@ class Monitor extends BeanModel {
739739
} else if (this.type === "docker") {
740740
log.debug("monitor", `[${this.name}] Prepare Options for Axios`);
741741

742-
const dockerHost = await R.load("docker_host", this.docker_host);
743-
744742
const options = {
745743
url: `/containers/${this.docker_container}/json`,
746744
timeout: this.interval * 1000 * 0.8,
@@ -757,6 +755,12 @@ class Monitor extends BeanModel {
757755
}),
758756
};
759757

758+
const dockerHost = await R.load("docker_host", this.docker_host);
759+
760+
if (!dockerHost) {
761+
throw new Error("Failed to load docker host config");
762+
}
763+
760764
if (dockerHost._dockerType === "socket") {
761765
options.socketPath = dockerHost._dockerDaemon;
762766
} else if (dockerHost._dockerType === "tcp") {

src/components/ActionSelect.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<div class="input-group mb-3">
3-
<select ref="select" v-model="model" class="form-select" :disabled="disabled">
4-
<option v-for="option in options" :key="option" :value="option.value">{{ option.label }}</option>
3+
<select ref="select" v-model="model" class="form-select" :disabled="disabled" :required="required">
4+
<option v-for="option in options" :key="option" :value="option.value" :disabled="option.disabled">{{ option.label }}</option>
55
</select>
6-
<a class="btn btn-outline-primary" @click="action()">
6+
<a class="btn btn-outline-primary" :class="{ disabled: actionDisabled }" @click="action()">
77
<font-awesome-icon :icon="icon" />
88
</a>
99
</div>
@@ -50,6 +50,22 @@ export default {
5050
action: {
5151
type: Function,
5252
default: () => {},
53+
},
54+
/**
55+
* Whether the action button is disabled.
56+
* @example true
57+
*/
58+
actionDisabled: {
59+
type: Boolean,
60+
default: false
61+
},
62+
/**
63+
* Whether the select field is required.
64+
* @example true
65+
*/
66+
required: {
67+
type: Boolean,
68+
default: false,
5369
}
5470
},
5571
emits: [ "update:modelValue" ],

src/components/DockerHostDialog.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
Confirm,
7171
},
7272
props: {},
73-
emits: [ "added" ],
73+
emits: [ "added", "deleted" ],
7474
data() {
7575
return {
7676
modal: null,
@@ -167,6 +167,7 @@ export default {
167167
this.processing = false;
168168
169169
if (res.ok) {
170+
this.$emit("deleted", this.id);
170171
this.modal.hide();
171172
}
172173
});

src/lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@
369369
"Setup Docker Host": "Setup Docker Host",
370370
"Connection Type": "Connection Type",
371371
"Docker Daemon": "Docker Daemon",
372+
"noDockerHostMsg": "Not Available. Setup a Docker Host First.",
373+
"DockerHostRequired": "Please set the Docker Host for this monitor.",
372374
"deleteDockerHostMsg": "Are you sure want to delete this docker host for all monitors?",
373375
"socket": "Socket",
374376
"tcp": "TCP / HTTP",

src/pages/EditMonitor.vue

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,22 +285,17 @@
285285
<!-- Docker Host -->
286286
<!-- For Docker Type -->
287287
<div v-if="monitor.type === 'docker'" class="my-3">
288-
<h2 class="mb-2">{{ $t("Docker Host") }}</h2>
289-
<p v-if="$root.dockerHostList.length === 0">
290-
{{ $t("Not available, please setup.") }}
291-
</p>
292-
293-
<div v-else class="mb-3">
288+
<div class="mb-3">
294289
<label for="docker-host" class="form-label">{{ $t("Docker Host") }}</label>
295-
<select id="docket-host" v-model="monitor.docker_host" class="form-select">
296-
<option v-for="host in $root.dockerHostList" :key="host.id" :value="host.id">{{ host.name }}</option>
297-
</select>
298-
<a href="#" @click="$refs.dockerHostDialog.show(monitor.docker_host)">{{ $t("Edit") }}</a>
290+
<ActionSelect
291+
v-model="monitor.docker_host"
292+
:options="dockerHostOptionsList"
293+
:disabled="$root.dockerHostList == null || $root.dockerHostList.length === 0"
294+
:icon="'plus'"
295+
:action="() => $refs.dockerHostDialog.show()"
296+
:required="true"
297+
/>
299298
</div>
300-
301-
<button class="btn btn-primary me-2" type="button" @click="$refs.dockerHostDialog.show()">
302-
{{ $t("Setup Docker Host") }}
303-
</button>
304299
</div>
305300

306301
<!-- MQTT -->
@@ -1119,6 +1114,21 @@ message HealthCheckResponse {
11191114
return list;
11201115
},
11211116
1117+
dockerHostOptionsList() {
1118+
if (this.$root.dockerHostList && this.$root.dockerHostList.length > 0) {
1119+
return this.$root.dockerHostList.map((host) => {
1120+
return {
1121+
label: host.name,
1122+
value: host.id
1123+
};
1124+
});
1125+
} else {
1126+
return [{
1127+
label: this.$t("noDockerHostMsg"),
1128+
value: null,
1129+
}];
1130+
}
1131+
}
11221132
},
11231133
watch: {
11241134
"$root.proxyList"() {
@@ -1351,6 +1361,12 @@ message HealthCheckResponse {
13511361
return false;
13521362
}
13531363
}
1364+
if (this.monitor.type === "docker") {
1365+
if (this.monitor.docker_host == null) {
1366+
toast.error(this.$t("DockerHostRequired"));
1367+
return false;
1368+
}
1369+
}
13541370
return true;
13551371
},
13561372

0 commit comments

Comments
 (0)