Class: Lcms::Engine::Admin::ResourcesController

Inherits:
AdminController show all
Defined in:
app/controllers/lcms/engine/admin/resources_controller.rb

Constant Summary collapse

CREATE_TAG_KEYS =
%i(new_topic_names new_tag_names new_content_source_names
new_standard_names).freeze
CREATE_TAG_METHODS =
{
  new_topic_names: 'topic',
  new_tag_names: 'tag',
  new_content_source_names: 'content_source'
}.freeze

Constants inherited from AdminController

AdminController::RE_GOOGLE_FOLDER

Instance Method Summary collapse

Methods inherited from AdminController

document_path, engine_klass, host_engine_path, material_path, root_path, settings, #whoami

Instance Method Details

#bundleObject



52
53
54
55
56
57
58
59
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 52

def bundle
  return redirect_to :admin_resources, notice: t('.fail') unless can_bundle?(@resource)

  # see settings loaded via `lcms.yml`
  generator = DocTemplate.config.dig('bundles', @resource.curriculum_type).constantize
  generator.perform(@resource)
  redirect_to :admin_resources, notice: t('.success')
end

#createObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 28

def create
  @resource = Resource.new(resource_params)

  if @resource.save
    create_tags
    redirect_to :admin_resources, notice: t('.success', resource_id: @resource.id)
  else
    render :new
  end
end

#destroyObject



79
80
81
82
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 79

def destroy
  @resource.destroy
  redirect_to :admin_resources, notice: t('.success', resource_id: @resource.id)
end

#editObject



39
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 39

def edit; end

#export_to_lti_ccObject



41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 41

def export_to_lti_cc
  # TODO: Later may need to extend this check to allow unit export as well
  unless @resource.module?
    return redirect_back fallback_location: admin_resources_path, notice: 'Unsupported resource type'
  end

  data = LtiExporter.perform @resource
  filename = "#{@resource.slug.parameterize}.zip"
  send_data data, filename: filename, type: 'application/zip', disposition: 'attachment'
end

#indexObject



17
18
19
20
21
22
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 17

def index
  @query = Resource.ransack(params[:q].try(:except, :grades))
  resources = @query.result.includes(:standards)
  resources = resources.where_grade(grade_params) if grade_params.present?
  @resources = resources.order(id: :desc).paginate(page: params[:page], per_page: 15)
end

#newObject



24
25
26
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 24

def new
  @resource = Resource.new
end

#updateObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 61

def update
  unless Settings[:editing_enabled]
    return redirect_to(:admin_resources, alert: t('admin.common.editing_disabled'))
  end

  create_tags
  Array.wrap(create_params[:new_standard_names]).each do |std_name|
    std = Standard.create_with(subject: @resource.subject).find_or_create_by!(name: std_name)
    resource_params[:standard_ids] << std.id
  end

  if @resource.update_attributes(resource_params)
    redirect_to :admin_resources, notice: t('.success', resource_id: @resource.id)
  else
    render :edit
  end
end