From f20a9f1044142284f8b05c1c783e191ebb76f5dc Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 1 Mar 2017 16:16:44 +0000 Subject: [PATCH] Limit dashboard questions to the current universe if universe scope is set --- app/controllers/main_controller.rb | 9 +++++++-- app/models/concerns/has_content.rb | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 4d4853a28..42ce9a2e8 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -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 diff --git a/app/models/concerns/has_content.rb b/app/models/concerns/has_content.rb index f49275cbb..52c9a8bb8 100644 --- a/app/models/concerns/has_content.rb +++ b/app/models/concerns/has_content.rb @@ -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,