Module: CommonwealthVlrEngine::Controller

Extended by:
ActiveSupport::Concern
Defined in:
lib/commonwealth-vlr-engine/controller.rb

Instance Method Summary collapse

Instance Method Details

#after_sign_in_path_for(resource) ⇒ Object



36
37
38
# File 'lib/commonwealth-vlr-engine/controller.rb', line 36

def (resource)
  session[:previous_url] || root_path
end

#create_img_sequence(image_files, current_img_pid) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/commonwealth-vlr-engine/controller.rb', line 40

def create_img_sequence(image_files, current_img_pid)
  page_sequence = {}
  page_sequence[:current] = current_img_pid
  page_sequence[:index] = image_files.index(current_img_pid) + 1
  page_sequence[:total] = image_files.length
  page_sequence[:prev] = page_sequence[:index]-2 > -1 ? image_files[page_sequence[:index]-2] : nil
  page_sequence[:next] = image_files[page_sequence[:index]].presence
  page_sequence
end

#not_foundObject

Raises:

  • (ActionController::RoutingError)


50
51
52
# File 'lib/commonwealth-vlr-engine/controller.rb', line 50

def not_found
  raise ActionController::RoutingError.new('Not Found')
end

#search_action_path(*args) ⇒ Object

override of Blacklight::Controller#search_action_path for proper constraints and facet links in collections and institution views gets a bit tricky for collections#facet, since this has multiple contexts (collections#index and collections#show)



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/commonwealth-vlr-engine/controller.rb', line 57

def search_action_path *args
  if args.first.is_a? Hash
    args.first[:only_path] = true
    # Rails 4.2 deprecated url helpers accepting string keys for 'controller' or 'action'
    args[0] = args.first.except(:controller, :action)
  end

  if params[:controller] == 'institutions' && params[:action] == 'index'
    institutions_url *args
  elsif params[:controller] == 'collections'
    if params[:action] == 'index'
      collections_url *args
    elsif params[:action] == 'facet'
      if request.query_parameters['f'] && request.query_parameters['f'][blacklight_config.collection_field]
        search_action_url *args
      else
        collections_url *args
      end
    else
      search_action_url *args
    end
  else
    search_action_url *args
  end
end

#store_locationObject

redirect after login to previous non-login page TODO figure out why it doesn’t work for Polaris or Facebook logins



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/commonwealth-vlr-engine/controller.rb', line 21

def store_location
  # store last url - this is needed for post-login redirect to whatever the user last visited.
  if (request.path != "/users/sign_in" &&
      request.path != "/users/sign_up" &&
      request.path != "/users/password" &&
      request.path != "/users/password/new" &&
      request.path != "/users/password/edit" &&
      request.path != "/users/confirmation" &&
      request.path != "/users/sign_out" &&
      !request.fullpath.match(/\/users\/auth\//) &&
          !request.xhr?) # don't store ajax calls
    session[:previous_url] = request.fullpath
  end
end