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

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) annotations

GET /annotations



103
104
105
106
# File 'app/controllers/descriptors_controller.rb', line 103

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

- (Object) autocomplete



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/descriptors_controller.rb', line 78

def autocomplete
  t = "#{params[:term]}%"
  @descriptors = Descriptor.where(project_id: sessions_current_project_id).where('name like ? or short_name like ?', t, t)
  data = @descriptors.collect do |t|
    {id:              t.id,
    label:           t.name, 
    gid: t.to_global_id.to_s,
    response_values: {
      params[:method] => t.id
    },
    label_html:      t.name 
  }
end
render :json => data
end

- (Object) batch_load



108
109
# File 'app/controllers/descriptors_controller.rb', line 108

def batch_load
end

- (Object) batch_params (private)



147
148
149
# File 'app/controllers/descriptors_controller.rb', line 147

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



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

def create
  @descriptor = Descriptor.new(descriptor_params)
  
  respond_to do |format|
    if @descriptor.save
      format.html { redirect_to @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



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/controllers/descriptors_controller.rb', line 122

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
# File 'app/controllers/descriptors_controller.rb', line 143

def descriptor_params
  params.require(:descriptor).permit(:name, :short_name, :type)
end

- (Object) destroy

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



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

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



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

def edit
end

- (Object) index

GET /descriptors GET /descriptors.json



8
9
10
11
12
13
14
15
16
17
18
# 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



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

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

- (Object) new

GET /descriptors/new



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

def new
  @descriptor = Descriptor.new
end

- (Object) preview_modify_gene_descriptor_batch_load



111
112
113
114
115
116
117
118
119
120
# File 'app/controllers/descriptors_controller.rb', line 111

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



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

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.find(params[:id])
end

- (Object) show

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



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

def show
end

- (Object) update

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



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

def update
  respond_to do |format|
    if @descriptor.update(descriptor_params)
      format.html { redirect_to @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