11580: add container_requests index page
authorradhika <radhika@curoverse.com>
Tue, 16 May 2017 00:09:25 +0000 (20:09 -0400)
committerradhika <radhika@curoverse.com>
Wed, 17 May 2017 18:28:15 +0000 (14:28 -0400)
apps/workbench/app/views/container_requests/_show_recent.html.erb [new file with mode: 0644]
apps/workbench/app/views/container_requests/_show_recent_rows.html.erb [new file with mode: 0644]
apps/workbench/app/views/container_requests/index.html.erb [new file with mode: 0644]
apps/workbench/test/integration/container_requests_test.rb

diff --git a/apps/workbench/app/views/container_requests/_show_recent.html.erb b/apps/workbench/app/views/container_requests/_show_recent.html.erb
new file mode 100644 (file)
index 0000000..546b076
--- /dev/null
@@ -0,0 +1,37 @@
+<%= form_tag({}, {id: "containerRequests"}) do |f| %>
+
+<table class="table table-condensed table-fixedlayout arv-recent-container-requests">
+  <colgroup>
+    <col width="10%" />
+    <col width="15%" />
+    <col width="25%" />
+    <col width="15%" />
+    <col width="15%" />
+    <col width="15%" />
+    <col width="5%" />
+  </colgroup>
+  <thead>
+    <tr class="contain-align-left">
+      <th>
+        Status
+      </th><th>
+        ContainerRequest
+      </th><th>
+        Description
+      </th><th>
+        Workflow
+      </th><th>
+        Owner
+      </th><th>
+        Created at
+      </th><th>
+      </th>
+    </tr>
+  </thead>
+
+  <tbody data-infinite-scroller="#recent-container-requests" id="recent-container-requests"
+         data-infinite-content-href="<%= url_for partial: :recent_rows %>" >
+  </tbody>
+</table>
+
+<% end %>
diff --git a/apps/workbench/app/views/container_requests/_show_recent_rows.html.erb b/apps/workbench/app/views/container_requests/_show_recent_rows.html.erb
new file mode 100644 (file)
index 0000000..d11bf35
--- /dev/null
@@ -0,0 +1,36 @@
+<%
+  containers = @objects.map(&:container_uuid).compact.uniq
+  preload_objects_for_dataclass(Container, containers) if containers.any?
+
+  workflows = @objects.collect {|o| o.properties[:template_uuid]}.compact.uniq
+  preload_objects_for_dataclass(Workflow, workflows) if workflows.any?
+
+  owner_uuids = @objects.map(&:owner_uuid).compact.uniq
+  preload_objects_for_dataclass(User, owner_uuids) if owner_uuids.any?
+  preload_objects_for_dataclass(Group, owner_uuids) if owner_uuids.any?
+
+  objs = containers + workflows + owner_uuids
+  preload_links_for_objects objs if objs.any?
+%>
+
+<% @objects.sort_by { |obj| obj.created_at }.reverse.each do |obj| %>
+  <% wu = obj.work_unit obj.name %>
+
+  <tr data-object-uuid="<%= wu.uuid %>" class="cr-<%= wu.uuid %>">
+    <td>
+      <span class="label label-<%= wu.state_bootstrap_class %>"><%= wu.state_label %></span>
+    </td><td>
+      <%= link_to_if_arvados_object obj, friendly_name: true %>
+    </td><td>
+      <%= obj.description || '' %>
+    </td><td>
+      <%= link_to_if_arvados_object wu.template_uuid, friendly_name: true %>
+    </td><td>
+      <%= link_to_if_arvados_object wu.owner_uuid, friendly_name: true %>
+    </td><td>
+      <%= wu.created_at.to_s %>
+    </td><td>
+      <%= render partial: 'delete_object_button', locals: {object:obj} %>
+    </td>
+  </tr>
+<% end %>
diff --git a/apps/workbench/app/views/container_requests/index.html.erb b/apps/workbench/app/views/container_requests/index.html.erb
new file mode 100644 (file)
index 0000000..f0a8959
--- /dev/null
@@ -0,0 +1,11 @@
+<% content_for :tab_line_buttons do %>
+  <div class="input-group">
+    <input type="text" class="form-control filterable-control recent-container-requests-filterable-control"
+           placeholder="Search container requests"
+           data-filterable-target="#recent-container-requests"
+           value="<%= params[:search] %>"
+           />
+  </div>
+<% end %>
+
+<%= render file: 'application/index.html.erb', locals: local_assigns %>
index 46f7e171fb21a7b6ebcb8402ec4b202775351bea..51b6b247bf7f4e33593adecc93807aa8c21a6f8b 100644 (file)
@@ -121,4 +121,41 @@ class ContainerRequestsTest < ActionDispatch::IntegrationTest
     page.assert_selector 'ellipse+text', text: cr['name'], visible: false
     page.assert_selector 'g.node>title', text: cr['uuid'], visible: false
   end
+
+  [
+    'active',
+    'admin',
+  ].each do |token|
+    test "index page as #{token} user" do
+      visit page_with_token(token, "/container_requests")
+
+      running_owner_active = api_fixture("container_requests", "requester_for_running")
+      anon_accessible_cr = api_fixture("container_requests", "running_anonymous_accessible")
+
+      # both of these CRs should be accessible to the user
+      assert_selector "a[href=\"/container_requests/#{running_owner_active['uuid']}\"]", text: running_owner_active[:name]
+      assert_selector "a[href=\"/container_requests/#{anon_accessible_cr['uuid']}\"]", text: anon_accessible_cr[:name]
+
+      # both the active user (owner) and admin can delete the "running" container_request
+      within(".cr-#{running_owner_active['uuid']}") do
+        assert_not_nil first('.glyphicon-trash')
+      end
+
+      # only admin user can delete the anonymously accessible container_request
+      within(".cr-#{anon_accessible_cr['uuid']}") do
+        if token == 'admin'
+          assert_not_nil first('.glyphicon-trash')
+        else
+          assert_nil first('.glyphicon-trash')
+        end
+      end
+
+      # verify the search box in the page
+      find('.recent-container-requests-filterable-control').set("anonymous")
+      sleep 0.350 # Wait for 250ms debounce timer (see filterable.js)
+      wait_for_ajax
+      assert_no_selector "a[href=\"/container_requests/#{running_owner_active['uuid']}\"]", text: running_owner_active[:name]
+      assert_selector "a[href=\"/container_requests/#{anon_accessible_cr['uuid']}\"]", text: anon_accessible_cr[:name]
+    end
+  end
 end