From 0eba218eb8401cc49370e5f59a2ae8251b7122c8 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 6 Sep 2024 09:30:28 -0400 Subject: [PATCH 01/16] don't overwrite opts --- .../app/lib/smart_attributes/attributes/bc_num_slots.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/bc_num_slots.rb b/apps/dashboard/app/lib/smart_attributes/attributes/bc_num_slots.rb index 857f048085..bd466e55e0 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/bc_num_slots.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/bc_num_slots.rb @@ -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 From 6df0e0c9f64cef274981040fa23b36884fedcd88 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 6 Sep 2024 10:50:09 -0400 Subject: [PATCH 02/16] don't overwrite auto_scripts in model --- apps/dashboard/app/models/launcher.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/app/models/launcher.rb b/apps/dashboard/app/models/launcher.rb index b8286cf57d..29413a72df 100644 --- a/apps/dashboard/app/models/launcher.rb +++ b/apps/dashboard/app/models/launcher.rb @@ -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 end def add_cluster_to_form(form: [], attributes: {}) From f221f5cbdebfe1d9d9dce2c93d91435c1036871a Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 6 Sep 2024 11:47:43 -0400 Subject: [PATCH 03/16] update fixed checkbox when environment variable changes --- .../dashboard/app/javascript/launcher_edit.js | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/app/javascript/launcher_edit.js b/apps/dashboard/app/javascript/launcher_edit.js index 5ad24685e8..e670a3dd61 100644 --- a/apps/dashboard/app/javascript/launcher_edit.js +++ b/apps/dashboard/app/javascript/launcher_edit.js @@ -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]; + + 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) { From a51806ee06b6369ea0e029e6a743dab8423e179a Mon Sep 17 00:00:00 2001 From: Ashton South Date: Mon, 9 Sep 2024 14:51:34 -0400 Subject: [PATCH 04/16] clean up some javascript --- .../dashboard/app/javascript/launcher_edit.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/dashboard/app/javascript/launcher_edit.js b/apps/dashboard/app/javascript/launcher_edit.js index e670a3dd61..d7d58d2023 100644 --- a/apps/dashboard/app/javascript/launcher_edit.js +++ b/apps/dashboard/app/javascript/launcher_edit.js @@ -164,39 +164,36 @@ function addInProgressField(event) { } function updateAutoEnvironmentVariable(event) { - var aev_name = event.target.value; + const 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]; + const input_field = event.target.parentElement.children[2].children[1]; + const oldId = input_field.id; input_field.removeAttribute('readonly'); input_field.id = idString; input_field.name = nameString; if (labelString.match(/Environment( |\s)Variable/)) { - var label_field = event.target.parentElement.children[2].children[0]; + const 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]; - - let checkbox = fixedBoxGroup.children[0]; + const fixedBoxGroup = event.target.parentElement.querySelector('.list-group-item'); + const checkbox = fixedBoxGroup.querySelector("input[type='checkbox']"); 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]; + const hiddenField = fixedBoxGroup.querySelector("input[type='hidden']"); hiddenField.name = nameString; - } else { - labelIndex = 1; } - let fixedLabel = fixedBoxGroup.children[labelIndex]; + const fixedLabel = fixedBoxGroup.querySelector('label'); fixedLabel.setAttribute('for', `${idString}_fixed`); } From e21b5fbf75506841f75c92937b614ae4460e4fed Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 19 Sep 2024 10:24:05 -0400 Subject: [PATCH 05/16] sleep before checking for success --- apps/dashboard/test/system/project_manager_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/test/system/project_manager_test.rb b/apps/dashboard/test/system/project_manager_test.rb index a858e6e2a6..d82783dde9 100644 --- a/apps/dashboard/test/system/project_manager_test.rb +++ b/apps/dashboard/test/system/project_manager_test.rb @@ -954,11 +954,12 @@ def add_auto_environment_variable(project_id, script_id, save: true) .stubs(:info).returns(OodCore::Job::Info.new(id: 'job-id-123', status: :running)) find("#launch_8woi7ghd").click - assert_selector('.alert-success', text: 'job-id-123') # sleep here because this test can error with Errno::ENOTEMPTY: Directory not empty @ dir_s_rmdir # something still has a hold on these files. sleep 2 + + assert_selector('.alert-success', text: 'job-id-123') end end end From 15e48f437829f58bf2955204b914cd98865d4814 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 19 Sep 2024 11:24:14 -0400 Subject: [PATCH 06/16] remove invalid script selection --- apps/dashboard/app/models/launcher.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/app/models/launcher.rb b/apps/dashboard/app/models/launcher.rb index 93f2d918a4..b9175514e0 100644 --- a/apps/dashboard/app/models/launcher.rb +++ b/apps/dashboard/app/models/launcher.rb @@ -340,10 +340,17 @@ def add_script_to_form(form: [], attributes: {}) dir = { directory: project_dir } attributes[:auto_scripts] = if attributes[:auto_scripts] - attributes[:auto_scripts].merge(dir) - else - dir - end + attributes[:auto_scripts].merge(dir) + else + dir + end + + # Delete 'value' if it does not exist in the available options + # so that projects created from templates don't point to another + # user's script + script_value = attributes[:auto_scripts]['value'] + script_options = attributes[:auto_scripts]['options'] + attributes[:auto_scripts].delete('value') if script_options.none? { |opt| opt.include?(script_value) } end def add_cluster_to_form(form: [], attributes: {}) From d90bf558ef19b517612740921f8261c88dbd5db3 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 19 Sep 2024 11:24:49 -0400 Subject: [PATCH 07/16] move sleep statement in test back --- apps/dashboard/test/system/project_manager_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/test/system/project_manager_test.rb b/apps/dashboard/test/system/project_manager_test.rb index d82783dde9..1fef94c3c0 100644 --- a/apps/dashboard/test/system/project_manager_test.rb +++ b/apps/dashboard/test/system/project_manager_test.rb @@ -955,11 +955,11 @@ def add_auto_environment_variable(project_id, script_id, save: true) find("#launch_8woi7ghd").click + assert_selector('.alert-success', text: 'job-id-123') + # sleep here because this test can error with Errno::ENOTEMPTY: Directory not empty @ dir_s_rmdir # something still has a hold on these files. sleep 2 - - assert_selector('.alert-success', text: 'job-id-123') end end end From a2a483b0c5eda1839ced0535cc594b6aee890f33 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 19 Sep 2024 11:29:40 -0400 Subject: [PATCH 08/16] add guard clause to prevent operating on Nil --- apps/dashboard/app/models/launcher.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/app/models/launcher.rb b/apps/dashboard/app/models/launcher.rb index b9175514e0..930ebd2b1c 100644 --- a/apps/dashboard/app/models/launcher.rb +++ b/apps/dashboard/app/models/launcher.rb @@ -348,8 +348,10 @@ def add_script_to_form(form: [], attributes: {}) # Delete 'value' if it does not exist in the available options # so that projects created from templates don't point to another # user's script - script_value = attributes[:auto_scripts]['value'] script_options = attributes[:auto_scripts]['options'] + return unless script_options + + script_value = attributes[:auto_scripts]['value'] attributes[:auto_scripts].delete('value') if script_options.none? { |opt| opt.include?(script_value) } end From c4646381ee45df8e0fa3ba7561f6236edd590e4f Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 19 Sep 2024 12:07:45 -0400 Subject: [PATCH 09/16] remove invalid value in attribute and not model --- .../smart_attributes/attributes/auto_scripts.rb | 15 +++++++++++++-- apps/dashboard/app/models/launcher.rb | 9 --------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb index 9dad7ee673..84478ca319 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb @@ -13,8 +13,9 @@ def self.build_auto_scripts(opts = {}) options = script_options_from_directory(dir) static_opts = { - options: options - }.merge(opts.without(:options).to_h) + options: options, + value: default_value(opts, options) + }.merge(opts.without(:options, :value).to_h) Attributes::AutoScripts.new('auto_scripts', static_opts) end @@ -26,6 +27,16 @@ def self.script_options_from_directory(dir) [File.basename(file), file] end.sort_by(&:first) end + + def self.default_value(initial_opts, script_opts) + if initial_opts[:value] && script_opts && script_opts.none? { |opt| opt.include?(initial_opts[:value]) } + initial_opts.delete(:value) + end + + return nil if !initial_opts[:value] && script_opts.empty? + + (initial_opts[:value] || script_opts.first.last).to_s + end end module Attributes diff --git a/apps/dashboard/app/models/launcher.rb b/apps/dashboard/app/models/launcher.rb index 930ebd2b1c..f63cee97b5 100644 --- a/apps/dashboard/app/models/launcher.rb +++ b/apps/dashboard/app/models/launcher.rb @@ -344,15 +344,6 @@ def add_script_to_form(form: [], attributes: {}) else dir end - - # Delete 'value' if it does not exist in the available options - # so that projects created from templates don't point to another - # user's script - script_options = attributes[:auto_scripts]['options'] - return unless script_options - - script_value = attributes[:auto_scripts]['value'] - attributes[:auto_scripts].delete('value') if script_options.none? { |opt| opt.include?(script_value) } end def add_cluster_to_form(form: [], attributes: {}) From e444b4c1a3acf3d03cc89c34b0bbc98f11d5d7db Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 19 Sep 2024 12:14:37 -0400 Subject: [PATCH 10/16] fix a test and add another --- .../test/lib/smart_attributes/auto_scripts_test.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/test/lib/smart_attributes/auto_scripts_test.rb b/apps/dashboard/test/lib/smart_attributes/auto_scripts_test.rb index 76e4cc3f14..7acecacfaa 100644 --- a/apps/dashboard/test/lib/smart_attributes/auto_scripts_test.rb +++ b/apps/dashboard/test/lib/smart_attributes/auto_scripts_test.rb @@ -9,7 +9,7 @@ def fixture_dir end test 'can correctly set the value when scripts directory is configured' do - value = '/test/script/executable.sh' + value = "#{fixture_dir}/script4.slurm" attribute = SmartAttributes::AttributeFactory.build('auto_scripts', { directory: fixture_dir, value: value }) assert_instance_of SmartAttributes::Attributes::AutoScripts, attribute @@ -57,4 +57,12 @@ def fixture_dir assert_instance_of SmartAttributes::Attributes::AutoScripts, attribute assert_equal('select', File.basename(attribute.widget)) end + + test 'correctly sets value when previous value is invalid' do + value = '/test/invalid/script.sh' + attribute = SmartAttributes::AttributeFactory.build('auto_scripts', { directory: fixture_dir, value: value }) + + assert_instance_of SmartAttributes::Attributes::AutoScripts, attribute + assert_equal(attribute.select_choices[0].last, attribute.value) + end end From 485e021f9117a7dc6c5fc0ed4a7dc128e0264d82 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Mon, 23 Sep 2024 13:39:59 -0400 Subject: [PATCH 11/16] reset invalid scripts but not empty values --- .../app/lib/smart_attributes/attributes/auto_scripts.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb index 84478ca319..749ddf0353 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb @@ -29,11 +29,9 @@ def self.script_options_from_directory(dir) end def self.default_value(initial_opts, script_opts) - if initial_opts[:value] && script_opts && script_opts.none? { |opt| opt.include?(initial_opts[:value]) } - initial_opts.delete(:value) - end + return nil if !initial_opts[:value] || script_opts.empty? - return nil if !initial_opts[:value] && script_opts.empty? + initial_opts.delete(:value) if script_opts&.none? { |opt| opt.include?(initial_opts[:value]) } (initial_opts[:value] || script_opts.first.last).to_s end From 4b2af251f1dfe78fd36b23c696222814f75790dd Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 26 Sep 2024 09:20:43 -0400 Subject: [PATCH 12/16] keep valid script but change directory --- .../lib/smart_attributes/attributes/auto_scripts.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb index 749ddf0353..d86789bb52 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb @@ -14,7 +14,7 @@ def self.build_auto_scripts(opts = {}) static_opts = { options: options, - value: default_value(opts, options) + value: default_script_value(opts, options, dir) }.merge(opts.without(:options, :value).to_h) Attributes::AutoScripts.new('auto_scripts', static_opts) @@ -28,10 +28,16 @@ def self.script_options_from_directory(dir) end.sort_by(&:first) end - def self.default_value(initial_opts, script_opts) + def self.default_script_value(initial_opts, script_opts, dir) return nil if !initial_opts[:value] || script_opts.empty? - initial_opts.delete(:value) if script_opts&.none? { |opt| opt.include?(initial_opts[:value]) } + # Replace directory if the script is present in correct directory, otherwise delete value + swapped_dir = "#{dir}/#{File.basename(initial_opts[:value])}" + if script_opts.any?(swapped_dir) + initial_opts[:value] = swapped_dir + elsif script_opts&.none? { |opt| opt.include?(initial_opts[:value]) } + initial_opts.delete(:value) + end (initial_opts[:value] || script_opts.first.last).to_s end From 43289e6b51849f52b52a8c9e05050708759e39af Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 26 Sep 2024 10:32:17 -0400 Subject: [PATCH 13/16] simplify check for script of the same name --- .../lib/smart_attributes/attributes/auto_scripts.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb index d86789bb52..c3c956165c 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb @@ -14,7 +14,7 @@ def self.build_auto_scripts(opts = {}) static_opts = { options: options, - value: default_script_value(opts, options, dir) + value: default_script_value(opts, options) }.merge(opts.without(:options, :value).to_h) Attributes::AutoScripts.new('auto_scripts', static_opts) @@ -28,13 +28,13 @@ def self.script_options_from_directory(dir) end.sort_by(&:first) end - def self.default_script_value(initial_opts, script_opts, dir) + def self.default_script_value(initial_opts, script_opts) return nil if !initial_opts[:value] || script_opts.empty? # Replace directory if the script is present in correct directory, otherwise delete value - swapped_dir = "#{dir}/#{File.basename(initial_opts[:value])}" - if script_opts.any?(swapped_dir) - initial_opts[:value] = swapped_dir + valid_opt = script_opts.select { |opt| opt.first == File.basename(initial_opts[:value]) }.first + if valid_opt + initial_opts[:value] = valid_opt.last elsif script_opts&.none? { |opt| opt.include?(initial_opts[:value]) } initial_opts.delete(:value) end From 27fe98e0644706f7d41d550a548f7a80022c66a4 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Mon, 30 Sep 2024 15:17:14 -0400 Subject: [PATCH 14/16] swap value and directory in system test --- apps/dashboard/test/system/project_manager_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/test/system/project_manager_test.rb b/apps/dashboard/test/system/project_manager_test.rb index e06af3671d..aadbf3d6b2 100644 --- a/apps/dashboard/test/system/project_manager_test.rb +++ b/apps/dashboard/test/system/project_manager_test.rb @@ -582,8 +582,8 @@ def add_auto_environment_variable(project_id, script_id, save: true) - "#{dir}/projects/#{project_id}/my_cool_script.sh" - - my_cooler_script.bash - "#{dir}/projects/#{project_id}/my_cooler_script.bash" - directory: "#{dir}/projects/#{project_id}" value: "#{dir}/projects/#{project_id}/my_cool_script.sh" + directory: "#{dir}/projects/#{project_id}" label: Script help: '' required: false @@ -688,8 +688,8 @@ def add_auto_environment_variable(project_id, script_id, save: true) - "#{dir}/projects/#{project_id}/my_cool_script.sh" - - my_cooler_script.bash - "#{dir}/projects/#{project_id}/my_cooler_script.bash" - directory: "#{dir}/projects/#{project_id}" value: "#{dir}/projects/#{project_id}/my_cool_script.sh" + directory: "#{dir}/projects/#{project_id}" label: Script help: '' required: false From 40d653b3890c74a8c3646f26776e518bbb64df91 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Mon, 30 Sep 2024 15:53:17 -0400 Subject: [PATCH 15/16] Revert "update fixed checkbox when environment variable changes" This reverts commit f221f5cbdebfe1d9d9dce2c93d91435c1036871a. --- .../dashboard/app/javascript/launcher_edit.js | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/apps/dashboard/app/javascript/launcher_edit.js b/apps/dashboard/app/javascript/launcher_edit.js index d7d58d2023..013a2c3d58 100644 --- a/apps/dashboard/app/javascript/launcher_edit.js +++ b/apps/dashboard/app/javascript/launcher_edit.js @@ -166,35 +166,16 @@ function addInProgressField(event) { function updateAutoEnvironmentVariable(event) { const 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}]`; - const input_field = event.target.parentElement.children[2].children[1]; - const oldId = input_field.id; + var input_field = event.target.parentElement.children[2].children[1]; input_field.removeAttribute('readonly'); - input_field.id = idString; - input_field.name = nameString; + input_field.id = `launcher_auto_environment_variable_${aev_name}`; + input_field.name = `launcher[auto_environment_variable_${aev_name}]`; if (labelString.match(/Environment( |\s)Variable/)) { const 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 - const fixedBoxGroup = event.target.parentElement.querySelector('.list-group-item'); - const checkbox = fixedBoxGroup.querySelector("input[type='checkbox']"); - 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 - if(fixedBoxGroup.children.length == 3) { - const hiddenField = fixedBoxGroup.querySelector("input[type='hidden']"); - hiddenField.name = nameString; - } - - const fixedLabel = fixedBoxGroup.querySelector('label'); - fixedLabel.setAttribute('for', `${idString}_fixed`); } function fixExcludeBasedOnSelect(selectElement) { From a66184e39ac6f933a902b7f6e11edb155c5f60e3 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 3 Oct 2024 09:14:53 -0400 Subject: [PATCH 16/16] restructure default_script_value --- .../attributes/auto_scripts.rb | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb index c3c956165c..a2bb495a0a 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb @@ -14,7 +14,7 @@ def self.build_auto_scripts(opts = {}) static_opts = { options: options, - value: default_script_value(opts, options) + value: default_script_value(opts[:value], options) }.merge(opts.without(:options, :value).to_h) Attributes::AutoScripts.new('auto_scripts', static_opts) @@ -28,18 +28,14 @@ def self.script_options_from_directory(dir) end.sort_by(&:first) end - def self.default_script_value(initial_opts, script_opts) - return nil if !initial_opts[:value] || script_opts.empty? - - # Replace directory if the script is present in correct directory, otherwise delete value - valid_opt = script_opts.select { |opt| opt.first == File.basename(initial_opts[:value]) }.first - if valid_opt - initial_opts[:value] = valid_opt.last - elsif script_opts&.none? { |opt| opt.include?(initial_opts[:value]) } - initial_opts.delete(:value) + def self.default_script_value(default, scripts) + if !default || scripts.empty? + nil + elsif scripts.none? { |s| s[0] == File.basename(default) } + scripts.first[1].to_s + else + scripts.select { |s| s[0] == File.basename(default) }.first[1] end - - (initial_opts[:value] || script_opts.first.last).to_s end end