2809: Merge branch 'master' into 2809-workbench-rails4 refs #2809
authorTom Clegg <tom@curoverse.com>
Thu, 15 May 2014 18:19:06 +0000 (14:19 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 15 May 2014 18:19:06 +0000 (14:19 -0400)
Conflicts:
apps/workbench/app/models/arvados_api_client.rb

1  2 
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/models/arvados_api_client.rb
apps/workbench/app/views/layouts/application.html.erb

index dfb9e892e6ab2a59292edccf07369b8792462fd5,2fbd8c560f6dd081ef49230151d91c9d10ed03ec..b62838f655e23a54033d28298c265849c32f2398
@@@ -1,6 -1,4 +1,6 @@@
  class ApplicationController < ActionController::Base
 +  include ArvadosApiClientHelper
 +
    respond_to :html, :json, :js
    protect_from_forgery
  
    end
  
    def index
+     @limit ||= 200
      if params[:limit]
-       limit = params[:limit].to_i
-     else
-       limit = 200
+       @limit = params[:limit].to_i
      end
  
+     @offset ||= 0
      if params[:offset]
-       offset = params[:offset].to_i
-     else
-       offset = 0
+       @offset = params[:offset].to_i
      end
  
+     @filters ||= []
      if params[:filters]
        filters = params[:filters]
        if filters.is_a? String
          filters = Oj.load filters
        end
-     else
-       filters = []
+       @filters += filters
      end
  
-     @objects ||= model_class.filter(filters).limit(limit).offset(offset).all
+     @objects ||= model_class
+     @objects = @objects.filter(@filters).limit(@limit).offset(@offset).all
      respond_to do |f|
        f.json { render json: @objects }
        f.html { render }
      respond_to do |f|
        f.html {
          if request.method == 'GET'
 -          redirect_to $arvados_api_client.arvados_login_url(return_to: request.url)
 +          redirect_to arvados_api_client.arvados_login_url(return_to: request.url)
          else
            flash[:error] = "Either you are not logged in, or your session has timed out. I can't automatically log you in and re-attempt this request."
            redirect_to :back
index dc1b6ede01250a737a6c1a9479efc9a49818a130,c6d8720c9232fa0dba6fdf8d72f2b20b716243cd..25e776a94267fd41394d47a4553bc8e03ecd80dd
@@@ -7,31 -7,21 +7,31 @@@ class ArvadosApiClien
    class InvalidApiResponseException < StandardError
    end
  
 -  @@client_mtx = Mutex.new
 -  @@api_client = nil
    @@profiling_enabled = Rails.configuration.profiling_enabled
 +  @@discovery = nil
 +
 +  # An API client object suitable for handling API requests on behalf
 +  # of the current thread.
 +  def self.new_or_current
 +    Thread.current[:arvados_api_client] ||= new
 +  end
 +
 +  def initialize *args
 +    @api_client = nil
 +    @client_mtx = Mutex.new
 +  end
  
    def api(resources_kind, action, data=nil)
      profile_checkpoint
  
 -    @@client_mtx.synchronize do
 -      if not @@api_client
 -        @@api_client = HTTPClient.new
 +    if not @api_client
 +      @client_mtx.synchronize do
 +        @api_client = HTTPClient.new
          if Rails.configuration.arvados_insecure_https
 -          @@api_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
 +          @api_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
          else
            # Use system CA certificates
 -          @@api_client.ssl_config.add_trust_ca('/etc/ssl/certs')
 +          @api_client.ssl_config.add_trust_ca('/etc/ssl/certs')
          end
        end
      end
  
      header = {"Accept" => "application/json"}
  
-     profile_checkpoint { "Prepare request #{url} #{query[:uuid]} #{query[:where]}" }
+     profile_checkpoint { "Prepare request #{url} #{query[:uuid]} #{query[:where]} #{query[:filters]}" }
 -    msg = @@api_client.post(url,
 -                            query,
 -                            header: header)
 +    msg = @client_mtx.synchronize do
 +      @api_client.post(url,
 +                       query,
 +                       header: header)
 +    end
      profile_checkpoint 'API transaction'
  
      if msg.status_code == 401
    end
  
    def discovery
 -    @discovery ||= api '../../discovery/v1/apis/arvados/v1/rest', ''
 +    @@discovery ||= api '../../discovery/v1/apis/arvados/v1/rest', ''
    end
  
    def kind_class(kind)
index f5aca0cd4e1da6f161d2a0a3cd63d31eeab327d2,e2db3d9b7eae03429c87be3a735880207c67ba38..2d3c4c0de0239881cfe5404679dfd076634f97ca
@@@ -77,7 -77,7 +77,7 @@@
              </li>
  
              <li class="dropdown">
-               <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-lg fa-folder-o fa-fw"></i> Folders <b class="caret"></b></a>
+               <a href="/folders" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-lg fa-folder-o fa-fw"></i> Folders <b class="caret"></b></a>
                <ul class="dropdown-menu">
                  <li><%= link_to raw('<i class="fa fa-plus fa-fw"></i> Create new folder'), folders_path, method: :post %></li>
                  <% @my_top_level_folders.call[0..7].each do |folder| %>
@@@ -91,6 -91,9 +91,9 @@@
              <li><a href="/collections">
                  <i class="fa fa-lg fa-briefcase fa-fw"></i> Collections (data files)
              </a></li>
+             <li><a href="/jobs">
+                 <i class="fa fa-lg fa-tasks fa-fw"></i> Jobs
+             </a></li>
              <li><a href="/pipeline_instances">
                  <i class="fa fa-lg fa-tasks fa-fw"></i> Pipeline instances
              </a></li>
              </ul>
            </li>
            <% else %>
 -            <li><a href="<%= $arvados_api_client.arvados_login_url(return_to: root_url) %>">Log in</a></li>
 +            <li><a href="<%= arvados_api_client.arvados_login_url(return_to: root_url) %>">Log in</a></li>
            <% end %>
          </ul>
        </div><!-- /.navbar-collapse -->