Class: DescriptorsController

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

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

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

#annotationsObject

TODO: remove for shared end point GET /annotations



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

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

#autocompleteObject



93
94
95
96
# File 'app/controllers/descriptors_controller.rb', line 93

def autocomplete
  @term = params[:term]
  @descriptors = Queries::Descriptor::Autocomplete.new(params.require(:term), project_id: sessions_current_project_id).all
end

#batch_loadObject



114
115
# File 'app/controllers/descriptors_controller.rb', line 114

def batch_load
end

#batch_paramsObject (private)



195
196
197
198
199
# File 'app/controllers/descriptors_controller.rb', line 195

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

#createObject

POST /descriptors POST /descriptors.json



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

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

#create_modify_gene_descriptor_batch_loadObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/controllers/descriptors_controller.rb', line 139

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

#create_qualitative_descriptor_batch_loadObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'app/controllers/descriptors_controller.rb', line 158

def create_qualitative_descriptor_batch_load
  if params[:file] && digested_cookie_exists?(
      params[:file].tempfile,
      :qualitative_descriptors_batch_load_md5)
    @result = BatchLoad::Import::Descriptors::QualitativeInterpreter.new(**batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created}."
      render 'descriptors/batch_load/qualitative_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

#descriptor_paramsObject (private)



186
187
188
189
190
191
192
193
# File 'app/controllers/descriptors_controller.rb', line 186

def descriptor_params
  params.require(:descriptor).permit(
    :name, :short_name, :key_name, :description_name,
    :description, :position, :type, :gene_attribute_logic, :default_unit, :weight,
    character_states_attributes: [:id, :descriptor_id, :_destroy, :label, :name, :position, :description_name, :key_name],
    gene_attributes_attributes: [:id, :_destroy, :sequence_id, :sequence_relationship_type, :controlled_vocabulary_term_id, :position ]
  )
end

#destroyObject

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



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

def destroy
  @descriptor.destroy
  respond_to do |format|
    if @descriptor.destroyed?
      format.html { destroy_redirect @descriptor, notice: 'Descriptor was successfully destroyed.' }
      format.json { head :no_content }
    else
      format.html { destroy_redirect @descriptor, notice: 'Descriptor was not destroyed, ' + @descriptor.errors.full_messages.join('; ') }
      format.json { render json: @descriptor.errors, status: :unprocessable_entity }
    end
  end
end

#editObject

GET /descriptors/1/edit



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

def edit
  redirect_to new_descriptor_task_path(descriptor_id: @descriptor.id), notice: 'Editing in new interface.'
end

#indexObject

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.where(project_id: sessions_current_project_id).limit(20)
    }
  end
end

#listObject



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

#newObject

GET /descriptors/new



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

def new
  @descriptor = Descriptor.new
  redirect_to new_descriptor_task_path(), notice: 'Using task interface.'
end

#preview_modify_gene_descriptor_batch_loadObject



117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/descriptors_controller.rb', line 117

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

#preview_qualitative_descriptor_batch_loadObject



128
129
130
131
132
133
134
135
136
137
# File 'app/controllers/descriptors_controller.rb', line 128

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

#searchObject



98
99
100
101
102
103
104
105
# File 'app/controllers/descriptors_controller.rb', line 98

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

#set_descriptorObject (private)



182
183
184
# File 'app/controllers/descriptors_controller.rb', line 182

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

#showObject

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



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

def show
end

#unitsObject



176
177
178
# File 'app/controllers/descriptors_controller.rb', line 176

def units
  render json: UNITS
end

#updateObject

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/descriptors_controller.rb', line 59

def update
  respond_to do |format|
    begin
      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
      # Can not cascade destroy Observations
    rescue ActiveRecord::RecordNotDestroyed
      format.html { render :edit }
      format.json { render json: 'Could not destroy, do observations still exist?', status: :unprocessable_entity }
    end
  end
end