From 555c1e920855989e059a4be0503ebb627193f987 Mon Sep 17 00:00:00 2001 From: Phil Hodgson Date: Thu, 11 Sep 2014 17:30:59 -0400 Subject: [PATCH] 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.) --- .../app/assets/javascripts/tab_panes.js | 8 +++ .../app/controllers/projects_controller.rb | 33 +++++++++-- .../app/views/application/_content.html.erb | 58 ++++++++++--------- .../app/views/projects/tab_counts.js.erb | 3 + apps/workbench/config/routes.rb | 1 + 5 files changed, 72 insertions(+), 31 deletions(-) create mode 100644 apps/workbench/app/views/projects/tab_counts.js.erb diff --git a/apps/workbench/app/assets/javascripts/tab_panes.js b/apps/workbench/app/assets/javascripts/tab_panes.js index 411a009f5c..22d6de1798 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 1e06b0a9ea..573e387f08 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 437975831a..8ec92bf16c 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 %> - -
-<% pane_list.each_with_index do |pane, i| %> -
- data-object-kind="arvados#<%= ArvadosApiClient.class_kind controller.model_class %>" -<% else %> - data-object-uuid="<%= @object.uuid %>" -<% end %> - > + -
-
- <% if i == 0 %> - <%= render_pane pane, to_string: true %> - <% else %> -
- <% end %> +
+ <% pane_list.each_with_index do |pane, i| %> + <% pane_name = (pane.is_a?(Hash) ? pane[:name] : pane) %> +
+ data-object-kind="arvados#<%= ArvadosApiClient.class_kind controller.model_class %>" + <% else %> + data-object-uuid="<%= @object.uuid %>" + <% end %> + > +
+
+ <% if i == 0 %> + <%= render_pane pane_name, to_string: true %> + <% else %> +
+ <% end %> +
+
-
+ <% end %>
-<% end %> -
<% 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 0000000000..bf64378536 --- /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 8f01a767b3..3179f6fde0 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 -- 2.39.5