Class: Admin::DocumentsController

Inherits:
AdminController show all
Defined in:
app/controllers/admin/documents_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /documents POST /documents.json



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/controllers/admin/documents_controller.rb', line 143

def create
  @document = Document.new(document_params)
  @document.friendlier_id = @document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:id])
  respond_to do |format|
    if @document.save
      format.html { redirect_to admin_documents_path, notice: "Document was successfully created." }
      format.json { render :show, status: :created, location: @document }
    else
      format.html { render :edit }
      format.json { render json: @document.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /documents/1 DELETE /documents/1.json



173
174
175
176
177
178
179
180
181
# File 'app/controllers/admin/documents_controller.rb', line 173

def destroy
  @document.destroy
  respond_to do |format|
    format.html do
      redirect_to admin_documents_url, notice: "Document '#{@document.title}' was successfully destroyed."
    end
    format.json { head :no_content }
  end
end

#editObject

GET /documents/1/edit



134
135
# File 'app/controllers/admin/documents_controller.rb', line 134

def edit
end

#fetchObject

Fetch documents from array of friendlier_ids



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/admin/documents_controller.rb', line 75

def fetch
  @request = "#{request.protocol}#{request.host}:#{request.port}"
  @documents = Document.where(friendlier_id: params["ids"])

  respond_to do |format|
    format.html { render :index }
    format.json { render json: @documents.to_json }

    # JSON - BTAA Aardvark
    format.json_btaa_aardvark do
      ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_btaa_aardvark"},
        ExportJsonService)
      head :no_content
    end

    # JSON - GBL Aardvark
    format.json_aardvark do
      ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_aardvark"},
        ExportJsonService)
      head :no_content
    end

    # JSON - GBL v1
    format.json_gbl_v1 do
      ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_gbl_v1"},
        ExportJsonService)
      head :no_content
    end

    # CSV - B1G
    format.csv do
      ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv"},
        ExportCsvService)
      head :no_content
    end

    # CSV Document Downloads - B1G
    format.csv_document_downloads do
      ExportJob.perform_later(@request, current_user,
        {ids: @documents.pluck(:friendlier_id), format: "csv_document_downloads"}, ExportCsvDocumentDownloadsService)
      head :no_content
    end

    # CSV Document Downloads - B1G
    format.csv_document_access_links do
      ExportJob.perform_later(@request, current_user,
        {ids: @documents.pluck(:friendlier_id), format: "csv_document_access_links"}, ExportCsvDocumentAccessLinksService)
      head :no_content
    end
  end
end

#indexObject

GET /documents GET /documents.json



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/admin/documents_controller.rb', line 12

def index
  @request = "#{request.protocol}#{request.host}:#{request.port}"

  query_params = {
    q: params["q"],
    f: params["f"],
    page: params["page"],
    rows: params["rows"] || 20,
    sort: params["sort"] || "score desc",
    daterange: params["daterange"] || nil
  }
  @documents = BlacklightApi.new(@request, **query_params)

  respond_to do |format|
    format.html { render :index }
    format.json { render json: @documents.results.to_json }

    # JSON - BTAA Aardvark
    format.json_btaa_aardvark do
      ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_btaa_aardvark"}),
        ExportJsonService)
      head :no_content
    end

    # JSON - GBL Aardvark
    format.json_aardvark do
      ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_aardvark"}), ExportJsonService)
      head :no_content
    end

    # JSON - GBL v1
    format.json_gbl_v1 do
      ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_gbl_v1"}), ExportJsonService)
      head :no_content
    end

    # JSON - FILE
    format.json_file do
      ExportJsonBulkJob.perform_later(@request, current_user, query_params.merge!({format: "json_file"}), ExportJsonService)
      head :no_content
    end

    # CSV - B1G
    format.csv do
      ExportJob.perform_later(@request, current_user, query_params, ExportCsvService)
      head :no_content
    end

    # CSV Document Downloads - B1G
    format.csv_document_downloads do
      ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentDownloadsService)
      head :no_content
    end

    # CSV Document Access Links - B1G
    format.csv_document_access_links do
      ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentAccessLinksService)
      head :no_content
    end
  end
end

#newObject

GET /documents/new



128
129
130
131
# File 'app/controllers/admin/documents_controller.rb', line 128

def new
  @document = Document.new
  render :edit
end

#showObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'app/controllers/admin/documents_controller.rb', line 183

def show
  respond_to do |format|
    format.html { redirect_to edit_admin_document_url(@document) }
    format.json { render json: @document.to_json } # App-style JSON
    format.json_aardvark
    format.json_btaa_aardvark
    format.json_gbl_v1
    # B1G CSV
    format.csv { send_data collect_csv([@document]), filename: "documents-#{Time.zone.today}.csv" }

    # @TODO:
    # geoblacklight_version: 1.0 (strict)
    # geoblacklight_version: 1.0 + B1G customizations
    # geoblacklight_version: 2.0 (strict)
    # geoblacklight_version: 2.0 + B1G customizations
  end
end

#updateObject

PATCH/PUT /documents/1 PATCH/PUT /documents/1.json



159
160
161
162
163
164
165
166
167
168
169
# File 'app/controllers/admin/documents_controller.rb', line 159

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

#versionsObject

GET /documents/1/versions



138
139
# File 'app/controllers/admin/documents_controller.rb', line 138

def versions
end