Derive the application name from the pip name
authorAlexander Ebert <ebert@woltlab.com>
Fri, 16 Jun 2023 15:10:47 +0000 (17:10 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 22 Jun 2023 11:33:45 +0000 (13:33 +0200)
ts/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/Instructions.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Form/Builder/Field/Devtools/Project/Instructions.js

index 9ebf396a3c00f254a75488a23470c62a33c30e89..6ff361c2f6b73804ed4e520c61b3a1853103aa97 100644 (file)
@@ -312,9 +312,15 @@ class Instructions {
       .getElementById(`${this.formFieldId}_instructions${instructionsId}_pip`)!
       .addEventListener("change", (ev) => this.changeInstructionPip(ev));
 
-    document
-      .getElementById(`${this.formFieldId}_instructions${instructionsId}_value`)!
-      .addEventListener("keypress", (ev) => this.instructionKeyPress(ev));
+    const value = document.getElementById(
+      `${this.formFieldId}_instructions${instructionsId}_value`,
+    ) as HTMLInputElement;
+    value.addEventListener("keypress", (ev) => this.instructionKeyPress(ev));
+
+    const application = document.getElementById(
+      `${this.formFieldId}_instructions${instructionsId}_application`,
+    ) as HTMLSelectElement;
+    application.addEventListener("focus", () => this.#deriveApplicationFromPipName(application, value));
 
     document
       .getElementById(`${this.formFieldId}_instructions${instructionsId}_addButton`)!
@@ -327,6 +333,20 @@ class Instructions {
     }
   }
 
+  #deriveApplicationFromPipName(application: HTMLSelectElement, value: HTMLInputElement): void {
+    if (application.value !== "") {
+      return;
+    }
+
+    const matches = value.value.trim().match(/_([a-z]+).tar$/);
+    if (matches !== null) {
+      const isValid = Array.from(application.options).some((option) => option.value === matches[1]);
+      if (isValid) {
+        application.value = matches[1];
+      }
+    }
+  }
+
   /**
    * Is called if the selected package installation plugin of an instruction is changed.
    */
index 039d86326f4861299093696b1ba838be374cb0b8..b7d3a8a145cb09518b1e0b124983820eed73c57d 100644 (file)
@@ -220,9 +220,10 @@ define(["require", "exports", "tslib", "../../../../../../Core", "../../../../..
             document
                 .getElementById(`${this.formFieldId}_instructions${instructionsId}_pip`)
                 .addEventListener("change", (ev) => this.changeInstructionPip(ev));
-            document
-                .getElementById(`${this.formFieldId}_instructions${instructionsId}_value`)
-                .addEventListener("keypress", (ev) => this.instructionKeyPress(ev));
+            const value = document.getElementById(`${this.formFieldId}_instructions${instructionsId}_value`);
+            value.addEventListener("keypress", (ev) => this.instructionKeyPress(ev));
+            const application = document.getElementById(`${this.formFieldId}_instructions${instructionsId}_application`);
+            application.addEventListener("focus", () => this.#deriveApplicationFromPipName(application, value));
             document
                 .getElementById(`${this.formFieldId}_instructions${instructionsId}_addButton`)
                 .addEventListener("click", (ev) => this.addInstruction(ev));
@@ -232,6 +233,18 @@ define(["require", "exports", "tslib", "../../../../../../Core", "../../../../..
                 });
             }
         }
+        #deriveApplicationFromPipName(application, value) {
+            if (application.value !== "") {
+                return;
+            }
+            const matches = value.value.trim().match(/_([a-z]+).tar$/);
+            if (matches !== null) {
+                const isValid = Array.from(application.options).some((option) => option.value === matches[1]);
+                if (isValid) {
+                    application.value = matches[1];
+                }
+            }
+        }
         /**
          * Is called if the selected package installation plugin of an instruction is changed.
          */