Merge branch '4359-project-paging' closes #4359
authorTom Clegg <tom@curoverse.com>
Thu, 30 Oct 2014 20:30:56 +0000 (16:30 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 30 Oct 2014 20:30:56 +0000 (16:30 -0400)
apps/workbench/app/assets/javascripts/filterable.js
apps/workbench/app/models/pipeline_instance.rb
apps/workbench/test/unit/pipeline_instance_test.rb

index d14551cc9a8fd34eaa633db79cb296705aeacfba..8ac195383b40027b39ef3062b1cb6e67c90fe41e 100644 (file)
@@ -1,3 +1,54 @@
+// filterable.js shows/hides content when the user operates
+// search/select widgets. For "infinite scroll" content, it passes the
+// filters to the server and retrieves new content. For other content,
+// it filters the existing DOM elements using jQuery show/hide.
+//
+// Usage:
+//
+// 1. Add the "filterable" class to each filterable content item.
+// Typically, each item is a 'tr' or a 'div class="row"'.
+//
+// <div id="results">
+//   <div class="filterable row">First row</div>
+//   <div class="filterable row">Second row</div>
+// </div>
+//
+// 2. Add the "filterable-control" class to each search/select widget.
+// Also add a data-filterable-target attribute with a jQuery selector
+// for an ancestor of the filterable items, i.e., the container in
+// which this widget should apply filtering.
+//
+// <input class="filterable-control" data-filterable-target="#results"
+//        type="text" />
+//
+// Supported widgets:
+//
+// <input type="text" ... />
+//
+// The input value is used as a regular expression. Rows with content
+// matching the regular expression are shown.
+//
+// <select ... data-filterable-attribute="data-example-attr">
+//  <option value="foo">Foo</option>
+//  <option value="">Show all</option>
+// </select>
+//
+// When the user selects the "Foo" option, rows with
+// data-example-attr="foo" are shown, and all others are hidden. When
+// the user selects the "Show all" option, all rows are shown.
+//
+// Notes:
+//
+// When multiple filterable-control widgets operate on the same
+// data-filterable-target, items must pass _all_ filters in order to
+// be shown.
+//
+// If one data-filterable-target is the parent of another
+// data-filterable-target, results are undefined. Don't do this.
+//
+// Combining "select" filterable-controls with infinite-scroll is not
+// yet supported.
+
 $(document).
     on('paste keyup input', 'input[type=text].filterable-control', function() {
         var $target = $($(this).attr('data-filterable-target'));
index 83328b9e52ce31dd126812ba874de766282fb93c..f575e20d4ea964355dda807bbafd5d21a33892e9 100644 (file)
@@ -52,7 +52,11 @@ class PipelineInstance < ArvadosBase
   end
 
   def attribute_editable?(name, ever=nil)
-    (ever or %w(New Ready).include?(state)) and super
+    if name.to_s == "components"
+      (ever or %w(New Ready).include?(state)) and super
+    else
+      super
+    end
   end
 
   def attributes_for_display
index 95ad8fa7cd11bf4abaabd7d04712945071255d28..4cad6e64b604b06858267055a60f81a25d13c096 100644 (file)
@@ -1,31 +1,49 @@
 require 'test_helper'
 
 class PipelineInstanceTest < ActiveSupport::TestCase
+  def attribute_editable_for?(token_name, pi_name, attr_name, ever=nil)
+    use_token token_name
+    find_fixture(PipelineInstance, pi_name).attribute_editable?(attr_name, ever)
+  end
+
   test "admin can edit name" do
-    use_token :admin
-    assert(find_fixture(PipelineInstance, "new_pipeline_in_subproject")
-             .attribute_editable?("name"),
+    assert(attribute_editable_for?(:admin, "new_pipeline_in_subproject",
+                                   "name"),
            "admin not allowed to edit pipeline instance name")
   end
 
   test "project owner can edit name" do
-    use_token :active
-    assert(find_fixture(PipelineInstance, "new_pipeline_in_subproject")
-             .attribute_editable?("name"),
+    assert(attribute_editable_for?(:active, "new_pipeline_in_subproject",
+                                   "name"),
            "project owner not allowed to edit pipeline instance name")
   end
 
   test "project admin can edit name" do
-    use_token :subproject_admin
-    assert(find_fixture(PipelineInstance, "new_pipeline_in_subproject")
-             .attribute_editable?("name"),
+    assert(attribute_editable_for?(:subproject_admin,
+                                   "new_pipeline_in_subproject", "name"),
            "project admin not allowed to edit pipeline instance name")
   end
 
   test "project viewer cannot edit name" do
-    use_token :project_viewer
-    refute(find_fixture(PipelineInstance, "new_pipeline_in_subproject")
-             .attribute_editable?("name"),
+    refute(attribute_editable_for?(:project_viewer,
+                                   "new_pipeline_in_subproject", "name"),
            "project viewer allowed to edit pipeline instance name")
   end
+
+  test "name editable on completed pipeline" do
+    assert(attribute_editable_for?(:active, "has_component_with_completed_jobs",
+                                   "name"),
+           "name not editable on complete pipeline")
+  end
+
+  test "components editable on new pipeline" do
+    assert(attribute_editable_for?(:active, "new_pipeline", "components"),
+           "components not editable on new pipeline")
+  end
+
+  test "components not editable on completed pipeline" do
+    refute(attribute_editable_for?(:active, "has_component_with_completed_jobs",
+                                   "components"),
+           "components not editable on new pipeline")
+  end
 end