[ARVADOS] created: 555c1e920855989e059a4be0503ebb627193f987

git at public.curoverse.com git at public.curoverse.com
Thu Sep 11 17:32:55 EDT 2014


        at  555c1e920855989e059a4be0503ebb627193f987 (commit)


commit 555c1e920855989e059a4be0503ebb627193f987
Author: Phil Hodgson <bitbucket at philhodgson.net>
Date:   Thu Sep 11 17:30:59 2014 -0400

    3338: System in place that allows for item counts to be displayed next to tab titles via AJAX.
    (Currently does not refresh itself after activities such as adding or removing items, but this is now eminently possible.)

diff --git a/apps/workbench/app/assets/javascripts/tab_panes.js b/apps/workbench/app/assets/javascripts/tab_panes.js
index 411a009..22d6de1 100644
--- a/apps/workbench/app/assets/javascripts/tab_panes.js
+++ b/apps/workbench/app/assets/javascripts/tab_panes.js
@@ -75,3 +75,11 @@ $(document).on('arv:pane:reload', '.tab-pane', function() {
 $(document).on('arv-log-event arv:pane:reload:all', function() {
     $('.tab-pane.loaded').trigger('arv:pane:reload');
 });
+
+// If there is a 'tab counts url' in the nav-tabs element then use it to get some javascript that will update them
+$(document).on('ready', function() {
+    var tabCountsUrl = $('ul.nav-tabs').data('tab-counts-url');
+    if( tabCountsUrl && tabCountsUrl.length ) {
+        $.get( tabCountsUrl );
+    }
+});
diff --git a/apps/workbench/app/controllers/projects_controller.rb b/apps/workbench/app/controllers/projects_controller.rb
index 1e06b0a..573e387 100644
--- a/apps/workbench/app/controllers/projects_controller.rb
+++ b/apps/workbench/app/controllers/projects_controller.rb
@@ -32,12 +32,35 @@ class ProjectsController < ApplicationController
     %w(Projects)
   end
 
+  # Returning an array of hashes instead of an array of strings will allow
+  # us to tell the interface to get counts for each pane (using :filters).
+  # It also seems to me that something like these could be used to configure the contents of the panes.
   def show_pane_list
-    if @user_is_manager
-      %w(Data_collections Jobs_and_pipelines Pipeline_templates Subprojects Other_objects Sharing Advanced)
-    else
-      %w(Data_collections Jobs_and_pipelines Pipeline_templates Subprojects Other_objects Advanced)
-    end
+    pane_list = [
+      {
+        :name => 'Data_collections',
+        :filters => [%w(uuid is_a arvados#collection)]
+      },
+      {
+        :name => 'Jobs_and_pipelines',
+        :filters => [%w(uuid is_a) + [%w(arvados#job arvados#pipelineInstance)]]
+      },
+      {
+        :name => 'Pipeline_templates',
+        :filters => [%w(uuid is_a arvados#pipelineTemplate)]
+      },
+      {
+        :name => 'Subprojects',
+        :filters => [%w(uuid is_a arvados#group)]
+      },
+      { :name => 'Other_objects',
+        :filters => [%w(uuid is_a) + [%w(arvados#human arvados#specimen arvados#trait)]]
+      }
+    ]
+    # Note that adding :filters to 'Sharing' won't help show the count for it because @user_is_manager is only set in #show
+    # Therefore if a count were desired there we'd want to set @user_is_manager in a before_filter or somesuch.
+    pane_list << { :name => 'Sharing' } if @user_is_manager
+    pane_list << { :name => 'Advanced' }
   end
 
   def remove_item
diff --git a/apps/workbench/app/views/application/_content.html.erb b/apps/workbench/app/views/application/_content.html.erb
index 4379758..8ec92bf 100644
--- a/apps/workbench/app/views/application/_content.html.erb
+++ b/apps/workbench/app/views/application/_content.html.erb
@@ -1,34 +1,40 @@
 <% content_for :tab_panes do %>
 
-<% comparable = controller.respond_to? :compare %>
+  <% comparable = controller.respond_to? :compare %>
 
-<ul class="nav nav-tabs">
-  <% pane_list.each_with_index do |pane, i| %>
-    <li class="<%= 'active' if i==0 %>"><a href="#<%= pane %>" data-toggle="tab" id="<%= pane %>-tab" data-pane-content-url="<%= url_for(params.merge(tab_pane: pane)) %>"> <%= pane.gsub('_', ' ') %></a></li>
-  <% end %>
-</ul>
-<div class="tab-content">
-<% pane_list.each_with_index do |pane, i| %>
-  <div id="<%= pane %>"
-       class="tab-pane fade <%= 'in active loaded' if i==0 %> arv-log-event-listener"
-<% if controller.action_name == "index" %>
-       data-object-kind="arvados#<%= ArvadosApiClient.class_kind controller.model_class %>"
-<% else %>
-       data-object-uuid="<%= @object.uuid %>"
-<% end %>
-  >
+  <ul class="nav nav-tabs" data-tab-counts-url="<%= url_for(action: :tab_counts) rescue '' %>">
+    <% pane_list.each_with_index do |pane, i| %>
+      <% pane_name = (pane.is_a?(Hash) ? pane[:name] : pane) %>
+      <li class="<%= 'active' if i==0 %>">
+        <a href="#<%= pane_name %>" data-toggle="tab" id="<%= pane_name %>-tab" data-pane-content-url="<%= url_for(params.merge(tab_pane: pane_name)) %>">
+          <%= pane_name.gsub('_', ' ') %> <span id="<%= pane_name %>-count"></span>
+        </a>
+      </li>
+    <% end %>
+  </ul>
 
-    <div id="<%= pane %>-scroll" style="margin-top:0.5em;">
-      <div class="pane-content">
-        <% if i == 0 %>
-          <%= render_pane pane, to_string: true %>
-        <% else %>
-          <div class="spinner spinner-32px spinner-h-center"></div>
-        <% end %>
+  <div class="tab-content">
+    <% pane_list.each_with_index do |pane, i| %>
+      <% pane_name = (pane.is_a?(Hash) ? pane[:name] : pane) %>
+      <div id="<%= pane_name %>"
+           class="tab-pane fade <%= 'in active loaded' if i==0 %> arv-log-event-listener"
+           <% if controller.action_name == "index" %>
+             data-object-kind="arvados#<%= ArvadosApiClient.class_kind controller.model_class %>"
+           <% else %>
+             data-object-uuid="<%= @object.uuid %>"
+           <% end %>
+      >
+        <div id="<%= pane_name %>-scroll" style="margin-top:0.5em;">
+          <div class="pane-content">
+            <% if i == 0 %>
+              <%= render_pane pane_name, to_string: true %>
+            <% else %>
+              <div class="spinner spinner-32px spinner-h-center"></div>
+            <% end %>
+          </div>
+        </div>
       </div>
-    </div>
+    <% end %>
   </div>
-<% end %>
-</div>
 
 <% end %>
diff --git a/apps/workbench/app/views/projects/tab_counts.js.erb b/apps/workbench/app/views/projects/tab_counts.js.erb
new file mode 100644
index 0000000..bf64378
--- /dev/null
+++ b/apps/workbench/app/views/projects/tab_counts.js.erb
@@ -0,0 +1,3 @@
+<% @tab_counts.each do |pane_name, tab_count| %>
+  $('span#<%= pane_name %>-count').html(' (<%= tab_count %>)');
+<% end %>
\ No newline at end of file
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 8f01a76..3179f6f 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -72,6 +72,7 @@ ArvadosWorkbench::Application.routes.draw do
     match 'remove_items', on: :member, via: :delete, action: :remove_items
     get 'choose', on: :collection
     post 'share_with', on: :member
+    get 'tab_counts', on: :member
   end
   resources :search do
     get 'choose', :on => :collection

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list