Class: SerialsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SerialsController
- Defined in:
- app/controllers/serials_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
-
#autocomplete ⇒ Object
GET /serials/autocomplete.
- #autocomplete_params ⇒ Object private
-
#create ⇒ Object
POST /serials POST /serials.json.
-
#destroy ⇒ Object
DELETE /serials/1 DELETE /serials/1.json.
-
#download ⇒ Object
GET /serials/download.
-
#edit ⇒ Object
GET /serials/1/edit.
-
#index ⇒ Object
GET /serials GET /serials.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /serials/new.
- #search ⇒ Object
-
#select_options ⇒ Object
GET /serials/select_options.json.
- #serial_params ⇒ Object private
- #set_serial ⇒ Object private
-
#show ⇒ Object
GET /serials/1 GET /serials/1.json.
-
#update ⇒ Object
PATCH/PUT /serials/1 PATCH/PUT /serials/1.json.
Methods included from DataControllerConfiguration::SharedDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
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
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#autocomplete ⇒ Object
GET /serials/autocomplete
97 98 99 100 101 102 103 104 |
# File 'app/controllers/serials_controller.rb', line 97 def autocomplete render json: {} and return if params[:term].blank? @serials = Queries::Serial::Autocomplete.new( params[:term], **autocomplete_params ).autocomplete end |
#autocomplete_params ⇒ Object (private)
126 127 128 |
# File 'app/controllers/serials_controller.rb', line 126 def autocomplete_params params.permit(:limit_to_project).merge(project_id: sessions_current_project_id).to_h.symbolize_keys end |
#create ⇒ Object
POST /serials POST /serials.json
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/serials_controller.rb', line 45 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 |
#destroy ⇒ Object
DELETE /serials/1 DELETE /serials/1.json
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/serials_controller.rb', line 75 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..join('; ') } format.json { render json: @serial.errors, status: :unprocessable_entity } end end end |
#download ⇒ Object
GET /serials/download
112 113 114 115 116 117 |
# File 'app/controllers/serials_controller.rb', line 112 def download send_data( Export::Download.generate_csv(Serial.all), type: 'text', filename: "serials_#{DateTime.now}.csv") end |
#edit ⇒ Object
GET /serials/1/edit
40 41 |
# File 'app/controllers/serials_controller.rb', line 40 def edit end |
#index ⇒ Object
GET /serials GET /serials.json
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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 = Queries::Serial::Filter.new(params).all .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
24 25 26 |
# File 'app/controllers/serials_controller.rb', line 24 def list @serials = Serial.order(:id).page(params[:page]) end |
#new ⇒ Object
GET /serials/new
35 36 37 |
# File 'app/controllers/serials_controller.rb', line 35 def new @serial = Serial.new end |
#search ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/controllers/serials_controller.rb', line 88 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_options ⇒ Object
GET /serials/select_options.json
107 108 109 |
# File 'app/controllers/serials_controller.rb', line 107 def @serials = Serial.select_optimized(sessions_current_user_id, sessions_current_project_id) end |
#serial_params ⇒ Object (private)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/controllers/serials_controller.rb', line 130 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_serial ⇒ Object (private)
121 122 123 124 |
# File 'app/controllers/serials_controller.rb', line 121 def set_serial @serial = Serial.find(params[:id]) @recent_object = @serial end |
#show ⇒ Object
GET /serials/1 GET /serials/1.json
30 31 32 |
# File 'app/controllers/serials_controller.rb', line 30 def show # TODO: put computation here for displaying alternate values? end |
#update ⇒ Object
PATCH/PUT /serials/1 PATCH/PUT /serials/1.json
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/serials_controller.rb', line 61 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 |