Class: SerialsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::SharedDataControllerConfiguration
Defined in:
app/controllers/serials_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

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

GET /serials/autocomplete



96
97
98
99
100
101
102
103
# File 'app/controllers/serials_controller.rb', line 96

def autocomplete
  render json: {} and return if params[:term].blank?

  @serials = Queries::Serial::Autocomplete.new(
    params[:term],
    **autocomplete_params
  ).autocomplete
end

#autocomplete_paramsObject (private)



125
126
127
# File 'app/controllers/serials_controller.rb', line 125

def autocomplete_params
  params.permit(:limit_to_project).merge(project_id: sessions_current_project_id).to_h.symbolize_keys
end

#createObject

POST /serials POST /serials.json



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

def create
  @serial = Serial.new(serial_params)

  respond_to do |format|
    if @serial.save
      format.html { redirect_to @serial, notice: "Serial '#{@serial.name}' was successfully created." }
      format.json { render action: 'show', status: :created, location: @serial }
    else
      format.html { render action: 'new' }
      format.json { render json: @serial.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /serials/1 DELETE /serials/1.json



74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/serials_controller.rb', line 74

def destroy
  @serial.destroy
  respond_to do |format|
    if @serial.destroyed?
      format.html { redirect_to serials_url }
      format.json { head :no_content }
    else
      format.html { destroy_redirect @serial, notice: 'Serial was not destroyed, ' + @serial.errors.full_messages.join('; ') }
      format.json { render json: @serial.errors, status: :unprocessable_entity }
    end
  end
end

#downloadObject

GET /serials/download



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

def download
  send_data(
    Export::CSV.generate_csv(Serial.all),
    type: 'text',
    filename: "serials_#{DateTime.now}.tsv")
end

#editObject

GET /serials/1/edit



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

def edit
end

#indexObject

GET /serials GET /serials.json



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

def index
  respond_to do |format|
    format.html do
      @recent_objects = Serial.order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @serials = Queries::Serial::Filter.new(params).all
      .page(params[:page])
      .per(params[:per])
    }
  end
end

#listObject



23
24
25
# File 'app/controllers/serials_controller.rb', line 23

def list
  @serials = Serial.order(:id).page(params[:page])
end

#newObject

GET /serials/new



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

def new
  @serial = Serial.new
end

#searchObject



87
88
89
90
91
92
93
# File 'app/controllers/serials_controller.rb', line 87

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

#select_optionsObject

GET /serials/select_options.json



106
107
108
# File 'app/controllers/serials_controller.rb', line 106

def select_options
  @serials = Serial.select_optimized(sessions_current_user_id, sessions_current_project_id)
end

#serial_paramsObject (private)



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/serials_controller.rb', line 129

def serial_params
  params.require(:serial).permit(
    :name,
    :publisher,
    :place_published,
    :primary_language_id,
    :first_year_of_issue,
    :last_year_of_issue,
    :translated_from_serial_id,
    :is_electronic_only,
    alternate_values_attributes: [
      :id,
      :value,
      :type,
      :language_id,
      :alternate_value_object_type,
      :alternate_value_object_id,
      :alternate_value_object_attribute,
      :_destroy
    ])
end

#set_serialObject (private)



120
121
122
123
# File 'app/controllers/serials_controller.rb', line 120

def set_serial
  @serial = Serial.find(params[:id])
  @recent_object = @serial
end

#showObject

GET /serials/1 GET /serials/1.json



29
30
31
# File 'app/controllers/serials_controller.rb', line 29

def show
  # TODO: put computation here for displaying alternate values?
end

#updateObject

PATCH/PUT /serials/1 PATCH/PUT /serials/1.json



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

def update
  respond_to do |format|
    if @serial.update(serial_params)
      format.html { redirect_to @serial, notice: 'Serial was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @serial.errors, status: :unprocessable_entity }
    end
  end
end