class ApplicationController < ActionController::Base
include ArvadosApiClientHelper
+ include ApplicationHelper
respond_to :html, :json, :js
protect_from_forgery
ERROR_ACTIONS = [:render_error, :render_not_found]
around_filter :thread_clear
- around_filter(:thread_with_mandatory_api_token,
- except: [:index, :show] + ERROR_ACTIONS)
+ around_filter :thread_with_mandatory_api_token, except: ERROR_ACTIONS
around_filter :thread_with_optional_api_token
before_filter :check_user_agreements, except: ERROR_ACTIONS
before_filter :check_user_notifications, except: ERROR_ACTIONS
- around_filter :using_reader_tokens, only: [:index, :show]
before_filter :find_object_by_uuid, except: [:index] + ERROR_ACTIONS
theme :select_theme
self.render_error status: 404
end
- def index
+ def find_objects_for_index
@limit ||= 200
if params[:limit]
@limit = params[:limit].to_i
end
@objects ||= model_class
- @objects = @objects.filter(@filters).limit(@limit).offset(@offset).all
+ @objects = @objects.filter(@filters).limit(@limit).offset(@offset)
+ end
+
+ helper_method :next_page_offset
+ def next_page_offset
+ if @objects.respond_to?(:result_offset) and
+ @objects.respond_to?(:result_limit) and
+ @objects.respond_to?(:items_available)
+ next_offset = @objects.result_offset + @objects.result_limit
+ if next_offset < @objects.items_available
+ next_offset
+ else
+ nil
+ end
+ end
+ end
+
+ def index
+ find_objects_for_index if !@objects
respond_to do |f|
f.json { render json: @objects }
f.html { render }
end
end
+ def choose
+ params[:limit] ||= 20
+ find_objects_for_index if !@objects
+ respond_to do |f|
+ if params[:partial]
+ f.json {
+ render json: {
+ content: render_to_string(partial: "choose_rows.html",
+ formats: [:html],
+ locals: {
+ multiple: params[:multiple]
+ }),
+ next_page_href: @next_page_href
+ }
+ }
+ end
+ f.js {
+ render partial: 'choose', locals: {multiple: params[:multiple]}
+ }
+ end
+ end
+
def render_content
if !@object
return render_not_found("object not found")
end
def update
- @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
+ @updates ||= params[@object.resource_param_name.to_sym]
@updates.keys.each do |attr|
if @object.send(attr).is_a? Hash
if @updates[attr].is_a? String
end
def show_pane_list
- %w(Attributes Metadata JSON API)
+ %w(Attributes Advanced)
end
protected
false # For convenience to return from callbacks
end
- def using_reader_tokens(login_optional=false)
- if params[:reader_tokens].is_a?(Array) and params[:reader_tokens].any?
- Thread.current[:reader_tokens] = params[:reader_tokens]
- end
- begin
- yield
- rescue ArvadosApiClient::NotLoggedInException
- if login_optional
- raise
- else
- return redirect_to_login
- end
- ensure
- Thread.current[:reader_tokens] = nil
- end
- end
-
def using_specific_api_token(api_token)
start_values = {}
[:arvados_api_token, :user].each do |key|
if params[:uuid].empty?
@object = nil
else
- @object = model_class.find(params[:uuid])
+ if (model_class != Link and
+ resource_class_for_uuid(params[:uuid]) == Link)
+ @name_link = Link.find(params[:uuid])
+ @object = model_class.find(@name_link.head_uuid)
+ else
+ @object = model_class.find(params[:uuid])
+ end
end
else
@object = model_class.where(uuid: params[:uuid]).first
@notification_count = ''
end
end
+
+ helper_method :my_folders
+ def my_folders
+ return @my_folders if @my_folders
+ @my_folders = []
+ root_of = {}
+ Group.filter([['group_class','=','folder']]).each do |g|
+ root_of[g.uuid] = g.owner_uuid
+ @my_folders << g
+ end
+ done = false
+ while not done
+ done = true
+ root_of = root_of.each_with_object({}) do |(child, parent), h|
+ if root_of[parent]
+ h[child] = root_of[parent]
+ done = false
+ else
+ h[child] = parent
+ end
+ end
+ end
+ @my_folders = @my_folders.select do |g|
+ root_of[g.uuid] == current_user.uuid
+ end
+ end
end