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 RedirectHelper

#destroy_redirect

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



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_indexObject



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_showObject



95
96
97
# File 'app/controllers/downloads_controller.rb', line 95

def api_show
  render '/downloads/api/v1/show'
end

#destroyObject

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



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/downloads_controller.rb', line 37

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.full_messages.join('; ') }
      format.json { render json: @download.errors, status: :unprocessable_entity }
    end
  end
end

#download_paramsObject (private)



113
114
115
# File 'app/controllers/downloads_controller.rb', line 113

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

#editObject

GET /downloads/1/edit



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

def edit
end

#fileObject

GET /downloads/1/file



71
72
73
74
75
76
77
78
# File 'app/controllers/downloads_controller.rb', line 71

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

#filter_paramsObject (private)



101
102
103
# File 'app/controllers/downloads_controller.rb', line 101

def filter_params
  params.permit(:download_type)
end

#indexObject

GET /downloads GET /downloads.json



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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(filter_params)
        .all
        .where(project_id: sessions_current_project_id)
        .page(params[:page])
        .per(params[:per] || 20)
    }
  end
end

#listObject

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



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

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

#set_downloadObject (private)



105
106
107
# File 'app/controllers/downloads_controller.rb', line 105

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

#set_download_apiObject (private)



109
110
111
# File 'app/controllers/downloads_controller.rb', line 109

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



28
29
# File 'app/controllers/downloads_controller.rb', line 28

def show
end

#updateObject

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



52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/downloads_controller.rb', line 52

def update
  respond_to do |format|
    if @download.update(download_params)
      format.html { redirect_to @download.metamorphosize, notice: 'Download was successfully updated.' }
      format.json { render :show, location: @download.metamorphosize }
    else
      format.html { render action: 'edit' }
      format.json { render json: @download.errors, status: :unprocessable_entity }
    end
  end
end