From c3fc86fc29ef2df55002d68d56ce601dc1000b51 Mon Sep 17 00:00:00 2001
From: Matthew K Defenderfer <mdefende@uab.edu>
Date: Tue, 3 Jun 2025 01:43:53 -0500
Subject: [PATCH] changes

---
 form.js      | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 form.yml.erb |  2 +-
 2 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 form.js

diff --git a/form.js b/form.js
new file mode 100644
index 0000000..746d927
--- /dev/null
+++ b/form.js
@@ -0,0 +1,72 @@
+const table = {
+  "interactive": { "max_cpu": 48, "max_hour": 2, "max_gpu": 0 },
+  "express": { "max_cpu": 48, "max_hour": 2, "max_gpu": 0 },
+  "short": { "max_cpu": 48, "max_hour": 12, "max_gpu": 0 },
+  "pascalnodes": { "max_cpu": 28, "max_hour": 12, "max_gpu": 4 },
+  "pascalnodes-medium": { "max_cpu": 28, "max_hour": 48, "max_gpu": 4 },
+  "medium": { "max_cpu": 48, "max_hour": 50, "max_gpu": 0 },
+  "long": { "max_cpu": 48, "max_hour": 150, "max_gpu": 0 },
+  "intel-dcb": { "max_cpu": 24, "max_hour": 150, "max_gpu": 0 },
+  "amd-hdr100": { "max_cpu": 128, "max_hour": 150, "max_gpu": 0 },
+  "largemem": { "max_cpu": 24, "max_hour": 50, "max_gpu": 0 },
+  "largemem-long": { "max_cpu": 24, "max_hour": 150, "max_gpu": 0 },
+  "amperenodes": { "max_cpu": 128, "max_hour": 12, "max_gpu": 2 },
+  "amperenodes-medium": { "max_cpu": 128, "max_hour": 48, "max_gpu": 2 },
+}
+
+const gpu_part_regex = /pascal|ampere/;
+
+function set_max_value(form_id, value) {
+  const form_element = $(form_id);
+  form_element.attr({'max': value});
+  if (form_element.val() > value)
+    form_element.val(value)
+}
+
+function set_partition_change_handler() {
+  let partition_select = $("#batch_connect_session_context_bc_partition");
+  partition_select.change( function(e) {
+    toggle_gpu_visibility(e);
+  });
+}
+
+function toggle_gpu_visibility(event) {
+  const partition = event.target.value;
+  const cpu_selector = '#batch_connect_session_context_bc_num_slots';
+  const gpu_selector = '#batch_connect_session_context_bc_num_gpus';
+  const hour_selector = '#batch_connect_session_context_bc_num_hours';
+
+  toggle_visibilty_of_form_group(gpu_selector, gpu_part_regex.test(partition));
+  set_max_value(cpu_selector, table[partition]["max_cpu"]);
+  set_max_value(gpu_selector, table[partition]["max_gpu"]);
+  set_max_value(hour_selector, table[partition]["max_hour"]);
+}
+
+function toggle_visibilty_of_form_group(form_id, show) {
+  let form_element = $(form_id);
+  let parent = form_element;
+
+  while (
+    (! parent[0].classList.contains('form-group')) &&
+    (! parent.is('html')) // ensure that we don't loop infinitely
+  ) {
+    parent = parent.parent();
+  }
+
+  // If parent is HTML then something has gone wrong and visibility should not be changed
+  if ( parent.is('html') ) {
+    return;
+  }
+
+  if(show) {
+    parent.show();
+  } else {
+    parent.hide();
+  }
+}
+
+toggle_gpu_visibility(
+  // Fake the event
+  { target: document.querySelector('#batch_connect_session_context_bc_partition') }
+);
+set_partition_change_handler();
diff --git a/form.yml.erb b/form.yml.erb
index a0e8820..0743d97 100644
--- a/form.yml.erb
+++ b/form.yml.erb
@@ -4,7 +4,6 @@
 ---
 title: "HPC Desktop"
 cluster: SLURM_CLUSTER
-submit: "submit/submit.yml.erb"
 attributes:
   desktop: "xfce"
   bc_num_slots:
@@ -41,6 +40,7 @@ attributes:
   bc_reservation:
     widget: "text_field"
     label: Reservation Name
+    value: ""
 
 form:
   - desktop
-- 
GitLab