Class: TypeMaterialsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/type_materials_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

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, #week_in_review_graphs

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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/type_materials_controller.rb', line 93

def autocomplete
  @type_materials = Queries::TypeMaterial::Autocomplete.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

#createObject

POST /type_materials POST /type_materials.json



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

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

#destroyObject

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



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

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

#downloadObject

GET /type_materials/download



110
111
112
# File 'app/controllers/type_materials_controller.rb', line 110

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

#editObject

GET /type_materials/1/edit



34
35
# File 'app/controllers/type_materials_controller.rb', line 34

def edit
end

#filter_paramsObject (private)

No filter.rb available



124
125
126
# File 'app/controllers/type_materials_controller.rb', line 124

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

#indexObject

GET /type_materials GET /type_materials.json



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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)
      .page(params[:page])
      .per(params[:per])
    }
  end
end

#listObject



80
81
82
# File 'app/controllers/type_materials_controller.rb', line 80

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

#newObject

GET /type_materials/new



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

def new
  @type_material = TypeMaterial.new
end

#searchObject



84
85
86
87
88
89
90
91
# File 'app/controllers/type_materials_controller.rb', line 84

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

#set_type_materialObject (private)



128
129
130
131
# File 'app/controllers/type_materials_controller.rb', line 128

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

#showObject

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



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

def show
end

#type_material_paramsObject (private)



133
134
135
136
137
138
139
140
141
142
# File 'app/controllers/type_materials_controller.rb', line 133

def type_material_params
  params.require(:type_material).permit(
    :protonym_id, :collection_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],
    collection_object_attributes: [
      :id, :buffered_collecting_event, :buffered_other_labels, :buffered_determinations,
      :total, :collecting_event_id, :preparation_type_id, :repository_id]
  )
end

#type_typesObject



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

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

#updateObject

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



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

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