Skip to content

Commit

Permalink
Limit dashboard questions to the current universe if universe scope i…
Browse files Browse the repository at this point in the history
…s set
  • Loading branch information
drusepth committed Mar 1, 2017
1 parent a8e0382 commit f20a9f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ def dashboard
attempts = 0

begin
@content = current_user.content.values.flatten.sample
@question = @content.question unless @content.nil?
if @universe_scope.present? && attempts < 2
content_pool = current_user.content_in_universe(@universe_scope).values.flatten
else
content_pool = current_user.content.values.flatten
end

@content = content_pool.sample
@question = @content.question unless @content.nil?
raise RetryMe if @content.present? && (@question.nil? || @question[:question].nil?) # :(
rescue RetryMe
attempts += 1
Expand Down
15 changes: 15 additions & 0 deletions app/models/concerns/has_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ def content
}
end

def content_in_universe universe_id
{
characters: characters.in_universe(universe_id),
items: items.in_universe(universe_id),
locations: locations.in_universe(universe_id),
creatures: creatures.in_universe(universe_id),
races: races.in_universe(universe_id),
religions: religions.in_universe(universe_id),
magics: magics.in_universe(universe_id),
languages: languages.in_universe(universe_id),
scenes: scenes.in_universe(universe_id),
groups: groups.in_universe(universe_id)
}
end

def content_count
[
characters.length,
Expand Down

0 comments on commit f20a9f1

Please sign in to comment.