From 9e778a62184d4604f62e6c30fec8d1be1781de4b Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Thu, 27 Feb 2014 16:16:08 -0500 Subject: [PATCH] Moved code specific to editing pipelines from editable.js to pipeline_instance.js. Improved detection of paramater data type to choose the right editing control. --- .../app/assets/javascripts/editable.js | 32 ----------- .../assets/javascripts/pipeline_instances.js | 46 +++++++++++++++ .../javascripts/pipeline_instances.js.coffee | 3 - .../app/helpers/application_helper.rb | 56 ++++++++++++------- .../_show_components.html.erb | 2 +- 5 files changed, 82 insertions(+), 57 deletions(-) create mode 100644 apps/workbench/app/assets/javascripts/pipeline_instances.js delete mode 100644 apps/workbench/app/assets/javascripts/pipeline_instances.js.coffee diff --git a/apps/workbench/app/assets/javascripts/editable.js b/apps/workbench/app/assets/javascripts/editable.js index 9418fb2e0d..a743586942 100644 --- a/apps/workbench/app/assets/javascripts/editable.js +++ b/apps/workbench/app/assets/javascripts/editable.js @@ -9,35 +9,3 @@ $.fn.editable.defaults.params = function (params) { a[key][params.name] = params.value; return a; }; - -(function() { - $.fn.editable.defaults.success = function (response, newValue) { - var tag = $(this); - if (tag.hasClass("required")) { - if (newValue && newValue.trim() != "") { - tag.parent().css("background-color", ""); - tag.parent().prev().css("background-color", ""); - } - else { - tag.parent().css("background-color", "#ffdddd"); - tag.parent().prev().css("background-color", "#ffdddd"); - } - } - } - - $(window).on('load', function() { - var a = $('a.editable.required'); - for (var i = 0; i < a.length; i++) { - var tag = $(a[i]); - if (tag.hasClass("editable-empty")) { - tag.parent().css("background-color", "#ffdddd"); - tag.parent().prev().css("background-color", "#ffdddd"); - } - else { - tag.parent().css("background-color", ""); - tag.parent().prev().css("background-color", ""); - } - } - } ); - -})(); diff --git a/apps/workbench/app/assets/javascripts/pipeline_instances.js b/apps/workbench/app/assets/javascripts/pipeline_instances.js new file mode 100644 index 0000000000..ee14e3b781 --- /dev/null +++ b/apps/workbench/app/assets/javascripts/pipeline_instances.js @@ -0,0 +1,46 @@ + +(function() { + var run_pipeline_button_state = function() { + var a = $('a.editable.required.editable-empty'); + if (a.length > 0) { + $("#run-pipeline-button").addClass("disabled"); + } + else { + $("#run-pipeline-button").removeClass("disabled"); + } + } + + $.fn.editable.defaults.success = function (response, newValue) { + var tag = $(this); + if (tag.hasClass("required")) { + if (newValue && newValue.trim() != "") { + tag.removeClass("editable-empty"); + tag.parent().css("background-color", ""); + tag.parent().prev().css("background-color", ""); + } + else { + tag.addClass("editable-empty"); + tag.parent().css("background-color", "#ffdddd"); + tag.parent().prev().css("background-color", "#ffdddd"); + } + } + run_pipeline_button_state(); + } + + $(window).on('load', function() { + var a = $('a.editable.required'); + for (var i = 0; i < a.length; i++) { + var tag = $(a[i]); + if (tag.hasClass("editable-empty")) { + tag.parent().css("background-color", "#ffdddd"); + tag.parent().prev().css("background-color", "#ffdddd"); + } + else { + tag.parent().css("background-color", ""); + tag.parent().prev().css("background-color", ""); + } + } + run_pipeline_button_state(); + } ); + +})(); diff --git a/apps/workbench/app/assets/javascripts/pipeline_instances.js.coffee b/apps/workbench/app/assets/javascripts/pipeline_instances.js.coffee deleted file mode 100644 index 761567942f..0000000000 --- a/apps/workbench/app/assets/javascripts/pipeline_instances.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb index 2c2316b0b7..6de96e8995 100644 --- a/apps/workbench/app/helpers/application_helper.rb +++ b/apps/workbench/app/helpers/application_helper.rb @@ -118,13 +118,13 @@ module ApplicationHelper datatype = nil required = true if template - puts "Template is #{template.class} #{template.is_a? Hash} #{template}" + #puts "Template is #{template.class} #{template.is_a? Hash} #{template}" if template.is_a? Hash if template[:output_of] return raw("#{template[:output_of]}") end - if template[:datatype] - datatype = template[:datatype] + if template[:dataclass] + dataclass = template[:dataclass] end if template[:optional] != nil required = (template[:optional] != "true") @@ -137,19 +137,31 @@ module ApplicationHelper return attrvalue if !object.attribute_editable? attr - if not datatype - dataclass = ArvadosBase.resource_class_for_uuid(template) - if dataclass - datatype = 'select' - else - if template.is_a? Array - # ?!? - elsif template.is_a? String - if /^\d+$/.match(template) - datatype = 'number' - else - datatype = 'text' - end + if not dataclass + rsc = template + if template.is_a? Hash + if template[:value] + rsc = template[:value] + elsif template[:default] + rsc = template[:default] + end + end + + dataclass = ArvadosBase.resource_class_for_uuid(rsc) + end + + if dataclass && dataclass.is_a?(Class) + datatype = 'select' + elsif dataclass == 'number' + datatype = 'number' + else + if template.is_a? Array + # ?!? + elsif template.is_a? String + if /^\d+$/.match(template) + datatype = 'number' + else + datatype = 'text' end end end @@ -164,12 +176,13 @@ module ApplicationHelper attrvalue = attrvalue.strip end - if dataclass + if dataclass and dataclass.is_a? Class items = [] - dataclass.where(uuid: attrvalue).each do |item| - items.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s}) - end - dataclass.limit(19).each do |item| + items.append({name: attrvalue, uuid: attrvalue, type: dataclass.to_s}) + #dataclass.where(uuid: attrvalue).each do |item| + # items.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s}) + #end + dataclass.limit(10).each do |item| items.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s}) end end @@ -183,6 +196,7 @@ module ApplicationHelper "data-name" => dn, "data-pk" => "{id: \"#{object.uuid}\", key: \"#{object.class.to_s.underscore}\"}", "data-showbuttons" => "false", + "data-value" => attrvalue, :class => "editable #{'required' if required}", :id => id }.merge(htmloptions) diff --git a/apps/workbench/app/views/pipeline_instances/_show_components.html.erb b/apps/workbench/app/views/pipeline_instances/_show_components.html.erb index 1148bffe47..af6da56ca4 100644 --- a/apps/workbench/app/views/pipeline_instances/_show_components.html.erb +++ b/apps/workbench/app/views/pipeline_instances/_show_components.html.erb @@ -104,7 +104,7 @@ setInterval(function(){$('a.refresh').click()}, 30000); <%= form_tag @object, :method => :put do |f| %> <%= hidden_field @object.class.to_s.underscore.singularize.to_sym, :active, :value => true %> - <%= button_tag "Run pipeline", {class: 'btn btn-primary pull-right'} %> + <%= button_tag "Run pipeline", {class: 'btn btn-primary pull-right', id: "run-pipeline-button"} %> <% end %> -- 2.30.2