Class: ObservationMatricesController

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

#autocompleteObject



89
90
91
# File 'app/controllers/observation_matrices_controller.rb', line 89

def autocomplete
  @observation_matrices = ObservationMatrix.where(project_id: sessions_current_project_id).where('name ilike ?', "%#{params[:term]}%")
end

#columnObject



156
157
158
# File 'app/controllers/observation_matrices_controller.rb', line 156

def column
  @observation_matrix_column = ObservationMatrixColumn.where(project_id: sessions_current_project_id).find(params.require(:observation_matrix_column_id))
end

#createObject

POST /observation_matrices POST /observation_matrices.json



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

def create
  @observation_matrix = ObservationMatrix.new(observation_matrix_params)

  respond_to do |format|
    if @observation_matrix.save
      format.html { redirect_to @observation_matrix, notice: 'Matrix was successfully created.' }
      format.json { render :show, status: :created, location: @observation_matrix }
    else
      format.html { render :new }
      format.json { render json: @observation_matrix.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /observation_matrices/1 DELETE /observation_matrices/1.json



81
82
83
84
85
86
87
# File 'app/controllers/observation_matrices_controller.rb', line 81

def destroy
  @observation_matrix.destroy
  respond_to do |format|
    format.html { redirect_to observation_matrices_url, notice: 'Matrix was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#downloadObject



161
162
163
# File 'app/controllers/observation_matrices_controller.rb', line 161

def download
  send_data Export::Download.generate_csv(ObservationMatrix.where(project_id: sessions_current_project_id)), type: 'text', filename: "observation_matrices_#{DateTime.now}.csv"
end

#download_contentsObject



165
166
167
# File 'app/controllers/observation_matrices_controller.rb', line 165

def download_contents
  send_data Export::Download.generate_csv(ObservationMatrix.where(project_id: sessions_current_project_id)), type: 'text', filename: "observation_matrices_#{DateTime.now}.csv"
end

#editObject

GET /observation_matrices/1/edit



34
35
# File 'app/controllers/observation_matrices_controller.rb', line 34

def edit
end

#indexObject

GET /observation_matrices GET /observation_matrices.json



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

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

#listObject



24
25
26
# File 'app/controllers/observation_matrices_controller.rb', line 24

def list
  @observation_matrices = ObservationMatrix.with_project_id(sessions_current_project_id).page(params[:page])
end

#newObject

GET /observation_matrices/new



29
30
31
# File 'app/controllers/observation_matrices_controller.rb', line 29

def new
  redirect_to new_matrix_task_path, notice: 'Redirecting to new task.'
end

#nexmlObject

TODO export formats can move to a concern controller



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

def nexml
  @options = nexml_params
  respond_to do |format|
    base =  '/observation_matrices/export/nexml/nexml'
    format.html { render base }
    format.text {
      s = render_to_string(base, layout: false, formats: [:rdf])
      send_data(s, filename: "nexml_#{DateTime.now}.xml", type: 'text/plain')
    }
  end
end

#nexml_paramsObject (private)

TODO: Not all params are supported yet.



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'app/controllers/observation_matrices_controller.rb', line 186

def nexml_params
  { observation_matrix: @observation_matrix,
    target: '', 
    include_otus: 'true',
    include_collection_objects: 'true',
    include_descriptors: 'true',
    include_matrix: 'true', 
    include_trees: 'false',
    rdf: false }.merge!(
      params.permit(
        :include_otus,
        :include_collection_objects,
        :include_descriptors,
        :include_matrix,
        :include_trees,
        :rdf
      ).to_h
    )
end

#nexusObject



139
140
141
142
143
144
145
146
147
148
# File 'app/controllers/observation_matrices_controller.rb', line 139

def nexus
  respond_to do |format|
    base = '/observation_matrices/export/nexus/'
    format.html { render base + 'index' }
    format.text {
      s = render_to_string(partial: base + 'nexus', locals: { as_file: true }, layout: false, formats: [:html])
      send_data(s, filename: "nexus_#{DateTime.now}.nex", type: 'text/plain')
    }
  end
end

#observation_matrix_paramsObject (private)



239
240
241
# File 'app/controllers/observation_matrices_controller.rb', line 239

def observation_matrix_params
  params.require(:observation_matrix).permit(:name)
end

#otu_contentsObject



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

def otu_contents
  @options = otu_contents_params
  respond_to do |format|
    #base =  '/observation_matrices/export/otu_contents/'
    #format.html { render base + 'index' }
    format.text {
      s = ObservationMatrices::Export::OtuContentsHelper.get_otu_contents(@options)
      send_data(s, filename: "otu_contents_#{DateTime.now}.csv", type: 'text/plain')
    }
  end
end

#otu_contents_paramsObject (private)



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'app/controllers/observation_matrices_controller.rb', line 206

def otu_contents_params
  { observation_matrix: @observation_matrix,
    target: '',
    include_otus: 'true',
    include_collection_objects: 'false',
    include_contents: 'true',
    include_distribution: 'true',
    include_type: 'true',
    taxon_name: 'true',
    include_nomenclature: 'true',
    include_autogenerated_description: 'true',
    include_depictions: 'true',
    rdf: false }.merge!(
    params.permit(
      :include_otus,
      :include_collection_objects,
      :include_matrix,
      :include_contents,
      :include_distribution,
      :include_type,
      :taxon_name,
      :include_nomenclature,
      :include_autogenerated_description,
      :include_depictions,
      :rdf
    ).to_h
  )
end

#otus_used_in_matricesObject



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'app/controllers/observation_matrices_controller.rb', line 169

def otus_used_in_matrices
  #ObservationMatrix.with_otu_ids_array([13597, 25680])
  if !params[:otu_ids].blank?
    p = ObservationMatrix.with_otu_id_array(params[:otu_ids].split('|')).pluck(:id)
    if p.nil?
      render json: {otus_used_in_matrices: ''}.to_json
    else
      render json: {otus_used_in_matrices: p}.to_json
    end
  else
    render json: {otus_used_in_matrices: ''}.to_json
  end
end

#reorder_columnsObject



75
76
77
# File 'app/controllers/observation_matrices_controller.rb', line 75

def reorder_columns
  @observation_matrix.reorder_columns(params.require(:by))
end

#reorder_rowsObject



67
68
69
70
71
72
73
# File 'app/controllers/observation_matrices_controller.rb', line 67

def reorder_rows
  if @observation_matrix.reorder_rows(params.require(:by))
    render json: :success
  else
    render json:  :error, status: :unprocessable_entity 
  end
end

#rowObject

GET /observation_matrices/row.json?observation_matrix_row_id=1 TODO: Why is this here? (used in Matrix Row Coder)



152
153
154
# File 'app/controllers/observation_matrices_controller.rb', line 152

def row
  @observation_matrix_row = ObservationMatrixRow.where(project_id: sessions_current_project_id).find(params.require(:observation_matrix_row_id))
end

#searchObject



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

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

#set_observation_matrixObject (private)



235
236
237
# File 'app/controllers/observation_matrices_controller.rb', line 235

def set_observation_matrix
  @observation_matrix = ObservationMatrix.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /observation_matrices/1 GET /observation_matrices/1.json



21
22
# File 'app/controllers/observation_matrices_controller.rb', line 21

def show
end

#tntObject



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

def tnt
  respond_to do |format|
    base = '/observation_matrices/export/tnt/'
    format.html { render base + 'index' }
    format.text {
      s = render_to_string(partial: base + 'tnt', locals: { as_file: true }, layout: false, formats: [:html])
      send_data(s, filename: "tnt_#{DateTime.now}.tnt", type: 'text/plain')
    }
  end
end

#updateObject

PATCH/PUT /observation_matrices/1 PATCH/PUT /observation_matrices/1.json



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

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