Class: DownloadsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DownloadsController
- Defined in:
- app/controllers/downloads_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #api_file ⇒ Object
- #api_index ⇒ Object
- #api_show ⇒ Object
-
#destroy ⇒ Object
DELETE /downloads/1 DELETE /downloads/1.json.
- #download_params ⇒ Object private
-
#edit ⇒ Object
GET /downloads/1/edit.
-
#file ⇒ Object
GET /downloads/1/file.
-
#index ⇒ Object
GET /downloads GET /downloads.json.
-
#list ⇒ Object
GET /downloads/list GET /downloads/list.json.
- #set_download ⇒ Object private
- #set_download_api ⇒ Object private
-
#show ⇒ Object
GET /downloads/1.
-
#update ⇒ Object
PATCH /downloads/1 PATCH /downloads/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_file ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/controllers/downloads_controller.rb', line 86 def api_file if @download.ready? @download.increment!(:times_downloaded) send_file @download.file_path else render json: { success: false } end end |
#api_index ⇒ Object
80 81 82 83 84 |
# File 'app/controllers/downloads_controller.rb', line 80 def api_index @downloads = Download.where(is_public: true, project_id: sessions_current_project_id) .order('downloads.id').page(params[:page]).per(params[:per]) render '/downloads/api/v1/index' end |
#api_show ⇒ Object
95 96 97 |
# File 'app/controllers/downloads_controller.rb', line 95 def api_show render '/downloads/api/v1/show' end |
#destroy ⇒ Object
DELETE /downloads/1 DELETE /downloads/1.json
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/downloads_controller.rb', line 36 def destroy @download.destroy respond_to do |format| if @download.destroyed? format.html { destroy_redirect @download, notice: 'Download was successfully destroyed.' } format.json { head :no_content} else format.html { destroy_redirect @download, notice: 'Download was not destroyed, ' + @download.errors..join('; ') } format.json { render json: @download.errors, status: :unprocessable_entity } end end end |
#download_params ⇒ Object (private)
109 110 111 |
# File 'app/controllers/downloads_controller.rb', line 109 def download_params params.require(:download).permit(:is_public, :name, :expires ) end |
#edit ⇒ Object
GET /downloads/1/edit
31 32 |
# File 'app/controllers/downloads_controller.rb', line 31 def edit end |
#file ⇒ Object
GET /downloads/1/file
70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/downloads_controller.rb', line 70 def file if @download.ready? @download.increment!(:times_downloaded) response.headers["Content-Length"] = File.size(@download.file_path).to_s send_file @download.file_path else redirect_to download_url end end |
#index ⇒ Object
GET /downloads GET /downloads.json
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/downloads_controller.rb', line 11 def index respond_to do |format| format.html do @recent_objects = Download.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' end format.json { @downloads = Queries::Download::Filter.new(params) .all .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
GET /downloads/list GET /downloads/list.json
65 66 67 |
# File 'app/controllers/downloads_controller.rb', line 65 def list @downloads = Download.where(project_id: sessions_current_project_id).order(:id).page(params[:page]).per(params[:per]) end |
#set_download ⇒ Object (private)
101 102 103 |
# File 'app/controllers/downloads_controller.rb', line 101 def set_download @download = Download.unscoped.where(project_id: sessions_current_project_id).find(params[:id]) end |
#set_download_api ⇒ Object (private)
105 106 107 |
# File 'app/controllers/downloads_controller.rb', line 105 def set_download_api @download = Download.unscoped.where(is_public: true, project_id: sessions_current_project_id).find(params[:id]) end |
#show ⇒ Object
GET /downloads/1
27 28 |
# File 'app/controllers/downloads_controller.rb', line 27 def show end |
#update ⇒ Object
PATCH /downloads/1 PATCH /downloads/1.json
51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/downloads_controller.rb', line 51 def update respond_to do |format| if @download.update(download_params) format.html { redirect_to @download., notice: 'Download was successfully updated.' } format.json { render :show, location: @download. } else format.html { render action: 'edit' } format.json { render json: @download.errors, status: :unprocessable_entity } end end end |