Skip to content

Commit

Permalink
Invalid achievement conditions no longer show up as viable choices
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusf committed Jul 15, 2015
1 parent 76a8365 commit 6e33aa7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/controllers/course/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ def current_component_host
self)
end

# Given an achievement, returns all valid achievement conditions it may depend on.
#
# @param [Course::Achievement] conditional The conditional for which to return conditions.
# @return [Array<Course::Achievement>]
def valid_achievement_conditions(conditional)
Course::Achievement.all -
[conditional] -
conditional.
specific_conditions.
select { |c| c.is_a?(Course::Condition::Achievement) }.
map(&:achievement)
end
helper_method :valid_achievement_conditions

private

# Selects sidebar items of the given type.
Expand Down
2 changes: 1 addition & 1 deletion app/views/course/condition/achievements/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
resource: :course_achievement_condition_achievement do |f|
= f.error_notification
= f.error :course_achievement_condition_achievement
= f.input :achievement_id, collection: Course::Achievement.all
= f.input :achievement_id, collection: valid_achievement_conditions(@conditional)

= f.button :submit

0 comments on commit 6e33aa7

Please sign in to comment.