From eb70ef4c077f2c98eada9a432833e96bb153b890 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 11 Jun 2012 16:03:22 -0400 Subject: [PATCH 1/2] Directly call toggleArrow in sequence render There might be a chance that an error got thrown after 'contentChanged' event was fired and stop the `toggleArrow()` method to be called. This will make sure that the navigation will still be working even some element in the content is failed. --- lms/static/coffee/spec/modules/sequence_spec.coffee | 5 ++++- lms/static/coffee/src/modules/sequence.coffee | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lms/static/coffee/spec/modules/sequence_spec.coffee b/lms/static/coffee/spec/modules/sequence_spec.coffee index 6ff79c1805..1e5447d847 100644 --- a/lms/static/coffee/spec/modules/sequence_spec.coffee +++ b/lms/static/coffee/spec/modules/sequence_spec.coffee @@ -24,7 +24,6 @@ describe 'Sequence', -> expect(titles).toEqual ['Video 1', 'Video 2', 'Sample Problem'] it 'bind the page events', -> - expect(@sequence.element).toHandleWith 'contentChanged', @sequence.toggleArrows expect($('#sequence-list a')).toHandleWith 'click', @sequence.goto it 'render the active sequence content', -> @@ -76,6 +75,7 @@ describe 'Sequence', -> spyOn $, 'postWithPrefix' @sequence = new Sequence '1', @items, 'sequence' spyOnEvent @sequence.element, 'contentChanged' + spyOn(@sequence, 'toggleArrows').andCallThrough() describe 'with a different position than the current one', -> beforeEach -> @@ -105,6 +105,9 @@ describe 'Sequence', -> it 'update the position', -> expect(@sequence.position).toEqual 1 + it 're-update the arrows', -> + expect(@sequence.toggleArrows).toHaveBeenCalled() + it 'trigger contentChanged event', -> expect('contentChanged').toHaveBeenTriggeredOn @sequence.element diff --git a/lms/static/coffee/src/modules/sequence.coffee b/lms/static/coffee/src/modules/sequence.coffee index 56a9b551bf..463bf419fc 100644 --- a/lms/static/coffee/src/modules/sequence.coffee +++ b/lms/static/coffee/src/modules/sequence.coffee @@ -9,7 +9,6 @@ class @Sequence $(selector, @element) bind: -> - @element.bind 'contentChanged', @toggleArrows @$('#sequence-list a').click @goto buildNavigation: -> @@ -43,6 +42,7 @@ class @Sequence MathJax.Hub.Queue(["Typeset", MathJax.Hub]) @position = new_position + @toggleArrows() @element.trigger 'contentChanged' goto: (event) => From b4ed14f4f72a9910ba54a7f558375a83c102ca19 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 11 Jun 2012 16:07:09 -0400 Subject: [PATCH 2/2] Handle the case where histogram score can be null This will leave out the student that never attempt the question and fixes the error with histogram rendering. --- lms/static/coffee/spec/histogram_spec.coffee | 2 +- lms/static/coffee/src/histogram.coffee | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lms/static/coffee/spec/histogram_spec.coffee b/lms/static/coffee/spec/histogram_spec.coffee index 4fd7ef98c3..7a377221b3 100644 --- a/lms/static/coffee/spec/histogram_spec.coffee +++ b/lms/static/coffee/spec/histogram_spec.coffee @@ -11,7 +11,7 @@ describe 'Histogram', -> describe 'calculate', -> beforeEach -> - @histogram = new Histogram(1, [[1, 1], [2, 2], [3, 3]]) + @histogram = new Histogram(1, [[null, 1], [1, 1], [2, 2], [3, 3]]) it 'store the correct value for data', -> expect(@histogram.data).toEqual [[1, Math.log(2)], [2, Math.log(3)], [3, Math.log(4)]] diff --git a/lms/static/coffee/src/histogram.coffee b/lms/static/coffee/src/histogram.coffee index 59d06e25a0..e81b6080aa 100644 --- a/lms/static/coffee/src/histogram.coffee +++ b/lms/static/coffee/src/histogram.coffee @@ -8,6 +8,7 @@ class @Histogram calculate: -> for [score, count] in @rawData + continue if score == null log_count = Math.log(count + 1) @data.push [score, log_count] @xTicks.push [score, score.toString()]