Class: TypeMaterialsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/type_materials_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 inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/type_materials_controller.rb', line 75

def autocomplete
  @type_materials = Queries::TypeMaterialAutocompleteQuery.new(params[:term], project_id: sessions_current_project_id).all

  data = @type_materials.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.type_material_tag(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: ApplicationController.helpers.type_material_tag(t)
    }
  end

  render :json => data
end

- (Object) create

POST /type_materials POST /type_materials.json



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/type_materials_controller.rb', line 30

def create
  @type_material = TypeMaterial.new(type_material_params)

  respond_to do |format|
    if @type_material.save
      msg = "Type material (#{@type_material.type_type}) " +
          "for #{@type_material.protonym.cached} was successfully created."
      format.html { redirect_to @type_material,
                                notice: msg }
      format.json { render :show, status: :created, location: @type_material }
    else
      format.html { render :new }
      format.json { render json: @type_material.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /type_materials/1 DELETE /type_materials/1.json



63
64
65
66
67
68
69
# File 'app/controllers/type_materials_controller.rb', line 63

def destroy
  @type_material.destroy
  respond_to do |format|
    format.html { redirect_to type_materials_url, notice: 'Type material was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) download

GET /type_materials/download



92
93
94
# File 'app/controllers/type_materials_controller.rb', line 92

def download
  send_data TypeMaterial.generate_download(TypeMaterial.where(project_id: $project_id)), type: 'text', filename: "controlled_vocabulary_terms_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /type_materials/1/edit



24
25
26
# File 'app/controllers/type_materials_controller.rb', line 24

def edit
  @type_material.source = Source.new if !@type_material.source
end

- (Object) index

GET /type_materials GET /type_materials.json



8
9
10
11
# File 'app/controllers/type_materials_controller.rb', line 8

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

- (Object) list



71
72
73
# File 'app/controllers/type_materials_controller.rb', line 71

def list
  @type_materials = TypeMaterial.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10) #.per(3)
end

- (Object) new

GET /type_materials/new



19
20
21
# File 'app/controllers/type_materials_controller.rb', line 19

def new
  @type_material = TypeMaterial.new
end

- (Object) set_type_material (private)

Use callbacks to share common setup or constraints between actions.



99
100
101
102
# File 'app/controllers/type_materials_controller.rb', line 99

def set_type_material
  @type_material = TypeMaterial.with_project_id($project_id).find(params[:id])
  @recent_object = @type_material
end

- (Object) show

GET /type_materials/1 GET /type_materials/1.json



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

def show
end

- (Object) type_material_params (private)

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



105
106
107
108
109
110
111
# File 'app/controllers/type_materials_controller.rb', line 105

def type_material_params
  params.require(:type_material).permit(
      :protonym_id, :biological_object_id, :type_type,
      roles_attributes: [:id, :_destroy, :type, :person_id, :position, person_attributes: [:last_name, :first_name, :suffix, :prefix]],
      origin_citation_attributes: [:id, :_destroy, :source_id] 
  ) 
end

- (Object) update

PATCH/PUT /type_materials/1 PATCH/PUT /type_materials/1.json



49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/type_materials_controller.rb', line 49

def update
  respond_to do |format|
    if @type_material.update(type_material_params)
      format.html { redirect_to @type_material, notice: 'Type material was successfully updated.' }
      format.json { render :show, status: :ok, location: @type_material }
    else
      format.html { render :edit }
      format.json { render json: @type_material.errors, status: :unprocessable_entity }
    end
  end
end