Class: SerialsController

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

Instance Method Summary collapse

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

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)


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

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 {redirect_back(fallback_location: (request.referer || root_path), 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::Download.generate_csv(Serial.all),
    type: 'text',
    filename: "serials_#{DateTime.now}.csv")
end

#editObject

GET /serials/1/edit


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

def edit
end

#filter_paramsObject (private)


120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/controllers/serials_controller.rb', line 120

def filter_params
  params.permit(
    :name, :id,
    data_attributes_attributes: [
      :id,
      :_destroy,
      :controlled_vocabulary_term_id,
      :type,
      :attribute_subject_id,
      :attribute_subject_type,
      :value ])
end

#indexObject

GET /serials GET /serials.json


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

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 = Serial.order(updated_at: :desc).limit(10)
      @serials = Queries::Serial::Filter.new(filter_params).all.page(params[:page]).per(params[:per] || 500)
    }
  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, 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

#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)


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'app/controllers/serials_controller.rb', line 142

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,
    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)


133
134
135
136
# File 'app/controllers/serials_controller.rb', line 133

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