canvas-lms/app/controllers/outcomes_controller.rb

316 lines
14 KiB
Ruby
Raw Normal View History

2011-02-01 09:57:29 +08:00
#
# Copyright (C) 2011 - present Instructure, Inc.
2011-02-01 09:57:29 +08:00
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
class OutcomesController < ApplicationController
include Api::V1::Outcome
before_action :require_context, :except => [:build_outcomes]
add_crumb(proc { t "#crumbs.outcomes", "Outcomes" }, :except => [:destroy, :build_outcomes]) { |c| c.send :named_context_url, c.instance_variable_get("@context"), :context_outcomes_path }
before_action { |c| c.active_tab = "outcomes" }
before_action :rich_content_service_config, only: [:show, :index]
2011-02-01 09:57:29 +08:00
def index
return unless authorized_action(@context, @current_user, :read)
return unless tab_enabled?(@context.class::TAB_OUTCOMES)
log_asset_access([ "outcomes", @context ], "outcomes", "other")
@root_outcome_group = @context.root_outcome_group
if (common_core_group_id = Setting.get(AcademicBenchmark.common_core_setting_key, nil))
common_core_group_id = common_core_group_id.to_i
common_core_group_url = polymorphic_path([:api_v1, :global, :outcome_group], :id => common_core_group_id)
2011-02-01 09:57:29 +08:00
end
js_env(:ROOT_OUTCOME_GROUP => outcome_group_json(@root_outcome_group, @current_user, session),
:CONTEXT_URL_ROOT => polymorphic_path([@context]),
:ACCOUNT_CHAIN_URL => polymorphic_path([:api_v1, @context, :account_chain]),
# Don't display state standards if in the context of a Course. Only at Account level.
:STATE_STANDARDS_URL => @context.is_a?(Course) ? nil : api_v1_global_redirect_path,
:COMMON_CORE_GROUP_ID => common_core_group_id,
:COMMON_CORE_GROUP_URL => common_core_group_url,
:PERMISSIONS => {
:manage_outcomes => @context.grants_right?(@current_user, session, :manage_outcomes),
:manage_rubrics => @context.grants_right?(@current_user, session, :manage_rubrics),
:manage_courses => @context.grants_right?(@current_user, session, :manage_courses)
})
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def show
if @context.respond_to?(:large_roster?) && @context.large_roster?
flash[:notice] = t "#application.notices.page_disabled_for_course", "That page has been disabled for this course"
redirect_to named_context_url(@context, :context_outcomes_path)
return
end
learning outcomes refactor This list is *NOT* complete, some items may have snuck in that I forgot to note, and/or some of the noted items may not be completely functional yet. Specs need to be written around a lot of this, other specs will no doubt need to be fixed. Some things, particularly around LearningOutcomeGroups will need data migrations that aren't there yet. * remove LearningOutcome.non_rubric_outcomes? and replace with false where invoked * remove LearningOutcome.enabled? and replace with true where invoked * remove never-taken branches * remove the shared/aligned_outcomes partial and it's supporting javascript, since it's now empty * remove js handler for add_outcome_alignment_link and supporting method since it only occurred in never-taken branches * mix LearningOutcomeContext into Course and Account * replace LearningOutcomeGroup.default_for(context) with LearningOutcomeContext#root_outcome_group * rename LearningOutcome#content_tags to LearningOutcome#alignments * rename LearningOutcomeGroup#content_tags to LearningOutcomeGroup#child_links, and properly restrict * remove ContentTag[Alignment]#rubric_association_id, add ContentTag[Alignment]#has_rubric_association? that looks at the presence of the content's rubric_association_id * condition off the assignment having a rubric_association rather than filtering tags by has_rubric_association (which just looks back at the assignment). all or none of the assignment's alignments are forced to have the association (via the assignment). this was true in practice before, is now codified (and more efficient) * rename AssessmentQuestionBank#learning_outcome_tags to AssessmentQuestionBank#learning_outcome_alignments * rename Assignment#learning_outcome_tags to Assignment#learning_outcome_alignments * rename Rubric#learning_outcome_tags to Rubric#learning_outcome_alignments * move/rename (Course|Account)#learning_outcome_tags to LearningOutcomeContext#learning_outcome_links * move/rename Account#learning_outcomes (corrected) and Course#learning_outcomes to LearningOutcomeContext#linked_learning_outcomes * move/rename Account#created_learning_outcomes and Course#created_learning_outcomes to LearningOutcomeContext#created_learning_outcomes * clarify and correct usage of linked_learning_outcomes vs. created_learning_outcomes * move/rename (Account|Account)#learning_outcome_groups to LearningOutcomeContext#learning_outcome_groups * remove unused Account#associated_learning_outcomes * just remove one link to a learning outcome when deleting * merge Account#has_outcomes?, Course#has_outcomes? and Course#has_outcomes into LearningOutcomeContext#has_outcomes?, add a use in Context#active_record_types * kill LearningOutcomeGroup#root_learning_outcome_group (unused) * rename LearningOutcomeResult#content_tag to LearningOutcomeResult#alignment * kill unused (and broken) OutcomesController#add_outcome_group * kill unused OutcomesController#update_outcomes_for_asset * kill unused OutcomesController#outcomes_for_asset * remove unused (outside specs, correct specs) AssessmentQuestionBank#outcomes= * remove unused ContentTag#learning_outcome_content * replace ContentTag.learning_outcome_tags_for(asset) (only ever called with asset=an assignment) with call to Assignment#learning_outcome_alignments * remove unused ContentTag.not_rubric * remove (now) unused ContentTag.include_outcome * remove unused LearningOutcome#learning_outcome_group_associations * avoid explicit use of ContentTag in outcome-related specs * replace LearningOutcomeGroup#learning_outcome_tags with LearningOutcomeGroup#child_outcome_links (and only use for outcome links; not tags for child groups) * split ContentTag#create_outcome_result into Submission#create_outcome_result, QuizSubmission#create_outcome_result, and RubricAssessment#create_outcome_result. fix some bugs along the way * refactor ContentTag.outcome_tags_for_banks and some code from QuizSubmission#(track_outcomes|update_outcomes_for_assessment_questions) into QuizSubmission#questions_and_alignments * refactor RubricAssociation#update_outcome_relations and Rubric#update_alignments into LearningOutcome.update_alignments * don't use ContentTag#rubric_association with outcome alignments; use the tag's content's rubric_association in its place (they should have been equal anyways) * refactor LearningOutcome.available_in_context and @context.root_outcome_group.sorted_all_outcomes (only time sorted_all_outcomes is used) into LearningOutcomeContext#available_outcomes and LearningOutcomeContext#available_outcome * overhaul LearningOutcomeGroup#sorted_content and rename to LearningOutcomeGroup#sorted_children. it not returns ContentTags (outcome links) and LearningOutcomeGroups, vs. LearningOutcomes and LearningOutcomeGroups; fix usages appropriately * fix UI for arranging/deleting outcome links and groups within a group to refer to the outcome link rather than the outcome Change-Id: I85d99f2634f7206332cb1f5d5ea575b428988d4b Reviewed-on: https://gerrit.instructure.com/12590 Reviewed-by: Jacob Fugal <jacob@instructure.com> Tested-by: Jacob Fugal <jacob@instructure.com>
2012-07-13 01:16:13 +08:00
@outcome = @context.linked_learning_outcomes.find(params[:id])
return unless authorized_action(@context, @current_user, :manage_outcomes)
log_asset_access(@outcome, "outcomes", "outcomes")
codes = [@context].map(&:asset_string)
if @context.is_a?(Account)
if @context == @outcome.context
codes = "all"
else
codes = @context.all_courses.pluck(:id).map{|id| "course_#{id}"}
2011-02-01 09:57:29 +08:00
end
end
@alignments = @outcome.alignments.active.for_context(@context)
add_crumb(@outcome.short_description, named_context_url(@context, :context_outcome_url, @outcome.id))
@results = @outcome.learning_outcome_results.for_context_codes(codes).custom_ordering(params[:sort]).paginate(:page => params[:page], :per_page => 10)
js_env({
:PERMISSIONS => {
:manage_outcomes => @context.grants_right?(@current_user, session, :manage_outcomes)
}
})
2011-02-01 09:57:29 +08:00
end
def details
learning outcomes refactor This list is *NOT* complete, some items may have snuck in that I forgot to note, and/or some of the noted items may not be completely functional yet. Specs need to be written around a lot of this, other specs will no doubt need to be fixed. Some things, particularly around LearningOutcomeGroups will need data migrations that aren't there yet. * remove LearningOutcome.non_rubric_outcomes? and replace with false where invoked * remove LearningOutcome.enabled? and replace with true where invoked * remove never-taken branches * remove the shared/aligned_outcomes partial and it's supporting javascript, since it's now empty * remove js handler for add_outcome_alignment_link and supporting method since it only occurred in never-taken branches * mix LearningOutcomeContext into Course and Account * replace LearningOutcomeGroup.default_for(context) with LearningOutcomeContext#root_outcome_group * rename LearningOutcome#content_tags to LearningOutcome#alignments * rename LearningOutcomeGroup#content_tags to LearningOutcomeGroup#child_links, and properly restrict * remove ContentTag[Alignment]#rubric_association_id, add ContentTag[Alignment]#has_rubric_association? that looks at the presence of the content's rubric_association_id * condition off the assignment having a rubric_association rather than filtering tags by has_rubric_association (which just looks back at the assignment). all or none of the assignment's alignments are forced to have the association (via the assignment). this was true in practice before, is now codified (and more efficient) * rename AssessmentQuestionBank#learning_outcome_tags to AssessmentQuestionBank#learning_outcome_alignments * rename Assignment#learning_outcome_tags to Assignment#learning_outcome_alignments * rename Rubric#learning_outcome_tags to Rubric#learning_outcome_alignments * move/rename (Course|Account)#learning_outcome_tags to LearningOutcomeContext#learning_outcome_links * move/rename Account#learning_outcomes (corrected) and Course#learning_outcomes to LearningOutcomeContext#linked_learning_outcomes * move/rename Account#created_learning_outcomes and Course#created_learning_outcomes to LearningOutcomeContext#created_learning_outcomes * clarify and correct usage of linked_learning_outcomes vs. created_learning_outcomes * move/rename (Account|Account)#learning_outcome_groups to LearningOutcomeContext#learning_outcome_groups * remove unused Account#associated_learning_outcomes * just remove one link to a learning outcome when deleting * merge Account#has_outcomes?, Course#has_outcomes? and Course#has_outcomes into LearningOutcomeContext#has_outcomes?, add a use in Context#active_record_types * kill LearningOutcomeGroup#root_learning_outcome_group (unused) * rename LearningOutcomeResult#content_tag to LearningOutcomeResult#alignment * kill unused (and broken) OutcomesController#add_outcome_group * kill unused OutcomesController#update_outcomes_for_asset * kill unused OutcomesController#outcomes_for_asset * remove unused (outside specs, correct specs) AssessmentQuestionBank#outcomes= * remove unused ContentTag#learning_outcome_content * replace ContentTag.learning_outcome_tags_for(asset) (only ever called with asset=an assignment) with call to Assignment#learning_outcome_alignments * remove unused ContentTag.not_rubric * remove (now) unused ContentTag.include_outcome * remove unused LearningOutcome#learning_outcome_group_associations * avoid explicit use of ContentTag in outcome-related specs * replace LearningOutcomeGroup#learning_outcome_tags with LearningOutcomeGroup#child_outcome_links (and only use for outcome links; not tags for child groups) * split ContentTag#create_outcome_result into Submission#create_outcome_result, QuizSubmission#create_outcome_result, and RubricAssessment#create_outcome_result. fix some bugs along the way * refactor ContentTag.outcome_tags_for_banks and some code from QuizSubmission#(track_outcomes|update_outcomes_for_assessment_questions) into QuizSubmission#questions_and_alignments * refactor RubricAssociation#update_outcome_relations and Rubric#update_alignments into LearningOutcome.update_alignments * don't use ContentTag#rubric_association with outcome alignments; use the tag's content's rubric_association in its place (they should have been equal anyways) * refactor LearningOutcome.available_in_context and @context.root_outcome_group.sorted_all_outcomes (only time sorted_all_outcomes is used) into LearningOutcomeContext#available_outcomes and LearningOutcomeContext#available_outcome * overhaul LearningOutcomeGroup#sorted_content and rename to LearningOutcomeGroup#sorted_children. it not returns ContentTags (outcome links) and LearningOutcomeGroups, vs. LearningOutcomes and LearningOutcomeGroups; fix usages appropriately * fix UI for arranging/deleting outcome links and groups within a group to refer to the outcome link rather than the outcome Change-Id: I85d99f2634f7206332cb1f5d5ea575b428988d4b Reviewed-on: https://gerrit.instructure.com/12590 Reviewed-by: Jacob Fugal <jacob@instructure.com> Tested-by: Jacob Fugal <jacob@instructure.com>
2012-07-13 01:16:13 +08:00
@outcome = @context.linked_learning_outcomes.find(params[:outcome_id])
return unless authorized_action(@context, @current_user, :read)
@outcome.tie_to(@context)
render :json => @outcome.as_json(
:methods => :artifacts_count_for_tied_context,
:user_content => %w(description))
end
2011-02-01 09:57:29 +08:00
def outcome_results
learning outcomes refactor This list is *NOT* complete, some items may have snuck in that I forgot to note, and/or some of the noted items may not be completely functional yet. Specs need to be written around a lot of this, other specs will no doubt need to be fixed. Some things, particularly around LearningOutcomeGroups will need data migrations that aren't there yet. * remove LearningOutcome.non_rubric_outcomes? and replace with false where invoked * remove LearningOutcome.enabled? and replace with true where invoked * remove never-taken branches * remove the shared/aligned_outcomes partial and it's supporting javascript, since it's now empty * remove js handler for add_outcome_alignment_link and supporting method since it only occurred in never-taken branches * mix LearningOutcomeContext into Course and Account * replace LearningOutcomeGroup.default_for(context) with LearningOutcomeContext#root_outcome_group * rename LearningOutcome#content_tags to LearningOutcome#alignments * rename LearningOutcomeGroup#content_tags to LearningOutcomeGroup#child_links, and properly restrict * remove ContentTag[Alignment]#rubric_association_id, add ContentTag[Alignment]#has_rubric_association? that looks at the presence of the content's rubric_association_id * condition off the assignment having a rubric_association rather than filtering tags by has_rubric_association (which just looks back at the assignment). all or none of the assignment's alignments are forced to have the association (via the assignment). this was true in practice before, is now codified (and more efficient) * rename AssessmentQuestionBank#learning_outcome_tags to AssessmentQuestionBank#learning_outcome_alignments * rename Assignment#learning_outcome_tags to Assignment#learning_outcome_alignments * rename Rubric#learning_outcome_tags to Rubric#learning_outcome_alignments * move/rename (Course|Account)#learning_outcome_tags to LearningOutcomeContext#learning_outcome_links * move/rename Account#learning_outcomes (corrected) and Course#learning_outcomes to LearningOutcomeContext#linked_learning_outcomes * move/rename Account#created_learning_outcomes and Course#created_learning_outcomes to LearningOutcomeContext#created_learning_outcomes * clarify and correct usage of linked_learning_outcomes vs. created_learning_outcomes * move/rename (Account|Account)#learning_outcome_groups to LearningOutcomeContext#learning_outcome_groups * remove unused Account#associated_learning_outcomes * just remove one link to a learning outcome when deleting * merge Account#has_outcomes?, Course#has_outcomes? and Course#has_outcomes into LearningOutcomeContext#has_outcomes?, add a use in Context#active_record_types * kill LearningOutcomeGroup#root_learning_outcome_group (unused) * rename LearningOutcomeResult#content_tag to LearningOutcomeResult#alignment * kill unused (and broken) OutcomesController#add_outcome_group * kill unused OutcomesController#update_outcomes_for_asset * kill unused OutcomesController#outcomes_for_asset * remove unused (outside specs, correct specs) AssessmentQuestionBank#outcomes= * remove unused ContentTag#learning_outcome_content * replace ContentTag.learning_outcome_tags_for(asset) (only ever called with asset=an assignment) with call to Assignment#learning_outcome_alignments * remove unused ContentTag.not_rubric * remove (now) unused ContentTag.include_outcome * remove unused LearningOutcome#learning_outcome_group_associations * avoid explicit use of ContentTag in outcome-related specs * replace LearningOutcomeGroup#learning_outcome_tags with LearningOutcomeGroup#child_outcome_links (and only use for outcome links; not tags for child groups) * split ContentTag#create_outcome_result into Submission#create_outcome_result, QuizSubmission#create_outcome_result, and RubricAssessment#create_outcome_result. fix some bugs along the way * refactor ContentTag.outcome_tags_for_banks and some code from QuizSubmission#(track_outcomes|update_outcomes_for_assessment_questions) into QuizSubmission#questions_and_alignments * refactor RubricAssociation#update_outcome_relations and Rubric#update_alignments into LearningOutcome.update_alignments * don't use ContentTag#rubric_association with outcome alignments; use the tag's content's rubric_association in its place (they should have been equal anyways) * refactor LearningOutcome.available_in_context and @context.root_outcome_group.sorted_all_outcomes (only time sorted_all_outcomes is used) into LearningOutcomeContext#available_outcomes and LearningOutcomeContext#available_outcome * overhaul LearningOutcomeGroup#sorted_content and rename to LearningOutcomeGroup#sorted_children. it not returns ContentTags (outcome links) and LearningOutcomeGroups, vs. LearningOutcomes and LearningOutcomeGroups; fix usages appropriately * fix UI for arranging/deleting outcome links and groups within a group to refer to the outcome link rather than the outcome Change-Id: I85d99f2634f7206332cb1f5d5ea575b428988d4b Reviewed-on: https://gerrit.instructure.com/12590 Reviewed-by: Jacob Fugal <jacob@instructure.com> Tested-by: Jacob Fugal <jacob@instructure.com>
2012-07-13 01:16:13 +08:00
@outcome = @context.linked_learning_outcomes.find(params[:outcome_id])
return unless authorized_action(@context, @current_user, :read)
codes = [@context].map(&:asset_string)
if @context.is_a?(Account)
if @context == @outcome.context
codes = "all"
else
codes = @context.all_courses.pluck(:id).map{|id| "course_#{id}"}
2011-02-01 09:57:29 +08:00
end
end
@results = @outcome.learning_outcome_results.for_context_codes(codes).custom_ordering(params[:sort])
render :json => Api.paginate(@results, self, polymorphic_url([@context, :outcome_results]))
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def user_outcome_results
user_id = params[:user_id]
if @context.is_a?(User)
@user = @context
elsif @context.is_a?(Course)
@user = @context.users.find(user_id)
else
@user = @context.all_users.find_by!(id: user_id)
2011-02-01 09:57:29 +08:00
end
return unless authorized_action(@context, @current_user, :manage)
if @user == @context
@outcomes = LearningOutcome.has_result_for(@user).active
else
@outcomes = @context.available_outcomes
2011-02-01 09:57:29 +08:00
end
@results = LearningOutcomeResult.for_user(@user).for_outcome_ids(@outcomes.map(&:id)) #.for_context_codes(@codes)
@results_for_outcome = @results.group_by(&:learning_outcome_id)
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def list
return unless authorized_action(@context, @current_user, :manage_outcomes)
@account_contexts = @context.associated_accounts rescue []
@current_outcomes = @context.linked_learning_outcomes
@outcomes = Canvas::ICU.collate_by(@context.available_outcomes, &:title)
if params[:unused]
@outcomes -= @current_outcomes
2011-02-01 09:57:29 +08:00
end
render :json => @outcomes.map{ |o| o.as_json(methods: :cached_context_short_name) }
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
# as in, add existing outcome from another context to this context
def add_outcome
return unless authorized_action(@context, @current_user, :manage_outcomes)
@account_contexts = @context.associated_accounts.uniq rescue []
codes = @account_contexts.map(&:asset_string)
@outcome = LearningOutcome.for_context_codes(codes).find(params[:learning_outcome_id])
@group = @context.learning_outcome_groups.find(params[:learning_outcome_group_id])
# this is silly. there should be different actions for moving a link
# (adopt_outcome_link) and adding a new link (add_outcome). as is, you
# can't add a second link to the same outcome under a new group. but just
# refactoring the model layer for now...
if outcome_link = @group.child_outcome_links.where(content_id: @outcome.id).first
@group.adopt_outcome_link(outcome_link)
else
@group.add_outcome(@outcome)
2011-02-01 09:57:29 +08:00
end
render :json => @outcome.as_json(:methods => :cached_context_short_name, :permissions => {:user => @current_user, :session => session})
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def align
return unless authorized_action(@context, @current_user, :manage_outcomes)
@outcome = @context.linked_learning_outcomes.find(params[:outcome_id])
@asset = @context.find_asset(params[:asset_string])
mastery_type = @asset.is_a?(Assignment) ? "points" : "none"
@alignment = @outcome.align(@asset, @context, :mastery_type => mastery_type) if @asset
render :json => @alignment.as_json(:include => :learning_outcome)
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def alignment_redirect
return unless authorized_action(@context, @current_user, :read)
@outcome = @context.available_outcome(params[:outcome_id].to_i)
@alignment = @outcome.alignments.find(params[:id])
content_tag_redirect(@context, @alignment, :context_outcomes_url)
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def remove_alignment
return unless authorized_action(@context, @current_user, :manage_outcomes)
@outcome = @context.available_outcome(params[:outcome_id].to_i)
@outcome.remove_alignment(params[:id], @context)
render :json => @alignment.as_json(:include => :learning_outcome)
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def outcome_result
return unless authorized_action(@context, @current_user, :manage_outcomes)
@outcome = @context.linked_learning_outcomes.find(params[:outcome_id])
@result = @outcome.learning_outcome_results.find(params[:id])
return unless authorized_action(@result.context, @current_user, :manage_outcomes)
if @result.artifact.is_a?(Submission)
@submission = @result.artifact
redirect_to named_context_url(@result.context, :context_assignment_submission_url, @submission.assignment_id, @submission.user_id)
elsif @result.artifact.is_a?(RubricAssessment) && @result.artifact.artifact && @result.artifact.artifact.is_a?(Submission)
@submission = @result.artifact.artifact
redirect_to named_context_url(@result.context, :context_assignment_submission_url, @submission.assignment_id, @submission.user_id)
elsif @result.artifact.is_a?(Quizzes::QuizSubmission) && @result.associated_asset
@submission = @result.artifact
@asset = @result.associated_asset
if @submission.attempt <= @result.attempt
@submission_version = @submission
else
@submission_version = @submission.submitted_attempts.detect{|s| s.attempt >= @result.attempt }
2011-02-01 09:57:29 +08:00
end
if @asset.is_a?(Quizzes::Quiz) && @result.alignment && @result.alignment.content_type == 'AssessmentQuestionBank'
# anchor to first question in aligned bank
question_bank_id = @result.alignment.content_id
first_aligned_question = Quizzes::QuizQuestion.where(quiz_id: @asset.id)
.joins(:assessment_question)
.where(assessment_questions: { assessment_question_bank_id: question_bank_id })
.order(:position)
.first
anchor = first_aligned_question ? "question_#{first_aligned_question.id}" : nil
elsif @asset.is_a? AssessmentQuestion
question = @submission.quiz_data.detect{|q| q['assessment_question_id'] == @asset.data[:id] }
question_id = (question && question['id']) || @asset.data[:id]
anchor = "question_#{question_id}"
end
redirect_to named_context_url(
@result.context, :context_quiz_history_url, @submission.quiz_id,
:quiz_submission_id => @submission.id,
:version => @submission_version.version_number,
:anchor => anchor)
else
flash[:error] = "Unrecognized artifact type: #{@result.try(:artifact_type) || 'nil'}"
redirect_to named_context_url(@context, :context_outcome_url, @outcome.id)
2011-02-01 09:57:29 +08:00
end
end
2011-02-01 09:57:29 +08:00
def reorder_alignments
return unless authorized_action(@context, @current_user, :manage_outcomes)
@outcome = @context.linked_learning_outcomes.find(params[:outcome_id])
@alignments = @outcome.reorder_alignments(@context, params[:order].split(","))
render :json => @alignments.map{ |a| a.as_json(include: :learning_outcome) }
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def create
return unless authorized_action(@context, @current_user, :manage_outcomes)
if params[:learning_outcome_group_id].present?
@outcome_group = @context.learning_outcome_groups.find(params[:learning_outcome_group_id])
end
@outcome_group ||= @context.root_outcome_group
@outcome = @context.created_learning_outcomes.build(learning_outcome_params)
respond_to do |format|
if @outcome.save
@outcome_group.add_outcome(@outcome)
flash[:notice] = t :successful_outcome_creation, "Outcome successfully created!"
format.html { redirect_to named_context_url(@context, :context_outcomes_url) }
format.json { render :json => @outcome }
else
flash[:error] = t :failed_outcome_creation, "Outcome creation failed"
format.html { redirect_to named_context_url(@context, :context_outcomes_url) }
format.json { render :json => @outcome.errors, :status => :bad_request }
2011-02-01 09:57:29 +08:00
end
end
end
2011-02-01 09:57:29 +08:00
def update
return unless authorized_action(@context, @current_user, :manage_outcomes)
@outcome = @context.created_learning_outcomes.find(params[:id])
respond_to do |format|
if @outcome.update_attributes(learning_outcome_params)
flash[:notice] = t :successful_outcome_update, "Outcome successfully updated!"
format.html { redirect_to named_context_url(@context, :context_outcomes_url) }
format.json { render :json => @outcome }
else
flash[:error] = t :failed_outcome_update, "Outcome update failed"
format.html { redirect_to named_context_url(@context, :context_outcomes_url) }
format.json { render :json => @outcome.errors, :statue => :bad_request }
2011-02-01 09:57:29 +08:00
end
end
end
2011-02-01 09:57:29 +08:00
def destroy
return unless authorized_action(@context, @current_user, :manage_outcomes)
respond_to do |format|
# TODO: params[:id] is overloaded to be either a native outcome id or
# the id of a link to a foreign outcome. therefore it's possible to
# intend to delete a link to a foreign but accidentally delete a
# completely unrelated native outcome. needs to be decoupled.
if params[:id].present? && @outcome = @context.created_learning_outcomes.where(id: params[:id]).first
@outcome.destroy
flash[:notice] = t :successful_outcome_delete, "Outcome successfully deleted"
format.json { render :json => @outcome }
elsif params[:id].present? && @link = @context.learning_outcome_links.where(id: params[:id]).first
@link.destroy
flash[:notice] = t :successful_outcome_removal, "Outcome successfully removed"
format.json { render :json => @link.learning_outcome }
else
flash[:notice] = t :missing_outcome, "Couldn't find that learning outcome"
format.json { render :json => {:errors => {:base => t(:missing_outcome, "Couldn't find that learning outcome")}}, :status => :bad_request }
2011-02-01 09:57:29 +08:00
end
format.html { redirect_to named_context_url(@context, :context_outcomes_url) }
2011-02-01 09:57:29 +08:00
end
end
protected
def rich_content_service_config
rce_js_env(:basic)
end
def learning_outcome_params
params.require(:learning_outcome).permit(:description, :short_description, :title, :display_name, :vendor_guid)
end
2011-02-01 09:57:29 +08:00
end