Class: SerialsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

Methods inherited from ApplicationController

#digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #project_matches, #record_not_found, #set_project_from_params

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Methods included from InterceptApi

#intercept_api, #token_authenticate

Instance Method Details

- (Object) autocomplete

GET /serials/autocomplete



82
83
84
85
86
87
88
89
# File 'app/controllers/serials_controller.rb', line 82

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

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

- (Object) autocomplete_params (private)



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

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

- (Object) create

POST /serials POST /serials.json



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/serials_controller.rb', line 35

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

- (Object) destroy

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



65
66
67
68
69
70
71
# File 'app/controllers/serials_controller.rb', line 65

def destroy
  @serial.destroy!
  respond_to do |format|
    format.html { redirect_to serials_url }
    format.json { head :no_content }
  end
end

- (Object) download

GET /serials/download



92
93
94
95
96
# File 'app/controllers/serials_controller.rb', line 92

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

- (Object) edit

GET /serials/1/edit



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

def edit
end

- (Object) index

GET /serials GET /serials.json



9
10
11
12
# File 'app/controllers/serials_controller.rb', line 9

def index
  @recent_objects = Serial.order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



14
15
16
# File 'app/controllers/serials_controller.rb', line 14

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

- (Object) new

GET /serials/new



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

def new
  @serial = Serial.new
end

- (Object) search



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

def search
  if params[:id].blank?
    redirect_to serials_path, notice: '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

- (Object) serial_params (private)



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/serials_controller.rb', line 109

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

- (Object) set_serial (private)



100
101
102
103
# File 'app/controllers/serials_controller.rb', line 100

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

- (Object) show

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



20
21
22
# File 'app/controllers/serials_controller.rb', line 20

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

- (Object) update

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



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

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