fix pinning of discussions on pages > 1

fixes CNVS-8314

test plan:
  * create over 100 discussions in a course;
  * as a teacher, navigate to the course discussions page;
  * scroll to the bottom of the page and, using the gear
    menu, attempt to pin the bottom-most discussion;
  * verify that it properly pins.

Change-Id: Icc064daf2316d8de37e6b45d6e6bb40320f5c90b
Reviewed-on: https://gerrit.instructure.com/24786
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Braden Anderson <banderson@instructure.com>
Product-Review: Zach Pendleton <zachp@instructure.com>
QA-Review: Zach Pendleton <zachp@instructure.com>
This commit is contained in:
Zach Pendleton 2013-09-27 17:21:34 -06:00
parent c61a8efc94
commit 1d73da82a9
3 changed files with 26 additions and 19 deletions

View File

@ -58,7 +58,7 @@ require [
# Returns nothing.
fetchDiscussions: ->
pipeline = new DiscussionTopicsCollection
pipeline.fetch(add: true, data: {order_by: 'recent_activity', per_page: 50})
pipeline.fetch(data: {order_by: 'recent_activity', per_page: 50})
pipeline.on('fetch', @_onPipelineLoad)
pipeline.on('fetched:last', @_onPipelineEnd)
@ -101,8 +101,8 @@ require [
#
# Returns nothing.
_onPipelineLoad: (collection, models) =>
@_sortCollection(collection)
setTimeout((-> collection.fetch(add: true, page: 'next')), 0) if collection.urls.next
@_sortCollection(models)
setTimeout((-> collection.fetch(page: 'next')), 0) if collection.urls.next
# Internal: Handle the last page of discussion topic results, propagating
# the event down to all of the filtered collections.
@ -135,7 +135,7 @@ require [
# Returns an object.
_groupModels: (pipeline) ->
defaults = { pinned: [], locked: [], open: [] }
_.extend(defaults, pipeline.groupBy(@_modelBucket))
_.extend(defaults, _.groupBy(pipeline, @_modelBucket))
# Determine the name of the model's proper collection.
#
@ -143,8 +143,12 @@ require [
#
# Returns a string.
_modelBucket: (model) ->
return 'pinned' if model.get('pinned')
return 'locked' if model.get('locked') || model.get('locked_for_user')
if model.attributes
return 'pinned' if model.get('pinned')
return 'locked' if model.get('locked') || model.get('locked_for_user')
else
return 'pinned' if model.pinned
return 'locked' if model.locked || model.locked_for_user
'open'
# Internal: Move a model from one collection to another.

View File

@ -72,19 +72,6 @@ define [
@model.save(locked: locked, pinned: pinned)
$(e.target).text(@messages[key])
# Public: Pin or unpin the model and update it on the server.
#
# e - Event object.
#
# Returns nothing.
togglePinned: (e) =>
e.preventDefault()
key = if @model.get('pinned') then 'pin' else 'unpin'
pinned = !@model.get('pinned')
locked = if pinned then false else @model.get('locked')
@model.save(locked: locked, pinned: pinned)
$(e.target).text(@messages[key])
# Public: Confirm a request to delete and then complete it if needed.
#
# e - Event object.

View File

@ -359,6 +359,22 @@ describe "discussions" do
ffj('.open.discussion-list li.discussion:visible').length.should == 1
end
it "should allow pinning of all pages of topics" do
100.times do |n|
DiscussionTopic.create!(context: @course, user: @teacher,
title: "Discussion Topic #{n+1}")
end
topic = DiscussionTopic.where(context_id: @course.id).order('id DESC').last
topic.should_not be_pinned
get(url)
wait_for_ajaximations
keep_trying_until { fj(".al-trigger") }
fj("[data-id=#{topic.id}] .al-trigger").click
fj('.icon-pin:visible').click
wait_for_ajaximations
topic.reload.should be_pinned
end
it "should allow locking a pinned topic" do
topic = @course.discussion_topics.create!(title: 'Test Discussion', user: @user, pinned: true)
get(url)