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 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



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

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

#autocompleteObject



83
84
85
86
# File 'app/controllers/descriptors_controller.rb', line 83

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

#batch_loadObject



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

def batch_load
end

#batch_paramsObject (private)



155
156
157
158
159
# File 'app/controllers/descriptors_controller.rb', line 155

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
56
# 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



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

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

#descriptor_paramsObject (private)



146
147
148
149
150
151
152
153
# File 'app/controllers/descriptors_controller.rb', line 146

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



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

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

#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



107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/descriptors_controller.rb', line 107

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

#searchObject



88
89
90
91
92
93
94
95
# File 'app/controllers/descriptors_controller.rb', line 88

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)



142
143
144
# File 'app/controllers/descriptors_controller.rb', line 142

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



136
137
138
# File 'app/controllers/descriptors_controller.rb', line 136

def units
  render json: UNITS
end

#updateObject

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



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

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