Class: DescriptorsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/descriptors_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, #whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) annotations

TODO: remove for shared end point GET /annotations



96
97
98
99
# File 'app/controllers/descriptors_controller.rb', line 96

def annotations
  @object = @descriptor
  render '/shared/data/all/annotations'
end

- (Object) autocomplete



81
82
83
# File 'app/controllers/descriptors_controller.rb', line 81

def autocomplete
  @descriptors = Queries::DescriptorAutocompleteQuery.new(params.require(:term), project_id: sessions_current_project_id).all
end

- (Object) batch_load



101
102
# File 'app/controllers/descriptors_controller.rb', line 101

def batch_load
end

- (Object) batch_params (private)



150
151
152
153
154
# File 'app/controllers/descriptors_controller.rb', line 150

def batch_params
  params.permit(:file).merge(
    user_id: sessions_current_user_id,
    project_id: sessions_current_project_id).to_h.symbolize_keys
end

- (Object) create

POST /descriptors POST /descriptors.json



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

def create
  @descriptor = Descriptor.new(descriptor_params)
  respond_to do |format|
    if @descriptor.save
      format.html { redirect_to url_for(@descriptor.metamorphosize),
        notice: 'Descriptor was successfully created.' }

      format.json { render :show, status: :created, location: @descriptor.metamorphosize }
    else
      format.html { render :new }
      format.json { render json: @descriptor.metamorphosize.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) create_modify_gene_descriptor_batch_load



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/controllers/descriptors_controller.rb', line 115

def create_modify_gene_descriptor_batch_load
  if params[:file] && digested_cookie_exists?(params[:file]
    .tempfile, :modify_gene_descriptor_batch_load_descriptors_md5)
    @result = BatchLoad::Import::Descriptors::ModifyGeneDescriptorInterpreter.new(batch_params)
    if @result.create!
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} " \
        'Gene Descriptors were modified.'

      render 'descriptors/batch_load/modify_gene_descriptor/create' and return
    else
      flash[:alert] = 'Batch import failed.'
    end
  else
    flash[:alert] = 'File to batch upload must be supplied.'
  end
  render :batch_load
end

- (Object) descriptor_params (private)



143
144
145
146
147
148
# File 'app/controllers/descriptors_controller.rb', line 143

def descriptor_params
  params.require(:descriptor).permit(
    :name, :short_name, :description, :position, :type, :gene_attribute_logic, :default_unit,
    character_states_attributes: [:id, :descriptor_id, :_destroy, :label, :name, :position]
  )
end

- (Object) destroy

DELETE /descriptors/1 DELETE /descriptors/1.json



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

def destroy
  @descriptor.destroy!
  respond_to do |format|
    format.html { redirect_to descriptors_url, notice: 'Descriptor was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) edit

GET /descriptors/1/edit



36
37
# File 'app/controllers/descriptors_controller.rb', line 36

def edit
end

- (Object) index

GET /descriptors GET /descriptors.json



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

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

- (Object) list



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

def list
  @descriptor = Descriptor.with_project_id(sessions_current_project_id).page(params[:page])
end

- (Object) new

GET /descriptors/new



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

def new
  @descriptor = Descriptor.new
end

- (Object) preview_modify_gene_descriptor_batch_load



104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/descriptors_controller.rb', line 104

def preview_modify_gene_descriptor_batch_load
  if params[:file]
    @result = BatchLoad::Import::Descriptors::ModifyGeneDescriptorInterpreter.new(batch_params)
    digest_cookie(params[:file].tempfile, :modify_gene_descriptor_batch_load_descriptors_md5)
    render 'descriptors/batch_load/modify_gene_descriptor/preview'
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

- (Object) search



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

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

- (Object) set_descriptor (private)



139
140
141
# File 'app/controllers/descriptors_controller.rb', line 139

def set_descriptor
  @descriptor = Descriptor.where(project_id: sessions_current_project_id).find(params[:id])
end

- (Object) show

GET /descriptors/1 GET /descriptors/1.json



23
24
# File 'app/controllers/descriptors_controller.rb', line 23

def show
end

- (Object) units



133
134
135
# File 'app/controllers/descriptors_controller.rb', line 133

def units
  render json: UNITS
end

- (Object) update

PATCH/PUT /descriptors/1 PATCH/PUT /descriptors/1.json



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

def update
  respond_to do |format|
    if @descriptor.update(descriptor_params)
      format.html { redirect_to url_for(@descriptor.metamorphosize),
                    notice: 'Descriptor was successfully updated.' }
      format.json { render :show, status: :ok, location: @descriptor.metamorphosize }
    else
      format.html { render :edit }
      format.json { render json: @descriptor.metamorphosize.errors, status: :unprocessable_entity }
    end
  end
end