Class: DatasetsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DatasetsController
- Defined in:
- app/controllers/datasets_controller.rb
Overview
Display, modify, delete, and analyze datasets belonging to a given user
This controller is responsible for the handling of the datasets which belong to a given user. It displays the user's list of datasets, and handles the starting and management of the user's background analysis tasks.
Instance Method Summary (collapse)
-
- (undefined) add
Add a single document to a dataset.
-
- (undefined) create
Create a new dataset in the database.
-
- (undefined) dataset_list
Show the list of datasets for this user.
-
- (undefined) delete
Show a confirmation box for deleting a dataset.
-
- (undefined) destroy
Delete a dataset from the database.
-
- (undefined) index
Show all of the current user's datasets.
-
- (undefined) new
Show the form for creating a new dataset.
-
- (undefined) show
Show information about the requested dataset.
-
- (undefined) task_destroy
Delete an analysis task.
-
- (undefined) task_download
Download a file from an analysis task.
-
- (undefined) task_list
Show the list of analysis tasks for this dataset.
-
- (undefined) task_start
Start an analysis task for this dataset.
-
- (undefined) task_view
Show a view from an analysis task.
Methods inherited from ApplicationController
#ensure_trailing_slash, #set_locale, #set_timezone, #trailing_slash?
Instance Method Details
- (undefined) add
Add a single document to a dataset
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/datasets_controller.rb', line 98 def add # This isn't a member action, so that it can be called easily from # a form. Get the id from :dataset_id, not :id. @dataset = current_user.datasets.find(params[:dataset_id]) raise ActiveRecord::RecordNotFound unless @dataset @document = Document.find(params[:shasum]) raise ActiveRecord::RecordNotFound unless @document # No reason for this to be a delayed job, just do the create @dataset.entries.create({ :shasum => params[:shasum] }) redirect_to dataset_path(@dataset) end |
- (undefined) create
Create a new dataset in the database
69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/datasets_controller.rb', line 69 def create Delayed::Job.enqueue Jobs::CreateDataset.new( :user_id => current_user.to_param, :name => params[:dataset][:name], :q => params[:q], :fq => params[:fq], :qt => params[:qt]), :queue => 'ui' redirect_to datasets_path, :notice => I18n.t('datasets.create.building') end |
- (undefined) dataset_list
Show the list of datasets for this user
This list needs to be updated live, as the datasets are being created in the background. This action is to be called via AJAX.
27 28 29 30 |
# File 'app/controllers/datasets_controller.rb', line 27 def dataset_list @datasets = current_user.datasets render :layout => false end |
- (undefined) delete
Show a confirmation box for deleting a dataset
60 61 62 63 64 |
# File 'app/controllers/datasets_controller.rb', line 60 def delete @dataset = current_user.datasets.find(params[:id]) raise ActiveRecord::RecordNotFound unless @dataset render :layout => 'dialog' end |
- (undefined) destroy
Delete a dataset from the database
83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/datasets_controller.rb', line 83 def destroy @dataset = current_user.datasets.find(params[:id]) raise ActiveRecord::RecordNotFound unless @dataset redirect_to @dataset and return if params[:cancel] Delayed::Job.enqueue Jobs::DestroyDataset.new( :user_id => current_user.to_param, :dataset_id => params[:id]), :queue => 'ui' redirect_to datasets_path end |
- (undefined) index
Show all of the current user's datasets
17 18 |
# File 'app/controllers/datasets_controller.rb', line 17 def index end |
- (undefined) new
Show the form for creating a new dataset
52 53 54 55 |
# File 'app/controllers/datasets_controller.rb', line 52 def new @dataset = current_user.datasets.build render :layout => 'dialog' end |
- (undefined) show
Show information about the requested dataset
This action also includes links for users to perform various analysis tasks on the dataset.
39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/datasets_controller.rb', line 39 def show @dataset = current_user.datasets.find(params[:id]) raise ActiveRecord::RecordNotFound unless @dataset if params[:clear_failed] && @dataset.analysis_tasks.failed.count > 0 @dataset.analysis_tasks.failed.destroy_all flash[:notice] = t('datasets.show.deleted') end end |
- (undefined) task_destroy
Delete an analysis task
This action deletes a given analysis task and its associated files.
177 178 179 180 181 182 183 184 185 186 187 |
# File 'app/controllers/datasets_controller.rb', line 177 def task_destroy dataset = current_user.datasets.find(params[:id]) raise ActiveRecord::RecordNotFound unless dataset redirect_to dataset and return if params[:cancel] task = dataset.analysis_tasks.find(params[:task_id]) raise ActiveRecord::RecordNotFound unless task task.destroy redirect_to dataset_path end |
- (undefined) task_download
Download a file from an analysis task
This method sends a user a result file from an analysis task. It requires a dataset ID and a task ID.
196 197 198 199 200 201 202 203 204 205 |
# File 'app/controllers/datasets_controller.rb', line 196 def task_download dataset = current_user.datasets.find(params[:id]) raise ActiveRecord::RecordNotFound unless dataset task = dataset.analysis_tasks.find(params[:task_id]) raise ActiveRecord::RecordNotFound unless task raise ActiveRecord::RecordNotFound unless task.result_file raise ActiveRecord::RecordNotFound unless File.exists?(task.result_file.filename) task.result_file.send_file(self) end |
- (undefined) task_list
Show the list of analysis tasks for this dataset
This list needs to be updated live, as the tasks are running in the background, so we split this off to a small AJAX action.
118 119 120 121 122 123 |
# File 'app/controllers/datasets_controller.rb', line 118 def task_list @dataset = current_user.datasets.find(params[:id]) raise ActiveRecord::RecordNotFound unless @dataset render :layout => false end |
- (undefined) task_start
Start an analysis task for this dataset
This method dynamically determines the appropriate background job to start and starts it. It requires a dataset ID.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/datasets_controller.rb', line 132 def task_start dataset = current_user.datasets.find(params[:id]) raise ActiveRecord::RecordNotFound unless dataset klass = AnalysisTask.job_class(params[:class]) # Put the job parameters together out of the job hash job_params = {} if params[:job_params] job_params = params[:job_params].to_hash job_params.symbolize_keys! end job_params[:user_id] = current_user.to_param job_params[:dataset_id] = dataset.to_param # Enqueue the job Delayed::Job.enqueue klass.new(job_params), :queue => 'analysis' redirect_to dataset_path(dataset) end |
- (undefined) task_view
Show a view from an analysis task
Background jobs are packaged with some of their own views. This controller action renders one of those views directly.
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'app/controllers/datasets_controller.rb', line 158 def task_view @dataset = current_user.datasets.find(params[:id]) raise ActiveRecord::RecordNotFound unless @dataset @task = @dataset.analysis_tasks.find(params[:task_id]) raise ActiveRecord::RecordNotFound unless @task raise ActiveRecord::RecordNotFound unless params[:view] klass = @task.job_class render :template => klass.view_path(params[:view]) end |