Class: Lcms::Engine::Admin::MaterialsController

Inherits:
AdminController show all
Includes:
GoogleCredentials, PathHelper, Reimportable
Defined in:
app/controllers/lcms/engine/admin/materials_controller.rb

Constant Summary

Constants inherited from AdminController

AdminController::RE_GOOGLE_FOLDER

Instance Method Summary collapse

Methods included from PathHelper

#dynamic_document_path, #dynamic_material_path, #dynamic_path

Methods inherited from AdminController

settings

Instance Method Details

#createObject



20
21
22
23
24
25
26
# File 'app/controllers/lcms/engine/admin/materials_controller.rb', line 20

def create
  @material_form = DocumentGenerator.material_form.new(form_params.except(:async))

  return create_multiple if form_params[:link].match?(RE_GOOGLE_FOLDER)

  form_params[:async].to_i.zero? ? create_sync : create_async
end

#destroyObject



28
29
30
31
32
# File 'app/controllers/lcms/engine/admin/materials_controller.rb', line 28

def destroy
  material = Material.find(params[:id])
  material.destroy
  redirect_to lcms_engine.admin_materials_path(query: @query_params), notice: t('.success')
end

#destroy_selectedObject



34
35
36
37
# File 'app/controllers/lcms/engine/admin/materials_controller.rb', line 34

def destroy_selected
  count = @materials.destroy_all.count
  redirect_to lcms_engine.admin_materials_path(query: @query_params), notice: t('.success', count: count)
end

#import_statusObject



39
40
41
42
# File 'app/controllers/lcms/engine/admin/materials_controller.rb', line 39

def import_status
  data = import_status_for DocumentGenerator.material_parse_job
  render json: data, status: :ok
end

#indexObject



14
15
16
17
18
# File 'app/controllers/lcms/engine/admin/materials_controller.rb', line 14

def index
  @query = OpenStruct.new @query_params # rubocop:disable Style/OpenStructUse
  @materials = DocTemplate.config['queries']['material'].constantize.call(@query, page: params[:page])
  render_customized_view
end

#newObject



44
45
46
# File 'app/controllers/lcms/engine/admin/materials_controller.rb', line 44

def new
  @material_form = MaterialForm.new(source_type: params[:source_type].presence || 'gdoc')
end

#reimport_selectedObject



48
49
50
51
# File 'app/controllers/lcms/engine/admin/materials_controller.rb', line 48

def reimport_selected
  bulk_import @materials.map(&:file_url)
  render :import
end