diff --git a/static/js/app-detail.js b/static/js/app-detail.js index 9778ea8..8636d54 100644 --- a/static/js/app-detail.js +++ b/static/js/app-detail.js @@ -6,6 +6,68 @@ */ document.addEventListener("alpine:init", () => { + // ============================================ + // Environment Variable Editor Component + // ============================================ + Alpine.data("envVarEditor", () => ({ + vars: [], + editIdx: -1, + editKey: "", + editVal: "", + + init() { + this.vars = Array.from(this.$el.querySelectorAll(".env-init")).map( + (span) => ({ + key: span.dataset.key, + value: span.dataset.value, + }), + ); + }, + + startEdit(i) { + this.editIdx = i; + this.editKey = this.vars[i].key; + this.editVal = this.vars[i].value; + }, + + saveEdit(i) { + this.vars[i] = { key: this.editKey, value: this.editVal }; + this.editIdx = -1; + this.submitAll(); + }, + + removeVar(i) { + if (!window.confirm("Delete this environment variable?")) { + return; + } + + this.vars.splice(i, 1); + this.submitAll(); + }, + + addVar(keyEl, valEl) { + const k = keyEl.value.trim(); + const v = valEl.value.trim(); + + if (!k) { + return; + } + + this.vars.push({ key: k, value: v }); + this.submitAll(); + }, + + submitAll() { + this.$refs.bulkData.value = this.vars + .map((e) => e.key + "=" + e.value) + .join("\n"); + this.$refs.bulkForm.submit(); + }, + })); + + // ============================================ + // App Detail Page Component + // ============================================ Alpine.data("appDetail", (config) => ({ appId: config.appId, currentDeploymentId: config.initialDeploymentId, diff --git a/templates/app_detail.html b/templates/app_detail.html index e315e4c..0e10cf9 100644 --- a/templates/app_detail.html +++ b/templates/app_detail.html @@ -101,91 +101,59 @@ -
| Key | -Value | -Actions | -|||
|---|---|---|---|---|---|
| - - - | - - - | - - - | - - -
-
-
-
-
-
- ⚠ Container restart needed after env var changes. - |
-
- ||
⚠ Container restart needed after env var changes.
-