Class: DownloadsController

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

#api_fileObject


56
57
58
59
60
61
62
63
# File 'app/controllers/downloads_controller.rb', line 56

def api_file
  if @download.ready?
    @download.increment!(:times_downloaded)
    send_file @download.file_path
  else
    render json: { success: false }
  end
end

#api_indexObject


51
52
53
54
# File 'app/controllers/downloads_controller.rb', line 51

def api_index
  @downloads = Download.where(is_public: true, project_id: sessions_current_project_id) # .page(params[:page]).per([ [(params[:per] || 100).to_i, 1000].min, 1].max)
  render '/downloads/api/index.json.jbuilder'
end

#api_showObject


65
66
67
# File 'app/controllers/downloads_controller.rb', line 65

def api_show
  render '/downloads/api/show.json.jbuilder'
end

#destroyObject

DELETE /downloads/1 DELETE /downloads/1.json


20
21
22
23
24
25
26
# File 'app/controllers/downloads_controller.rb', line 20

def destroy
  @download.destroy
  respond_to do |format|
    format.html { redirect_to downloads_url, notice: 'Download was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#download_fileObject

GET /downloads/1/download_file


42
43
44
45
46
47
48
49
# File 'app/controllers/downloads_controller.rb', line 42

def download_file
  if @download.ready?
    @download.increment!(:times_downloaded)
    send_file @download.file_path
  else
    redirect_to download_url
  end
end

#download_paramsObject (private)


79
80
81
# File 'app/controllers/downloads_controller.rb', line 79

def download_params
  params.require(:download).permit(:is_public)
end

#indexObject

GET /downloads GET /downloads.json


9
10
11
12
# File 'app/controllers/downloads_controller.rb', line 9

def index
  @recent_objects = Download.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

#listObject

GET /downloads/list GET /downloads/list.json


37
38
39
# File 'app/controllers/downloads_controller.rb', line 37

def list
  @downloads = Download.where(project_id: sessions_current_project_id).order(:id).page(params[:page]).per(params[:per])
end

#set_downloadObject (private)


71
72
73
# File 'app/controllers/downloads_controller.rb', line 71

def set_download
  @download = Download.unscoped.where(project_id: sessions_current_project_id).find(params[:id])
end

#set_download_apiObject (private)


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

def set_download_api
  @download = Download.unscoped.where(is_public: true, project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /downloads/1


15
16
# File 'app/controllers/downloads_controller.rb', line 15

def show
end

#updateObject

PATCH /downloads/1 PATCH /downloads/1.json


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

def update
  @download.update(download_params)
  render action: :show
end