-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the auto_scripts smart attribute and go ahead and add cluster config too This also fixed next_id not working right and form_item_id needs to be a symbol.
- Loading branch information
Showing
3 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
apps/dashboard/app/lib/smart_attributes/attributes/auto_scripts.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
module SmartAttributes | ||
class AttributeFactory | ||
|
||
AUTO_SCRIPT_EXTENSIONS = ['sh', 'csh', 'bash', 'slurm', 'sbatch', 'qsub'].freeze | ||
|
||
# Build this attribute object. Must specify a valid directory in opts | ||
# | ||
# @param opts [Hash] attribute's options | ||
# @return [Attributes::AutoScripts] the attribute object | ||
def self.build_auto_scripts(opts = {}) | ||
dir = Pathname.new(opts[:directory].to_s) | ||
options = script_options_from_directory(dir) | ||
|
||
static_opts = { | ||
options: options | ||
}.merge(opts.without(:options).to_h) | ||
|
||
Attributes::AutoScripts.new('auto_scripts', static_opts) | ||
end | ||
|
||
def self.script_options_from_directory(dir) | ||
return [] unless dir.directory? && dir.readable? | ||
|
||
Dir.glob("#{dir}/*.{#{AUTO_SCRIPT_EXTENSIONS.join(',')}}").map do |file| | ||
[File.basename(file), file] | ||
end | ||
end | ||
end | ||
|
||
module Attributes | ||
class AutoScripts < Attribute | ||
def widget | ||
'select' | ||
end | ||
|
||
def label(*) | ||
(opts[:label] || 'Script').to_s | ||
end | ||
|
||
# Submission hash describing how to submit this attribute | ||
# @param fmt [String, nil] formatting of hash | ||
# @return [Hash] submission hash | ||
def submit(*) | ||
content = File.read(value) | ||
{ script: { content: content } } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters