Moved code specific to editing pipelines from editable.js to pipeline_instance.js.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Thu, 27 Feb 2014 21:16:08 +0000 (16:16 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Thu, 27 Feb 2014 21:16:08 +0000 (16:16 -0500)
Improved detection of paramater data type to choose the right editing control.

apps/workbench/app/assets/javascripts/editable.js
apps/workbench/app/assets/javascripts/pipeline_instances.js [new file with mode: 0644]
apps/workbench/app/assets/javascripts/pipeline_instances.js.coffee [deleted file]
apps/workbench/app/helpers/application_helper.rb
apps/workbench/app/views/pipeline_instances/_show_components.html.erb

index 9418fb2e0d6dfb3a368a710085b8f2a6816591d6..a74358694213fe36041d32852111741bf1581f1a 100644 (file)
@@ -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 (file)
index 0000000..ee14e3b
--- /dev/null
@@ -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 (file)
index 7615679..0000000
+++ /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/
index 2c2316b0b7667fae44bcedae44c2354a8078245d..6de96e8995638aa3c4525ebe489218ff5680df31 100644 (file)
@@ -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("<span class='label label-default'>#{template[:output_of]}</span>")
         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)
index 1148bffe47b4ccda0525b0e10507ee3e47d9d11f..af6da56ca468abcd69cfa3aa47f731476d90c974 100644 (file)
@@ -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 %>
 
 <table class="table pipeline-components-table" style="margin-top: -.1em">