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


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

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

#createObject

POST /observation_matrices POST /observation_matrices.json


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

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


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

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


145
146
147
# File 'app/controllers/observation_matrices_controller.rb', line 145

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

#editObject

GET /observation_matrices/1/edit


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

def edit
end

#indexObject

GET /observation_matrices GET /observation_matrices.json


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

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


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

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

#newObject

GET /observation_matrices/new


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

def new
  @observation_matrix = ObservationMatrix.new
end

#nexmlObject

TODO export formats can move to a concern controller


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

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.


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'app/controllers/observation_matrices_controller.rb', line 152

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


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

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)


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

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

#reorder_columnsObject


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

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

#reorder_rowsObject


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

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?


141
142
143
# File 'app/controllers/observation_matrices_controller.rb', line 141

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

#searchObject


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

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)


172
173
174
# File 'app/controllers/observation_matrices_controller.rb', line 172

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


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

def show
end

#tntObject


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

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


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

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