Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launcher save fixed attributes #3784

Merged
merged 19 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions apps/dashboard/app/javascript/launcher_edit.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you submit the changes to this file in another pull request? I can't just glance at this to see what it is, so I'll need more time to look it over.

Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,38 @@ function addInProgressField(event) {
function updateAutoEnvironmentVariable(event) {
var aev_name = event.target.value;
const labelString = event.target.dataset.labelString;
const idString = `launcher_auto_environment_variable_${aev_name}`;
const nameString = `launcher[auto_environment_variable_${aev_name}]`;
var input_field = event.target.parentElement.children[2].children[1];

input_field.removeAttribute('readonly');
input_field.id = `launcher_auto_environment_variable_${aev_name}`;
input_field.name = `launcher[auto_environment_variable_${aev_name}]`;
input_field.id = idString;
input_field.name = nameString;

if (labelString.match(/Environment( |\s)Variable/)) {
var label_field = event.target.parentElement.children[2].children[0];
label_field.innerHTML = `Environment Variable: ${aev_name}`;
}

// Update the checkbox so that environment variables can be fixed when created
let fixedBoxGroup = event.target.parentElement.children[3].children[0].children[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's really flaky and prone to errors. Is there some ID or data- attribute we can apply here so we don't have this?

querySelector (or querySelectorAll) is a method on the document object, bit it's also a method on all elements. So you could do event.target.querySelector to find what we're looking for.


let checkbox = fixedBoxGroup.children[0];
checkbox.id = `${idString}_fixed`;
checkbox.name = `launcher[auto_environment_variable_${aev_name}_fixed]`;
checkbox.setAttribute('data-fixed-toggler', idString);

// Update hidden field if attribute is already fixed, otherwise just update label
let labelIndex = 2;
if(fixedBoxGroup.children.length == 3) {
let hiddenField = fixedBoxGroup.children[1];
hiddenField.name = nameString;
} else {
labelIndex = 1;
}

let fixedLabel = fixedBoxGroup.children[labelIndex];
fixedLabel.setAttribute('for', `${idString}_fixed`);
}

function fixExcludeBasedOnSelect(selectElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ def self.build_bc_num_slots(opts = {})

module Attributes
class BcNumSlots < Attribute
# Hash of options used to define this attribute
# @return [Hash] attribute options
def opts
@opts.reverse_merge(min: 1, step: 1)
def initialize(id, opts)
super(id, opts)
@opts = @opts.reverse_merge(min: 1, step: 1)
end

# Value of attribute
Expand Down
9 changes: 6 additions & 3 deletions apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,12 @@ def add_default_fields(form: [], **_args)
def add_script_to_form(form: [], attributes: {})
form << 'auto_scripts' unless form.include?('auto_scripts')

attributes[:auto_scripts] = {
directory: project_dir
}
dir = { directory: project_dir }
attributes[:auto_scripts] = if attributes[:auto_scripts]
attributes[:auto_scripts].merge(dir)
else
dir
end
johrstrom marked this conversation as resolved.
Show resolved Hide resolved
end

def add_cluster_to_form(form: [], attributes: {})
Expand Down
Loading