Class: LoansController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/loans_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#attributesObject



67
68
69
70
71
72
# File 'app/controllers/loans_controller.rb', line 67

def attributes
  render json: ::Loan.columns.select{
    |a| ::Queries::Loan::Filter::ATTRIBUTES.include?(
      a.name.to_sym)
  }.collect{|b| {'name' => b.name, 'type' => b.type } }
end

#autocompleteObject



112
113
114
# File 'app/controllers/loans_controller.rb', line 112

def autocomplete
  @loans = ::Queries::Loan::Autocomplete.new(params[:term], project_id: sessions_current_project_id).autocomplete
end

#createObject

POST /loans POST /loans.json



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/loans_controller.rb', line 49

def create
  @loan = Loan.new(loan_params)

  respond_to do |format|
    if @loan.save
      format.html { redirect_to @loan, notice: 'Loan was successfully created.' }
      format.json { render :show, status: :created, location: @loan }
    else
      format.html { render :new }
      format.json { render json: @loan.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /loans/1 DELETE /loans/1.json



91
92
93
94
95
96
97
# File 'app/controllers/loans_controller.rb', line 91

def destroy
  @loan.destroy
  respond_to do |format|
    format.html { redirect_to loans_url }
    format.json { head :no_content }
  end
end

#downloadObject

GET /loans/download



117
118
119
# File 'app/controllers/loans_controller.rb', line 117

def download
  send_data Export::CSV.generate_csv(Loan.where(project_id: sessions_current_project_id)), type: 'text', filename: "loans_#{DateTime.now}.tsv"
end

#editObject

GET /loans/1/edit



43
44
45
# File 'app/controllers/loans_controller.rb', line 43

def edit
  redirect_to edit_loan_task_path(id: params[:id])
end

#indexObject

GET /loans GET /loans.json



10
11
12
13
# File 'app/controllers/loans_controller.rb', line 10

def index
  @recent_objects = Loan.includes(:loan_items, :identifiers).recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

#listObject



99
100
101
102
# File 'app/controllers/loans_controller.rb', line 99

def list
  @loans = Loan.includes(:identifiers).with_project_id(sessions_current_project_id)
    .order(Arel.sql('LENGTH(identifier), identifier')).references(:identifiers).page(params[:page])
end

#loan_paramsObject (private)



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/controllers/loans_controller.rb', line 133

def loan_params
  params.require(:loan).permit(
    :date_requested, :request_method, :date_sent, :date_received,
    :date_return_expected, :recipient_person_id, :recipient_address,
    :recipient_email, :recipient_phone, :recipient_country, :supervisor_person_id,
    :supervisor_email, :supervisor_phone, :date_closed, :recipient_honorific,
    :lender_address,
    :is_gift,
    :clone_from,
    :is_gift,
    loan_items_attributes: [
      :_destroy,
      :id,
      :global_entity,
      :loan_item_object_type,
      :loan_item_object_id,
      :position,
      :total,
      :disposition,
      :date_,
      :date_returned_jquery ],
      roles_attributes: [
        :id, :_destroy, :type, :person_id, :position,
        person_attributes: [
          :last_name, :first_name, :suffix, :prefix]],
  )
end

#newObject

GET /loans/new



37
38
39
40
# File 'app/controllers/loans_controller.rb', line 37

def new
  redirect_to edit_loan_task_path
  # @loan = Loan.new(params.permit(:clone_from))
end

#recipient_formObject



63
64
65
# File 'app/controllers/loans_controller.rb', line 63

def recipient_form
  render layout: 'us_letter'
end

#searchObject



104
105
106
107
108
109
110
# File 'app/controllers/loans_controller.rb', line 104

def search
  if params[:id].blank?
    redirect_to loan_path, alert: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to loan_path(params[:id])
  end
end

#select_optionsObject

GET /loans/select_options



122
123
124
# File 'app/controllers/loans_controller.rb', line 122

def select_options
  @loans = Loan.select_optimized(sessions_current_user_id, sessions_current_project_id)
end

#set_loanObject (private)



128
129
130
131
# File 'app/controllers/loans_controller.rb', line 128

def set_loan
  @loan = Loan.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object = @loan
end

#showObject

GET /loans/1 GET /loans/1.json



33
34
# File 'app/controllers/loans_controller.rb', line 33

def show
end

#updateObject

PATCH/PUT /loans/1 PATCH/PUT /loanss/1.json



76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/loans_controller.rb', line 76

def update
  respond_to do |format|
    if @loan.update(loan_params)
      @loan.reload
      format.html { redirect_to @loan, notice: 'Loan was successfully updated.' }
      format.json { render :show, status: :ok, location: @loan }
    else
      format.html { render :edit }
      format.json { render json: @loan.errors, status: :unprocessable_entity }
    end
  end
end