Class: Admin::DocumentLicensedAccessesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /document_licensed_accesses POST /document_licensed_accesses.json Creates a new document licensed access.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 65

def create
  @document_licensed_access = DocumentLicensedAccess.new(document_licensed_access_params)
  logger.debug("DA Params: #{DocumentLicensedAccess.new(document_licensed_access_params).inspect}")
  logger.debug("Document LICENSED ACCESS: #{@document_licensed_access.inspect}")

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

#destroyObject

DELETE /document_licensed_accesses/1 DELETE /document_licensed_accesses/1.json Deletes a specific document licensed access.



103
104
105
106
107
108
109
110
111
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 103

def destroy
  @document_licensed_access.destroy
  respond_to do |format|
    format.html do
      redirect_to admin_document_document_licensed_accesses_path(@document), notice: "Document licensed access was successfully destroyed."
    end
    format.json { head :no_content }
  end
end

#destroy_allObject

DELETE /document_licensed_accesses/destroy_all Deletes all document licensed access links provided in the params.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 115

def destroy_all
  logger.debug("Destroy Access Links")
  return unless params.dig(:document_licensed_access, :assets, :file)

  respond_to do |format|
    if DocumentLicensedAccess.destroy_all(params.dig(:document_licensed_access, :assets, :file))
      format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document Licensed Access Links were created destroyed." }
    else
      format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document Licensed Access Links could not be destroyed." }
    end
  rescue => e
    format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document Licensed Access Links could not be destroyed. #{e}" }
  end
end

#editObject

GET /document_licensed_accesses/1/edit Renders a form for editing an existing document licensed access.



59
60
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 59

def edit
end

#importObject

GET /documents/#id/licensed_access/import POST /documents/#id/licensed_access/import Imports document licensed access links from a file provided in the params.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 133

def import
  logger.debug("Import Action")
  return unless params.dig(:document_licensed_access, :assets, :file)

  respond_to do |format|
    if DocumentLicensedAccess.import(params.dig(:document_licensed_access, :assets, :file))
      format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document licensed access links were created successfully." }
    else
      format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document licensed access links could not be created." }
    end
  rescue => e
    format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document licensed access links could not be created. #{e}" }
  end
end

#indexObject

GET /documents/#id/licensed_access GET /documents/#id/licensed_access.json Lists all document licensed accesses, optionally filtered by document_id.



37
38
39
40
41
42
43
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 37

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

#newObject

GET /document_licensed_accesses/new Renders a form for creating a new document licensed access.



53
54
55
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 53

def new
  @document_licensed_access = DocumentLicensedAccess.new
end

#showObject

GET /document_licensed_accesses/1 GET /document_licensed_accesses/1.json Displays a specific document licensed access.



48
49
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 48

def show
end

#updateObject

PATCH/PUT /document_licensed_accesses/1 PATCH/PUT /document_licensed_accesses/1.json Updates an existing document licensed access.



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/admin/document_licensed_accesses_controller.rb', line 86

def update
  respond_to do |format|
    if @document_licensed_access.update(document_licensed_access_params)
      format.html do
        redirect_to admin_document_document_licensed_accesses_path(@document), notice: "Document licensed access was successfully updated."
      end
      format.json { render :show, status: :ok, location: @document_licensed_access }
    else
      format.html { render :edit }
      format.json { render json: @document_licensed_access.errors, status: :unprocessable_entity }
    end
  end
end