From a2be6dd4204e33593ec4d5150437c6edfde6d523 Mon Sep 17 00:00:00 2001 From: Kevin Chugh Date: Tue, 12 Mar 2013 10:31:05 -0400 Subject: [PATCH 01/12] first cut of UI --- .gitignore | 3 +- .../django_comment_client/forum/views.py | 3 ++ lms/static/images/__MACOSX/._pinned.png | Bin 0 -> 82 bytes lms/static/images/__MACOSX/._unpinned.png | Bin 0 -> 82 bytes lms/static/images/pinned.png | Bin 0 -> 518 bytes lms/static/images/unpinned.png | Bin 0 -> 498 bytes lms/static/sass/_discussion.scss | 37 +++++++++++++++++- .../discussion/_underscore_templates.html | 5 +++ 8 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 lms/static/images/__MACOSX/._pinned.png create mode 100644 lms/static/images/__MACOSX/._unpinned.png create mode 100644 lms/static/images/pinned.png create mode 100644 lms/static/images/unpinned.png diff --git a/.gitignore b/.gitignore index 493df5a7fd..a1af40ffec 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ nosetests.xml cover_html/ .idea/ .redcar/ -chromedriver.log \ No newline at end of file +chromedriver.log +/nbproject diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index a3120c563a..a41cf6c45a 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -210,6 +210,9 @@ def forum_form_discussion(request, course_id): user_cohort_id = get_cohort_id(request.user, course_id) + + + context = { 'csrf': csrf(request)['csrf_token'], 'course': course, diff --git a/lms/static/images/__MACOSX/._pinned.png b/lms/static/images/__MACOSX/._pinned.png new file mode 100644 index 0000000000000000000000000000000000000000..1073ea4c42b27830690abb44fa97664a5e13ef43 GIT binary patch literal 82 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDI}u>uf-_(4F-5a8#Y=IiYg31VXd08sV@ Ap8x;= literal 0 HcmV?d00001 diff --git a/lms/static/images/__MACOSX/._unpinned.png b/lms/static/images/__MACOSX/._unpinned.png new file mode 100644 index 0000000000000000000000000000000000000000..1073ea4c42b27830690abb44fa97664a5e13ef43 GIT binary patch literal 82 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDI}u>uf-_(4F-5a8#Y=IiYg31VXd08sV@ Ap8x;= literal 0 HcmV?d00001 diff --git a/lms/static/images/pinned.png b/lms/static/images/pinned.png new file mode 100644 index 0000000000000000000000000000000000000000..76bb207ffffbe470ecfa81ff8b9b3ee9d8de9100 GIT binary patch literal 518 zcmeAS@N?(olHy`uVBq!ia0vp^AT}Qd8;}%R+`Ae`u@pObhHwBu4M$1`kk47*5m^jW z_Zoy5o4R?UfP$hWt`Q~9MX8A;nfZANA(^?U42DMfCi;d(v!?&Q1XLgcQV^VktX{it;ltjGcOqWeCoIl(?&ae(bN$ErFswPCc}s>;OShxR6tyO)XTtH` z?>|;u$lv*W-sg{VtL>V4n^xsAaxh5D`Tp(|LxKbwL&I&B>s*t~EDg`}SaPkp#!$er zfR7<0U~9wt)Bda9EnRV_<*D5)|BKgluRnY<x4}zPlJ?FI%DisZl84D{ww$S zaIcm{KtYBERi%wPeC`xU^&fk6*0s|2dg*!}nNANKK87=ATTkzs;3IP||2v~P8-u}b zpR+plha5Y8uibq!JxVh^aMHt7!8{CJMln~tesVEf$Pc@HcJk`O=i8s(&8!y@cYK;! zn7((GX4+|ntgt?p5M!RlkN@qkm}7eXTZL83Ns-OdU9K21r$3WWdbLGbcjfvfj4aIt~|b6WrZP<|q3xMhA>9RugaH2*hjA9nzwgu&C*&t;uc GLK6VR%hyE! literal 0 HcmV?d00001 diff --git a/lms/static/images/unpinned.png b/lms/static/images/unpinned.png new file mode 100644 index 0000000000000000000000000000000000000000..030198f7e8d00489d5883eb59dbd38af31c4c267 GIT binary patch literal 498 zcmeAS@N?(olHy`uVBq!ia0vp^AT}Qd8;}%R+`Ae`u@pObhHwBu4M$1`kk47*5m^jW z_Zoy5o4R?UfP$hWt`Q~9MX8A;nfZANA(^?U495C~hWduax}IV`feK_m3WD>~O3D+9 zQW+dm@{>{(+%k(&%kzt}ixr%M&0g%;)Wg8Q=mj zvL+o5HYU#-YD?cb*(szl{X10S81=Vd%1QNzi0-8(DSgs;()|wrU!fnco$2m?i?4dMm<+Kc4PUqUvZjWmu}7DQryMxfW`5` zq@ZVBo|ESAur*))Tld~eQ;@}xn_*7T&X`T|lY$n-t-n9T%l>W7yC3`h_b^HIy3I>3 zR_|K0FeocVg}EUpOUCu00K<#xt5?4)soEW*XTAIGx}%o$pKI%7+8zowc)n8>^u1*A zSEAQ#_T!HgXD#L15`Q?jbe}0uk9KzHw&**WwbiQoafHCdLw3zKTVL|l;$3_4E literal 0 HcmV?d00001 diff --git a/lms/static/sass/_discussion.scss b/lms/static/sass/_discussion.scss index e5134837fe..fe4f37f7aa 100644 --- a/lms/static/sass/_discussion.scss +++ b/lms/static/sass/_discussion.scss @@ -2442,4 +2442,39 @@ body.discussion { color:#000; font-style: italic; background-color:#fff; - } \ No newline at end of file + } + +.discussion-flag-abuse { + font-size: 12px; + float:right; + padding-right: 5px; + font-style: italic; + } + +.notpinned .icon +{ + display: inline-block; + width: 10px; + height: 14px; + padding-right: 3px; + background: transparent url('../images/notpinned.png') no-repeat 0 0; +} + +.pinned .icon +{ + display: inline-block; + width: 10px; + height: 14px; + padding-right: 3px; + background: transparent url('../images/pinned.png') no-repeat 0 0; +} + +.pinned span { + color: #B82066; + font-style: italic; +} + +.notpinned span { + color: #888; + font-style: italic; +} \ No newline at end of file diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index de1ff394bd..7faef4195c 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -45,6 +45,11 @@
${'<%- body %>'}
+ + % if has_permission(user, 'create_comment', course.id): +
+ Pin Thread
+ % endif ${'<% if (obj.courseware_url) { %>'}
(this post is about ${'<%- courseware_title %>'}) From 8280c55992644addbf5ebfd883360ba92d5f2ba5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 12 Mar 2013 17:40:26 -0400 Subject: [PATCH 02/12] pinning .1 --- .../coffee/src/discussion/content.coffee | 13 ++++++ .../static/coffee/src/discussion/utils.coffee | 2 + .../views/discussion_thread_show_view.coffee | 44 +++++++++++++++++++ .../django_comment_client/base/urls.py | 2 + .../django_comment_client/base/views.py | 15 +++++++ .../django_comment_client/permissions.py | 2 + lms/djangoapps/django_comment_client/utils.py | 2 +- lms/lib/comment_client/thread.py | 24 +++++++++- lms/static/sass/_discussion.scss | 4 +- .../discussion/_underscore_templates.html | 2 +- 10 files changed, 104 insertions(+), 6 deletions(-) diff --git a/common/static/coffee/src/discussion/content.coffee b/common/static/coffee/src/discussion/content.coffee index 4e612dfc40..00c34df686 100644 --- a/common/static/coffee/src/discussion/content.coffee +++ b/common/static/coffee/src/discussion/content.coffee @@ -79,6 +79,17 @@ if Backbone? @getContent(id).updateInfo(info) $.extend @contentInfos, infos + pinThread: -> + pinned = @get("pinned") + @set("pinned",pinned) + @trigger "change", @ + + unPinThread: -> + pinned = @get("pinned") + @set("pinned",pinned) + @trigger "change", @ + + class @Thread extends @Content urlMappers: 'retrieve' : -> DiscussionUtil.urlFor('retrieve_single_thread', @discussion.id, @id) @@ -91,6 +102,8 @@ if Backbone? 'delete' : -> DiscussionUtil.urlFor('delete_thread', @id) 'follow' : -> DiscussionUtil.urlFor('follow_thread', @id) 'unfollow' : -> DiscussionUtil.urlFor('unfollow_thread', @id) + 'pinThread' : -> DiscussionUtil.urlFor("pin_thread", @id) + 'unPinThread' : -> DiscussionUtil.urlFor("un_pin_thread", @id) initialize: -> @set('thread', @) diff --git a/common/static/coffee/src/discussion/utils.coffee b/common/static/coffee/src/discussion/utils.coffee index 6b2714dc54..41f52f1711 100644 --- a/common/static/coffee/src/discussion/utils.coffee +++ b/common/static/coffee/src/discussion/utils.coffee @@ -50,6 +50,8 @@ class @DiscussionUtil delete_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/delete" upvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/upvote" downvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/downvote" + pin_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/pin" + un_pin_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unpin" undo_vote_for_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unvote" follow_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/follow" unfollow_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unfollow" diff --git a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee index 6320c3d1e3..06a5038573 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee @@ -3,6 +3,7 @@ if Backbone? events: "click .discussion-vote": "toggleVote" + "click .discussion-pin": "togglePin" "click .action-follow": "toggleFollowing" "click .action-edit": "edit" "click .action-delete": "delete" @@ -24,6 +25,7 @@ if Backbone? @delegateEvents() @renderDogear() @renderVoted() + @renderPinned() @renderAttrs() @$("span.timeago").timeago() @convertMath() @@ -41,8 +43,20 @@ if Backbone? else @$("[data-role=discussion-vote]").removeClass("is-cast") + renderPinned: => + if @model.get("pinned") + @$("[data-role=thread-pin]").addClass("pinned") + @$("[data-role=thread-pin]").removeClass("notpinned") + @$(".discussion-pin .pin-label").html("Pinned") + else + @$("[data-role=thread-pin]").removeClass("pinned") + @$("[data-role=thread-pin]").addClass("notpinned") + @$(".discussion-pin .pin-label").html("Pin Thread") + + updateModelDetails: => @renderVoted() + @renderPinned() @$("[data-role=discussion-vote] .votes-count-number").html(@model.get("votes")["up_count"]) convertMath: -> @@ -99,6 +113,34 @@ if Backbone? delete: (event) -> @trigger "thread:delete", event + togglePin: (event) -> + event.preventDefault() + if @model.get('pinned') + @unPin() + else + @pin() + + pin: -> + url = @model.urlFor("pinThread") + DiscussionUtil.safeAjax + $elem: @$(".discussion-pin") + url: url + type: "POST" + success: (response, textStatus) => + if textStatus == 'success' + @model.set('pinned', true) + + unPin: -> + url = @model.urlFor("unPinThread") + DiscussionUtil.safeAjax + $elem: @$(".discussion-pin") + url: url + type: "POST" + success: (response, textStatus) => + if textStatus == 'success' + @model.set('pinned', false) + + toggleClosed: (event) -> $elem = $(event.target) url = @model.urlFor('close') @@ -137,3 +179,5 @@ if Backbone? if @model.get('username')? params = $.extend(params, user:{username: @model.username, user_url: @model.user_url}) Mustache.render(@template, params) + + \ No newline at end of file diff --git a/lms/djangoapps/django_comment_client/base/urls.py b/lms/djangoapps/django_comment_client/base/urls.py index d8fd4927fb..92826a18ae 100644 --- a/lms/djangoapps/django_comment_client/base/urls.py +++ b/lms/djangoapps/django_comment_client/base/urls.py @@ -12,6 +12,8 @@ urlpatterns = patterns('django_comment_client.base.views', url(r'threads/(?P[\w\-]+)/upvote$', 'vote_for_thread', {'value': 'up'}, name='upvote_thread'), url(r'threads/(?P[\w\-]+)/downvote$', 'vote_for_thread', {'value': 'down'}, name='downvote_thread'), url(r'threads/(?P[\w\-]+)/unvote$', 'undo_vote_for_thread', name='undo_vote_for_thread'), + url(r'threads/(?P[\w\-]+)/pin$', 'pin_thread', name='pin_thread'), + url(r'threads/(?P[\w\-]+)/unpin$', 'un_pin_thread', name='un_pin_thread'), url(r'threads/(?P[\w\-]+)/follow$', 'follow_thread', name='follow_thread'), url(r'threads/(?P[\w\-]+)/unfollow$', 'unfollow_thread', name='unfollow_thread'), url(r'threads/(?P[\w\-]+)/close$', 'openclose_thread', name='openclose_thread'), diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index d93ea19f44..f08c302bdb 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -289,6 +289,21 @@ def undo_vote_for_thread(request, course_id, thread_id): user.unvote(thread) return JsonResponse(utils.safe_content(thread.to_dict())) +@require_POST +@login_required +@permitted +def pin_thread(request, course_id, thread_id): + user = cc.User.from_django_user(request.user) + thread = cc.Thread.find(thread_id) + thread.pin(user,thread) + return JsonResponse(utils.safe_content(thread.to_dict())) + +def un_pin_thread(request, course_id, thread_id): + user = cc.User.from_django_user(request.user) + thread = cc.Thread.find(thread_id) + thread.un_pin(user,thread) + return JsonResponse(utils.safe_content(thread.to_dict())) + @require_POST @login_required diff --git a/lms/djangoapps/django_comment_client/permissions.py b/lms/djangoapps/django_comment_client/permissions.py index dfdcd3e7ba..7d21cc9783 100644 --- a/lms/djangoapps/django_comment_client/permissions.py +++ b/lms/djangoapps/django_comment_client/permissions.py @@ -90,6 +90,8 @@ VIEW_PERMISSIONS = { 'undo_vote_for_comment': [['unvote', 'is_open']], 'vote_for_thread' : [['vote', 'is_open']], 'undo_vote_for_thread': [['unvote', 'is_open']], + 'pin_thread': ['create_comment'], + 'un_pin_thread': ['create_comment'], 'follow_thread' : ['follow_thread'], 'follow_commentable': ['follow_commentable'], 'follow_user' : ['follow_user'], diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index dde219294c..7e31e451d1 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -430,7 +430,7 @@ def safe_content(content): 'updated_at', 'depth', 'type', 'commentable_id', 'comments_count', 'at_position_list', 'children', 'highlighted_title', 'highlighted_body', 'courseware_title', 'courseware_url', 'tags', 'unread_comments_count', - 'read', 'group_id', 'group_name', 'group_string' + 'read', 'group_id', 'group_name', 'group_string', 'pinned' ] if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False): diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index ca607d3ff3..9fe1b4397f 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -11,12 +11,12 @@ class Thread(models.Model): 'closed', 'tags', 'votes', 'commentable_id', 'username', 'user_id', 'created_at', 'updated_at', 'comments_count', 'unread_comments_count', 'at_position_list', 'children', 'type', 'highlighted_title', - 'highlighted_body', 'endorsed', 'read', 'group_id', 'group_name' + 'highlighted_body', 'endorsed', 'read', 'group_id', 'group_name', 'pinned' ] updatable_fields = [ 'title', 'body', 'anonymous', 'anonymous_to_peers', 'course_id', - 'closed', 'tags', 'user_id', 'commentable_id', 'group_id', 'group_name' + 'closed', 'tags', 'user_id', 'commentable_id', 'group_id', 'group_name', 'pinned' ] initializable_fields = updatable_fields @@ -79,3 +79,23 @@ class Thread(models.Model): response = perform_request('get', url, request_params) self.update_attributes(**response) + + def pin(self, user, thread_id): + url = _url_for_pin_thread(thread_id) + params = {'user_id': user.id} + request = perform_request('put', url, params) + self.update_attributes(request) + + def un_pin(self, user, thread_id): + url = _url_for_un_pin_thread(thread_id) + params = {'user_id': user.id} + request = perform_request('put', url, params) + self.update_attributes(request) + + +def _url_for_pin_thread(thread_id): + return "{prefix}/threads/{thread_id}/pin".format(prefix=settings.PREFIX, thread_id=thread_id) + +def _url_for_un_pin_thread(thread_id): + return "{prefix}/threads/{thread_id}/unpin".format(prefix=settings.PREFIX, thread_id=thread_id) + \ No newline at end of file diff --git a/lms/static/sass/_discussion.scss b/lms/static/sass/_discussion.scss index fe4f37f7aa..2f044ca5a3 100644 --- a/lms/static/sass/_discussion.scss +++ b/lms/static/sass/_discussion.scss @@ -2444,7 +2444,7 @@ body.discussion { background-color:#fff; } -.discussion-flag-abuse { +.discussion-pin { font-size: 12px; float:right; padding-right: 5px; @@ -2457,7 +2457,7 @@ body.discussion { width: 10px; height: 14px; padding-right: 3px; - background: transparent url('../images/notpinned.png') no-repeat 0 0; + background: transparent url('../images/unpinned.png') no-repeat 0 0; } .pinned .icon diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index 7faef4195c..9bfb32b3ff 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -47,7 +47,7 @@
${'<%- body %>'}
% if has_permission(user, 'create_comment', course.id): -
+
Pin Thread
% endif ${'<% if (obj.courseware_url) { %>'} From 07534a72314d3b614504934ccd5a8564c5866094 Mon Sep 17 00:00:00 2001 From: Kevin Chugh Date: Wed, 13 Mar 2013 09:02:57 -0400 Subject: [PATCH 03/12] fix thread/thread id issue --- lms/djangoapps/django_comment_client/base/views.py | 4 ++-- lms/lib/comment_client/thread.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index f08c302bdb..6734625a76 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -295,13 +295,13 @@ def undo_vote_for_thread(request, course_id, thread_id): def pin_thread(request, course_id, thread_id): user = cc.User.from_django_user(request.user) thread = cc.Thread.find(thread_id) - thread.pin(user,thread) + thread.pin(user,thread_id) return JsonResponse(utils.safe_content(thread.to_dict())) def un_pin_thread(request, course_id, thread_id): user = cc.User.from_django_user(request.user) thread = cc.Thread.find(thread_id) - thread.un_pin(user,thread) + thread.un_pin(user,thread_id) return JsonResponse(utils.safe_content(thread.to_dict())) diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index 9fe1b4397f..ccf11f7b1b 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -84,6 +84,8 @@ class Thread(models.Model): url = _url_for_pin_thread(thread_id) params = {'user_id': user.id} request = perform_request('put', url, params) + print "\n\n\n\n\n\n*******************" + print request self.update_attributes(request) def un_pin(self, user, thread_id): From 74501280646e5da338eb3363244b7dccb859bc3e Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 12:52:07 -0400 Subject: [PATCH 04/12] update coffeescript --- .../src/discussion/views/discussion_thread_list_view.coffee | 2 +- lms/lib/comment_client/thread.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee index 8364963218..b7518052a4 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee @@ -15,7 +15,7 @@ if Backbone? initialize: -> @displayedCollection = new Discussion(@collection.models, pages: @collection.pages) @collection.on "change", @reloadDisplayedCollection - @sortBy = "date" + @sortBy = "pinned" @discussionIds="" @collection.on "reset", (discussion) => board = $(".current-board").html() diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index ccf11f7b1b..9fe1b4397f 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -84,8 +84,6 @@ class Thread(models.Model): url = _url_for_pin_thread(thread_id) params = {'user_id': user.id} request = perform_request('put', url, params) - print "\n\n\n\n\n\n*******************" - print request self.update_attributes(request) def un_pin(self, user, thread_id): From a2f9e4d56571a13d02fdca6bf62bf662df57b868 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 15:29:57 -0400 Subject: [PATCH 05/12] almost there --- .../views/discussion_thread_show_view.coffee | 2 +- lms/djangoapps/django_comment_client/forum/views.py | 1 + lms/templates/discussion/_underscore_templates.html | 13 ++++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee index 06a5038573..a5a1deac10 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee @@ -3,7 +3,7 @@ if Backbone? events: "click .discussion-vote": "toggleVote" - "click .discussion-pin": "togglePin" + "click .admin-pin": "togglePin" "click .action-follow": "toggleFollowing" "click .action-edit": "edit" "click .action-delete": "delete" diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index a41cf6c45a..2b05643ff5 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -88,6 +88,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG 'tags', 'commentable_ids']))) threads, page, num_pages = cc.Thread.search(query_params) + #now add the group name if the thread has a group id for thread in threads: diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index 9bfb32b3ff..d6c0da5b4c 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -46,10 +46,17 @@
${'<%- body %>'}
- % if has_permission(user, 'create_comment', course.id): -
- Pin Thread
+ % if has_permission(user, 'create_commentx', course.id): +
+ Pin Thread
+ elif pinned: + THIS ONE IS PINNED % endif + + + + + ${'<% if (obj.courseware_url) { %>'}
(this post is about ${'<%- courseware_title %>'}) From 08bc073fa5f808b594d4e1e9213d4043c2da375e Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 16:40:04 -0400 Subject: [PATCH 06/12] updates --- .../discussion/views/discussion_thread_list_view.coffee | 2 +- lms/templates/discussion/_underscore_templates.html | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee index b7518052a4..8364963218 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee @@ -15,7 +15,7 @@ if Backbone? initialize: -> @displayedCollection = new Discussion(@collection.models, pages: @collection.pages) @collection.on "change", @reloadDisplayedCollection - @sortBy = "pinned" + @sortBy = "date" @discussionIds="" @collection.on "reset", (discussion) => board = $(".current-board").html() diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index d6c0da5b4c..8a89ffe3ed 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -46,11 +46,14 @@
${'<%- body %>'}
- % if has_permission(user, 'create_commentx', course.id): + % if has_permission(user, 'change_permission', course.id):
Pin Thread
- elif pinned: - THIS ONE IS PINNED + %else: + ${"<% if (pinned) { %>"} +
+ Pin Thread
+ ${"<% } %>"} % endif From 117be695cbf4983d74d9f9e86b43580c8f99f718 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 18:40:10 -0400 Subject: [PATCH 07/12] candidate without inline --- .../coffee/src/discussion/discussion.coffee | 18 ++++++++++++++++-- .../django_comment_client/forum/views.py | 1 + lms/templates/discussion/_single_thread.html | 3 +++ .../discussion/_underscore_templates.html | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/common/static/coffee/src/discussion/discussion.coffee b/common/static/coffee/src/discussion/discussion.coffee index 9cee068b74..2294d4a65a 100644 --- a/common/static/coffee/src/discussion/discussion.coffee +++ b/common/static/coffee/src/discussion/discussion.coffee @@ -58,10 +58,24 @@ if Backbone? @current_page = response.page sortByDate: (thread) -> - thread.get("created_at") + + if thread.get('pinned') + #use tomorrow's date + today = new Date(); + new Date(today.getTime() + (24 * 60 * 60 * 1000)); + else + thread.get("created_at") + + + sortByDateRecentFirst: (thread) -> - -(new Date(thread.get("created_at")).getTime()) + if thread.get('pinned') + #use tomorrow's date + today = new Date(); + -(new Date(today.getTime() + (24 * 60 * 60 * 1000))); + else + -(new Date(thread.get("created_at")).getTime()) #return String.fromCharCode.apply(String, # _.map(thread.get("created_at").split(""), # ((c) -> return 0xffff - c.charChodeAt())) diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 2b05643ff5..03175a4918 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -92,6 +92,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG #now add the group name if the thread has a group id for thread in threads: + if thread.get('group_id'): thread['group_name'] = get_cohort_by_id(course_id, thread.get('group_id')).name thread['group_string'] = "This post visible only to Group %s." % (thread['group_name']) diff --git a/lms/templates/discussion/_single_thread.html b/lms/templates/discussion/_single_thread.html index 0dec32ad47..66e901f5e9 100644 --- a/lms/templates/discussion/_single_thread.html +++ b/lms/templates/discussion/_single_thread.html @@ -6,6 +6,9 @@
+ %if thread['pinned'] + PINNED + %endif %if thread['group_id']
This post visible only to group ${cohort_dictionary[thread['group_id']]}.
%endif diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index 8a89ffe3ed..5fdfb8aa82 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -46,7 +46,7 @@
${'<%- body %>'}
- % if has_permission(user, 'change_permission', course.id): + % if course and has_permission(user, 'openclose_thread', course.id):
Pin Thread
%else: From fc907fe0558cf20a22be68c4e3dbb279be8553a1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 18:50:00 -0400 Subject: [PATCH 08/12] candidate without inline --- lms/templates/discussion/_single_thread.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/lms/templates/discussion/_single_thread.html b/lms/templates/discussion/_single_thread.html index 66e901f5e9..0dec32ad47 100644 --- a/lms/templates/discussion/_single_thread.html +++ b/lms/templates/discussion/_single_thread.html @@ -6,9 +6,6 @@
- %if thread['pinned'] - PINNED - %endif %if thread['group_id']
This post visible only to group ${cohort_dictionary[thread['group_id']]}.
%endif From 6ee14ec34a0d3268fee108f48df2bf65cc3cfd34 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 18:51:40 -0400 Subject: [PATCH 09/12] candidate without inline --- lms/static/images/__MACOSX/._pinned.png | Bin 82 -> 0 bytes lms/static/images/__MACOSX/._unpinned.png | Bin 82 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lms/static/images/__MACOSX/._pinned.png delete mode 100644 lms/static/images/__MACOSX/._unpinned.png diff --git a/lms/static/images/__MACOSX/._pinned.png b/lms/static/images/__MACOSX/._pinned.png deleted file mode 100644 index 1073ea4c42b27830690abb44fa97664a5e13ef43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 82 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDI}u>uf-_(4F-5a8#Y=IiYg31VXd08sV@ Ap8x;= diff --git a/lms/static/images/__MACOSX/._unpinned.png b/lms/static/images/__MACOSX/._unpinned.png deleted file mode 100644 index 1073ea4c42b27830690abb44fa97664a5e13ef43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 82 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDI}u>uf-_(4F-5a8#Y=IiYg31VXd08sV@ Ap8x;= From 97eb7eb58badbcb2957e791d279a69ce50a07e44 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 19:07:46 -0400 Subject: [PATCH 10/12] remove whitespace --- lms/djangoapps/django_comment_client/forum/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 03175a4918..50224e7de6 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -88,7 +88,6 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG 'tags', 'commentable_ids']))) threads, page, num_pages = cc.Thread.search(query_params) - #now add the group name if the thread has a group id for thread in threads: From 896ee094c6d79b242ae51a1294d0cf352ce962f8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 19:44:41 -0400 Subject: [PATCH 11/12] added comment to explain sorting --- .../static/coffee/src/discussion/discussion.coffee | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/common/static/coffee/src/discussion/discussion.coffee b/common/static/coffee/src/discussion/discussion.coffee index 2294d4a65a..2a92091f53 100644 --- a/common/static/coffee/src/discussion/discussion.coffee +++ b/common/static/coffee/src/discussion/discussion.coffee @@ -58,7 +58,13 @@ if Backbone? @current_page = response.page sortByDate: (thread) -> - + # + #The comment client asks each thread for a value by which to sort the collection + #and calls this sort routine regardless of the order returned from the LMS/comments service + #so, this takes advantage of this per-thread value and returns tomorrow's date + #for pinned threads, ensuring that they appear first, which is the intent of pinned threads + #the negative is to display most recent first + # if thread.get('pinned') #use tomorrow's date today = new Date(); @@ -67,9 +73,11 @@ if Backbone? thread.get("created_at") - - sortByDateRecentFirst: (thread) -> + # + #Same as above + #the negative is to display most recent first (basically to flip the order) + # if thread.get('pinned') #use tomorrow's date today = new Date(); From 7f877344d60f5c92b8a5595b07f482f4be98ff9e Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 13 Mar 2013 19:47:19 -0400 Subject: [PATCH 12/12] added comment to explain sorting --- common/static/coffee/src/discussion/discussion.coffee | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/static/coffee/src/discussion/discussion.coffee b/common/static/coffee/src/discussion/discussion.coffee index 2a92091f53..83e25e1da7 100644 --- a/common/static/coffee/src/discussion/discussion.coffee +++ b/common/static/coffee/src/discussion/discussion.coffee @@ -62,8 +62,7 @@ if Backbone? #The comment client asks each thread for a value by which to sort the collection #and calls this sort routine regardless of the order returned from the LMS/comments service #so, this takes advantage of this per-thread value and returns tomorrow's date - #for pinned threads, ensuring that they appear first, which is the intent of pinned threads - #the negative is to display most recent first + #for pinned threads, ensuring that they appear first, (which is the intent of pinned threads) # if thread.get('pinned') #use tomorrow's date @@ -76,7 +75,7 @@ if Backbone? sortByDateRecentFirst: (thread) -> # #Same as above - #the negative is to display most recent first (basically to flip the order) + #but negative to flip the order (newest first) # if thread.get('pinned') #use tomorrow's date