Class: TypeMaterialsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TypeMaterialsController
- Defined in:
- app/controllers/type_materials_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #autocomplete ⇒ Object
-
#create ⇒ Object
POST /type_materials POST /type_materials.json.
-
#destroy ⇒ Object
DELETE /type_materials/1 DELETE /type_materials/1.json.
-
#download ⇒ Object
GET /type_materials/download.
-
#edit ⇒ Object
GET /type_materials/1/edit.
-
#filter_params ⇒ Object
private
No filter.rb available.
-
#index ⇒ Object
GET /type_materials GET /type_materials.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /type_materials/new.
- #search ⇒ Object
- #set_type_material ⇒ Object private
-
#show ⇒ Object
GET /type_materials/1 GET /type_materials/1.json.
- #type_material_params ⇒ Object private
- #type_types ⇒ Object
-
#update ⇒ Object
PATCH/PUT /type_materials/1 PATCH/PUT /type_materials/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
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, #week_in_review_graphs
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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# 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| v = ApplicationController.helpers.type_material_tag(t) {id: t.id, label: v , response_values: { params[:method] => t.id }, label_html: v } end render json: data end |
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#download ⇒ Object
GET /type_materials/download
111 112 113 |
# File 'app/controllers/type_materials_controller.rb', line 111 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 |
#edit ⇒ Object
GET /type_materials/1/edit
34 35 |
# File 'app/controllers/type_materials_controller.rb', line 34 def edit end |
#filter_params ⇒ Object (private)
No filter.rb available
125 126 127 |
# File 'app/controllers/type_materials_controller.rb', line 125 def filter_params params.permit(:protonym_id, :collection_object_id, :type_type) end |
#index ⇒ Object
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 |
#list ⇒ Object
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 |
#new ⇒ Object
GET /type_materials/new
29 30 31 |
# File 'app/controllers/type_materials_controller.rb', line 29 def new @type_material = TypeMaterial.new end |
#search ⇒ Object
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_material ⇒ Object (private)
129 130 131 132 |
# File 'app/controllers/type_materials_controller.rb', line 129 def set_type_material @type_material = TypeMaterial.with_project_id(sessions_current_project_id).find(params[:id]) @recent_object = @type_material end |
#show ⇒ Object
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_params ⇒ Object (private)
134 135 136 137 138 139 140 141 142 143 |
# File 'app/controllers/type_materials_controller.rb', line 134 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_types ⇒ Object
115 116 117 118 119 120 |
# File 'app/controllers/type_materials_controller.rb', line 115 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 |
#update ⇒ Object
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 |