Class: Admin::DocumentDownloadsController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/document_downloads_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /document_downloads or /document_downloads.json



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/admin/document_downloads_controller.rb', line 33

def create
  @document_download = DocumentDownload.new(document_download_params)

  logger.debug("DD Params: #{DocumentDownload.new(document_download_params).inspect}")
  logger.debug("Document DOWNLOAD: #{@document_download.inspect}")

  respond_to do |format|
    if @document_download.save
      format.html do
        redirect_to admin_document_document_downloads_path(@document_download.document),
          notice: "Document download was successfully created."
      end
      format.json { render :show, status: :created, location: @document_download }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @document_download.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /document_downloads/1 or /document_downloads/1.json



70
71
72
73
74
75
76
77
# File 'app/controllers/admin/document_downloads_controller.rb', line 70

def destroy
  @document_download.destroy

  respond_to do |format|
    format.html { redirect_to admin_document_downloads_url, notice: "Document download was successfully destroyed." }
    format.json { head :no_content }
  end
end

#destroy_allObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/admin/document_downloads_controller.rb', line 79

def destroy_all
  logger.debug("Destroy Downloads")
  return unless params.dig(:document_download, :downloads, :file)

  respond_to do |format|
    if DocumentDownload.destroy_all(params.dig(:document_download, :downloads, :file))
      format.html { redirect_to admin_document_downloads_path, notice: "Download Links were destroyed." }
    else
      format.html { redirect_to admin_document_downloads_path, notice: "Download Links could not be destroyed." }
    end
  rescue => e
    format.html { redirect_to admin_document_downloads_path, notice: "Download Links could not be destroyed. #{e}" }
  end
end

#editObject

GET /document_downloads/1/edit



29
30
# File 'app/controllers/admin/document_downloads_controller.rb', line 29

def edit
end

#importObject

GET /documents/#id/downloads/import POST /documents/#id/downloads/import



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/admin/document_downloads_controller.rb', line 96

def import
  logger.debug("Import Downloads")
  return unless params.dig(:document_download, :downloads, :file)

  respond_to do |format|
    if DocumentDownload.import(params.dig(:document_download, :downloads, :file))
      format.html { redirect_to admin_document_downloads_path, notice: "Download Links were created successfully." }
    else
      format.html { redirect_to admin_document_downloads_path, notice: "Download Links could not be created." }
    end
  rescue => e
    format.html { redirect_to admin_document_downloads_path, notice: "Download Links could not be created. #{e}" }
  end
end

#indexObject

GET /document_downloads or /document_downloads.json



10
11
12
13
14
15
16
17
# File 'app/controllers/admin/document_downloads_controller.rb', line 10

def index
  @document_downloads = DocumentDownload.all
  if params[:document_id]
    @document_downloads = DocumentDownload.where(friendlier_id: @document.friendlier_id).order(position: :asc)
  else
    @pagy, @document_downloads = pagy(DocumentDownload.all.order(friendlier_id: :asc, updated_at: :desc), items: 20)
  end
end

#newObject

GET /document_downloads/new



24
25
26
# File 'app/controllers/admin/document_downloads_controller.rb', line 24

def new
  @document_download = DocumentDownload.new
end

#showObject

GET /document_downloads/1 or /document_downloads/1.json



20
21
# File 'app/controllers/admin/document_downloads_controller.rb', line 20

def show
end

#updateObject

PATCH/PUT /document_downloads/1 or /document_downloads/1.json



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/admin/document_downloads_controller.rb', line 54

def update
  respond_to do |format|
    if @document_download.update(document_download_params)
      format.html do
        redirect_to admin_document_document_downloads_path(@document_download.document),
          notice: "Document download was successfully updated."
      end
      format.json { render :show, status: :ok, location: @document_download }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @document_download.errors, status: :unprocessable_entity }
    end
  end
end