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

Instance Method Details

#autocompleteObject



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

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



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

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



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

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



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

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



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

def edit
end

#indexObject

GET /observation_matrices GET /observation_matrices.json



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



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

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

#newObject

GET /observation_matrices/new



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

def new
  @observation_matrix = ObservationMatrix.new
end

#nexmlObject

TODO export formats can move to a concern controller



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

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.



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

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



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

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)



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

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

#reorder_columnsObject



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

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

#reorder_rowsObject



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

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?



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

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

#searchObject



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

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)



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

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



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

def show
end

#tntObject



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

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



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

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