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 included from DataControllerConfiguration::ProjectDataControllerConfiguration

#polymorphic_filter_params

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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/type_materials_controller.rb', line 82

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/type_materials_controller.rb', line 37

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



70
71
72
73
74
75
76
# File 'app/controllers/type_materials_controller.rb', line 70

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



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

def download
  send_data Download.generate_csv(TypeMaterial.where(project_id: sessions_current_project_id)), type: 'text', filename: "type_materials_#{DateTime.now}.csv"
end

- (Object) edit

GET /type_materials/1/edit



31
32
33
# File 'app/controllers/type_materials_controller.rb', line 31

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

- (Object) filter_params (private)



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

def filter_params
  params.permit(:protonym_id, :biological_object_id, :type_type)
end

- (Object) index

GET /type_materials GET /type_materials.json



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

def index
  respond_to do |format|
    format.html do
      @recent_objects = TypeMaterial.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @type_materials = TypeMaterial.where(filter_params).with_project_id(sessions_current_project_id)
    }
  end
end

- (Object) list



78
79
80
# File 'app/controllers/type_materials_controller.rb', line 78

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



26
27
28
# File 'app/controllers/type_materials_controller.rb', line 26

def new
  @type_material = TypeMaterial.new
end

- (Object) set_type_material (private)



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

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

- (Object) show

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



22
23
# File 'app/controllers/type_materials_controller.rb', line 22

def show
end

- (Object) type_material_params (private)



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

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, :pages],
      material_attributes: [
        :id, :buffered_collecting_event, :buffered_other_labels, :buffered_determinations,
        :total, :collecting_event_id, :preparation_type_id, :repository_id]
  )
end

- (Object) type_types



103
104
105
106
107
108
# File 'app/controllers/type_materials_controller.rb', line 103

def type_types
  render json: {
    icn: TypeMaterial::ICN_TYPES.inject({}){|hsh, k| hsh.merge!(k[0] =>  k[1].name)},
    iczn: TypeMaterial::ICZN_TYPES.inject({}){|hsh, k| hsh.merge!(k[0] => k[1].name)}
  }
end

- (Object) update

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



56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/type_materials_controller.rb', line 56

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