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

Inherits:
AdminController show all
Includes:
ViewHelper
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 included from ViewHelper

ViewHelper::ENABLE_BASE64_CACHING

Constants inherited from AdminController

AdminController::RE_GOOGLE_FOLDER

Instance Method Summary collapse

Methods included from ViewHelper

#add_class_for_action, #add_class_for_path, #base64_encoded_asset, #color_code, #flash_to_hash, #header_mod, #inlined_asset, #lcms_engine_url_helpers, #nav_link, #page_description, #page_og_image, #page_title, #redirect_meta_tag, #redirect_via_meta_tag, #selected_id?, #set_canonical_url, #set_page_description, #set_page_title, #strip_tags_and_squish

Methods inherited from AdminController

settings

Methods included from PathHelper

#dynamic_document_path, #dynamic_material_path, #dynamic_path

Instance Method Details

#bundleObject



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

def bundle
  return redirect_to lcms_engine.admin_resources_path, 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 lcms_engine.admin_resources_path, notice: t('.success')
end

#createObject



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

def create
  @resource = Resource.new(resource_params)

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

#destroyObject



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

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

#editObject



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

def edit; end

#export_to_lti_ccObject



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

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



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

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



26
27
28
# File 'app/controllers/lcms/engine/admin/resources_controller.rb', line 26

def new
  @resource = Resource.new
end

#updateObject



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

def update
  unless Settings[:editing_enabled]
    return redirect_to(lcms_engine.admin_resources_path, 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(resource_params)
    redirect_to lcms_engine.admin_resources_path, notice: t('.success', resource_id: @resource.id)
  else
    render :edit
  end
end