diff --git a/app/coffeescripts/views/assignments/AssignmentGroupListItemView.coffee b/app/coffeescripts/views/assignments/AssignmentGroupListItemView.coffee index 9a59e1a2ec9..9b123471d39 100644 --- a/app/coffeescripts/views/assignments/AssignmentGroupListItemView.coffee +++ b/app/coffeescripts/views/assignments/AssignmentGroupListItemView.coffee @@ -207,17 +207,19 @@ define [ search: (regex, gradingPeriod) -> @resetBorders() + assignmentCount = @collection.reduce( (count, as) => + count++ if as.search(regex, gradingPeriod) + count + , 0) - atleastone = false - @collection.each (as) => - atleastone = true if as.search(regex, gradingPeriod) + atleastone = assignmentCount > 0 if atleastone @show() @expand(false) @borderFix() else @hide() - atleastone + assignmentCount endSearch: -> @resetBorders() diff --git a/app/coffeescripts/views/assignments/IndexView.coffee b/app/coffeescripts/views/assignments/IndexView.coffee index 9666307dade..514a083f3b8 100644 --- a/app/coffeescripts/views/assignments/IndexView.coffee +++ b/app/coffeescripts/views/assignments/IndexView.coffee @@ -9,6 +9,7 @@ define [ 'jst/assignments/NoAssignmentsSearch' 'compiled/views/assignments/AssignmentKeyBindingsMixin' 'compiled/userSettings' + 'compiled/jquery.rails_flash_notifications' ], (I18n, KeyboardNavDialog, keyboardNavTemplate, $, _, Backbone, template, NoAssignments, AssignmentKeyBindingsMixin, userSettings) -> class IndexView extends Backbone.View @@ -90,9 +91,13 @@ define [ else regex = new RegExp(@cleanSearchTerm(term), 'ig') #search - atleastoneGroup = false - @collection.each (group) => - atleastoneGroup = true if group.groupView.search(regex, gradingPeriod) + matchingAssignmentCount = @collection.reduce( (runningTotal, group) -> + additionalCount = group.groupView.search(regex, gradingPeriod) + runningTotal + additionalCount + , 0) + + atleastoneGroup = matchingAssignmentCount > 0 + @alertForMatchingGroups(matchingAssignmentCount) #add noAssignments placeholder if !atleastoneGroup @@ -109,6 +114,15 @@ define [ @noAssignments.remove() @noAssignments = null + alertForMatchingGroups: (numAssignments) -> + msg = I18n.t({ + one: "1 assignment found." + other: "%{count} assignments found." + zero: "No matching assignments found." + }, count: numAssignments + ) + $.screenReaderFlashMessageExclusive(msg) + cleanSearchTerm: (text) -> text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") diff --git a/app/coffeescripts/views/quizzes/IndexView.coffee b/app/coffeescripts/views/quizzes/IndexView.coffee index b0596084997..617afe16bd1 100644 --- a/app/coffeescripts/views/quizzes/IndexView.coffee +++ b/app/coffeescripts/views/quizzes/IndexView.coffee @@ -1,10 +1,12 @@ define [ + 'i18n!quizzes' 'jquery' 'underscore' 'Backbone' 'compiled/views/quizzes/QuizItemGroupView' 'jst/quizzes/IndexView' -], ($, _, Backbone, QuizItemGroupView, template) -> + 'compiled/jquery.rails_flash_notifications' +], (I18n, $, _, Backbone, QuizItemGroupView, template) -> class IndexView extends Backbone.View template: template @@ -37,8 +39,27 @@ define [ keyUpSearch: _.debounce -> @filterResults() + @announceCount() , 200 filterResults: => _.each @views(), (view) => view.filterResults($('#searchTerm').val()) + + announceCount: => + searchTerm = $('#searchTerm').val() + return if searchTerm == '' || searchTerm == null + + matchingQuizCount = _.reduce(@views(), (runningCount, view) => + return runningCount + view.matchingCount(searchTerm) + , 0) + @announceMatchingQuizzes(matchingQuizCount) + + announceMatchingQuizzes: (numQuizzes) -> + msg = I18n.t({ + one: "1 quiz found." + other: "%{count} quizzes found." + zero: "No matching quizzes found." + }, count: numQuizzes + ) + $.screenReaderFlashMessageExclusive(msg) diff --git a/app/coffeescripts/views/quizzes/QuizItemGroupView.coffee b/app/coffeescripts/views/quizzes/QuizItemGroupView.coffee index f6058221d2d..2e5cb00337d 100644 --- a/app/coffeescripts/views/quizzes/QuizItemGroupView.coffee +++ b/app/coffeescripts/views/quizzes/QuizItemGroupView.coffee @@ -32,9 +32,13 @@ define [ if !!model.get('hidden') != hidden anyChanged = true model.set('hidden', hidden) - @render() if anyChanged + matchingCount: (term) => + _.select( @collection.models, (m) => + @filter(m, term) + ).length + filter: (model, term) => return true unless term