Class: LoanItemsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/loan_items_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

#autocompleteObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/loan_items_controller.rb', line 89

def autocomplete
  @loan_items = LoanItem.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)).includes(:taxon_name)
  data = @loan_items.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.loan_item_tag(t),
     response_values: {
       params[:method] => t.id
     },
     label_html: ApplicationController.helpers.loan_item_autocomplete_selected_tag(t)
    }
  end

  render json: data
end

#batch_createObject

POST /loan_items/batch_create?batch_type=tags&loan_id=123&keyword_id=456&klass=Otu POST /loan_items/batch_create?batch_type=pinboard&loan_id=123&klass=Otu POST /loan_items/batch_create?batch_type=collection_object_filter&loan_id=123&collection_object_filter=<>



110
111
112
113
114
115
116
# File 'app/controllers/loan_items_controller.rb', line 110

def batch_create
  if @loan_items = LoanItem.batch_create(batch_params)
    render :index
  else
    render json: {success: false}
  end
end

#batch_moveObject

POST /loan_items/batch_move.json?collection_object_query=<>



128
129
130
131
132
133
134
# File 'app/controllers/loan_items_controller.rb', line 128

def batch_move
  if @loan_items = LoanItem.batch_move(batch_params)[:moved]
    render :index
  else
    render json: {success: false}
  end
end

#batch_paramsObject (private)



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/controllers/loan_items_controller.rb', line 146

def batch_params
  params.permit(
    :batch_type,
    :loan_id,
    :keyword_id,
    :collection_object_status,
    :date_returned,
    :date_returned_jquery, #!? old forms only perhaps
    :disposition,
    :klass).to_h.symbolize_keys.merge(
      project_id: sessions_current_project_id,
      user_id: sessions_current_user_id,
      collection_object_query: params[:collection_object_query]
     )
end

#batch_returnObject

POST /loan_items/batch_return.json?collection_object_query=<>



119
120
121
122
123
124
125
# File 'app/controllers/loan_items_controller.rb', line 119

def batch_return
  if @loan_items = LoanItem.batch_return(batch_params)[:returned]
    render :index
  else
    render json: {success: false}
  end
end

#createObject

POST /loan_items POST /loan_items.json



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/loan_items_controller.rb', line 44

def create
  @loan_item = LoanItem.new(loan_item_params)
  respond_to do |format|
    if @loan_item.save
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was successfully created.')}
      format.json { render :show, status: :created, location: @loan_item }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was NOT successfully created.')}
      format.json { render json: @loan_item.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /loan_items/1 DELETE /loan_items/1.json



73
74
75
76
77
78
79
# File 'app/controllers/loan_items_controller.rb', line 73

def destroy
  @loan_item.destroy
  respond_to do |format|
    format.html { destroy_redirect @loan_item, notice: 'Loan item was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /loan_items/1/edit



35
36
# File 'app/controllers/loan_items_controller.rb', line 35

def edit
end

#filter_paramsObject (private)



138
139
140
# File 'app/controllers/loan_items_controller.rb', line 138

def filter_params
  params.permit(:loan_id)
end

#indexObject

GET /loan_items GET /loan_items.json



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/loan_items_controller.rb', line 9

def index
  respond_to do |format|
    format.html {
      @recent_objects = LoanItem.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @loan_items = LoanItem.where(filter_params)
        .with_project_id(sessions_current_project_id)
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject



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

def list
  @loan_items = LoanItem.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10)
end

#loan_item_paramsObject (private)



162
163
164
165
166
167
168
169
# File 'app/controllers/loan_items_controller.rb', line 162

def loan_item_params
  params.require(:loan_item).permit(
    :loan_id, :collection_object_status, :date_returned, :loan_item_object_id, :loan_item_object_type,
    :date_returned_jquery, :disposition, :total,
    :global_entity,
    :position
  )
end

#newObject

GET /loan_items/new



30
31
32
# File 'app/controllers/loan_items_controller.rb', line 30

def new
  @loan_item = LoanItem.new(loan: Loan.new)
end

#searchObject



81
82
83
84
85
86
87
# File 'app/controllers/loan_items_controller.rb', line 81

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

#set_loan_itemObject (private)



142
143
144
# File 'app/controllers/loan_items_controller.rb', line 142

def set_loan_item
  @loan_item = LoanItem.with_project_id(sessions_current_project_id).find(params[:id])
end

#showObject

GET /loan_items/1 GET /loan_items/1.json



26
27
# File 'app/controllers/loan_items_controller.rb', line 26

def show
end

#updateObject

PATCH/PUT /loan_items/1 PATCH/PUT /loan_items/1.json



59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/loan_items_controller.rb', line 59

def update
  respond_to do |format|
    if @loan_item.update(loan_item_params)
      format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was successfully updated.')}
      format.json { render :show, status: :ok, location: @loan_item }
    else
      format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was NOT successfully updated.' + @loan_item.errors.full_messages.join('; '))}
      format.json { render json: @loan_item.errors, status: :unprocessable_entity }
    end
  end
end