From 631bc60cb20399b81f7e8dc1b881c723406040f2 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 25 Nov 2023 22:14:21 +0800 Subject: [PATCH] Add support for extra info: URLs (#182) * Always show Down button * Add URL and improve ArrayInput handling * Minor --- frontend/src/components/ArrayInput.vue | 38 +++++++++++++++-- frontend/src/components/ArraySelect.vue | 7 ++- frontend/src/lang/en.json | 3 +- frontend/src/pages/Compose.vue | 57 +++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/ArrayInput.vue b/frontend/src/components/ArrayInput.vue index 2271083..09587c9 100644 --- a/frontend/src/components/ArrayInput.vue +++ b/frontend/src/components/ArrayInput.vue @@ -30,6 +30,10 @@ export default { displayName: { type: String, required: true, + }, + objectType: { + type: String, + default: "service", } }, data() { @@ -41,8 +45,7 @@ export default { array() { // Create the array if not exists, it should be safe. if (!this.service[this.name]) { - // eslint-disable-next-line vue/no-side-effects-in-computed-properties - this.service[this.name] = []; + return []; } return this.service[this.name]; }, @@ -56,8 +59,24 @@ export default { return this.service[this.name] !== undefined; }, + /** + * Not a good name, but it is used to get the object. + */ service() { - return this.$parent.$parent.service; + if (this.objectType === "service") { + // Used in Container.vue + return this.$parent.$parent.service; + } else if (this.objectType === "x-dockge") { + + if (!this.$parent.$parent.jsonConfig["x-dockge"]) { + return {}; + } + + // Used in Compose.vue + return this.$parent.$parent.jsonConfig["x-dockge"]; + } else { + return {}; + } }, valid() { @@ -81,6 +100,19 @@ export default { }, methods: { addField() { + + // Create the object if not exists. + if (this.objectType === "x-dockge") { + if (!this.$parent.$parent.jsonConfig["x-dockge"]) { + this.$parent.$parent.jsonConfig["x-dockge"] = {}; + } + } + + // Create the array if not exists. + if (!this.service[this.name]) { + this.service[this.name] = []; + } + this.array.push(""); }, remove(index) { diff --git a/frontend/src/components/ArraySelect.vue b/frontend/src/components/ArraySelect.vue index ebf505c..40152ba 100644 --- a/frontend/src/components/ArraySelect.vue +++ b/frontend/src/components/ArraySelect.vue @@ -49,8 +49,7 @@ export default { array() { // Create the array if not exists, it should be safe. if (!this.service[this.name]) { - // eslint-disable-next-line vue/no-side-effects-in-computed-properties - this.service[this.name] = []; + return []; } return this.service[this.name]; }, @@ -89,6 +88,10 @@ export default { }, methods: { addField() { + // Create the array if not exists. + if (!this.service[this.name]) { + this.service[this.name] = []; + } this.array.push(""); }, remove(index) { diff --git a/frontend/src/lang/en.json b/frontend/src/lang/en.json index 874482e..d01bcb6 100644 --- a/frontend/src/lang/en.json +++ b/frontend/src/lang/en.json @@ -96,5 +96,6 @@ "reverseProxyMsg2": "Check how to config it for WebSocket", "Cannot connect to the socket server.": "Cannot connect to the socket server.", "reconnecting...": "Reconnecting...", - "connecting...": "Connecting to the socket server..." + "connecting...": "Connecting to the socket server...", + "url": "URL | URLs" } diff --git a/frontend/src/pages/Compose.vue b/frontend/src/pages/Compose.vue index fa8a727..c2fb67a 100644 --- a/frontend/src/pages/Compose.vue +++ b/frontend/src/pages/Compose.vue @@ -56,6 +56,13 @@ + +
+ + {{ url.display }} + +
+
{{ $t("Lowercase only") }}
+ + +
+ + +
@@ -111,6 +126,20 @@ + +
+

{{ $t("Extra") }}

+
+ +
+ + +
+
+
+

Terminal

@@ -252,6 +281,34 @@ export default { }; }, computed: { + + urls() { + if (!this.jsonConfig["x-dockge"] || !this.jsonConfig["x-dockge"].urls || !Array.isArray(this.jsonConfig["x-dockge"].urls)) { + return []; + } + + let urls = []; + for (const url of this.jsonConfig["x-dockge"].urls) { + let display; + try { + let obj = new URL(url); + let pathname = obj.pathname; + if (pathname === "/") { + pathname = ""; + } + display = obj.host + pathname + obj.search; + } catch (e) { + display = url; + } + + urls.push({ + display, + url, + }); + } + return urls; + }, + isAdd() { return this.$route.path === "/compose" && !this.submitted; },