Class: PreparationTypesController

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

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

#createObject

POST /preparation_types POST /preparation_types.json



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

def create
  @preparation_type = PreparationType.new(preparation_type_params)

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

#destroyObject

DELETE /preparation_types/1 DELETE /preparation_types/1.json



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

def destroy
  @preparation_type.destroy
  respond_to do |format|
    format.html { redirect_to preparation_types_url }
    format.json { head :no_content }
  end
end

#downloadObject

GET /preparation_types/download



86
87
88
89
90
# File 'app/controllers/preparation_types_controller.rb', line 86

def download
  send_data(Export::Csv.generate_csv(PreparationType.all),
            type: 'text',
            filename: "preparation_types_#{DateTime.now}.tsv")
end

#editObject

GET /preparation_types/1/edit



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

def edit
end

#indexObject

GET /preparation_types GET /preparation_types.json



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/preparation_types_controller.rb', line 8

def index
  respond_to do |format|
    @preparation_types = PreparationType.all
    format.html do
      @recent_objects = PreparationType.order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {}
  end
end

#listObject



73
74
75
# File 'app/controllers/preparation_types_controller.rb', line 73

def list
  @preparation_types = PreparationType.order(:id).page(params[:page]) #.per(10) #.per(3)
end

#newObject

GET /preparation_types/new



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

def new
  @preparation_type = PreparationType.new
end

#preparation_type_paramsObject (private)

Never trust parameters from the scary internet, only allow the white list through.



117
118
119
# File 'app/controllers/preparation_types_controller.rb', line 117

def preparation_type_params
  params.require(:preparation_type).permit(:name, :definition)
end

#searchObject



77
78
79
80
81
82
83
# File 'app/controllers/preparation_types_controller.rb', line 77

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

#set_preparation_typeObject (private)

Use callbacks to share common setup or constraints between actions.



111
112
113
114
# File 'app/controllers/preparation_types_controller.rb', line 111

def set_preparation_type
  @preparation_type = PreparationType.find(params[:id])
  @recent_object = @preparation_type
end

#showObject

GET /preparation_types/1 GET /preparation_types/1.json



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

def show
end

#updateObject

PATCH/PUT /preparation_types/1 PATCH/PUT /preparation_types/1.json



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

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