Order recent announcements widget by `posted_at`

Additionally, remove default time limit from recent
announcements posting so that all announcements are shown.

Fixes CNVS-34030

Test Plan:
* As a teacher, go to a Course's settings page
* Enable "Show recent announcments on homepage"
* Make sure you have the course homepage set to
  the wiki front page
* Create multiple announcements
* Post them in a different order than you created them,
  e.g. by using the `Delay Posting` setting
* Make sure that the announcements `posted_at` ranges
  from longer than two weeks ago to further out than
  two weeks from now
* View the homepage
* The recent announcement list should be ordered
  by the date/time that you posted the announcement
  and not in the order that they were created,
  in order from most recent to least
* It should display all the relevant announcements,
  even if they were posted longer that two weeks ago
  or further out than two weeks from now
* Students should not see announcements that have
  not yet been posted or that they don't otherwise
  have access to

Change-Id: Ie575f8561614529b7fd6245a24ffe9fdad5d8111
Reviewed-on: https://gerrit.instructure.com/98610
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins
QA-Review: David Tan <dtan@instructure.com>
Product-Review: Dan Minkevitch <dan@instructure.com>
This commit is contained in:
Dan Minkevitch 2016-12-29 14:16:54 -08:00
parent cbd71e359b
commit 4322f02c60
3 changed files with 16 additions and 10 deletions

View File

@ -4,13 +4,14 @@ require [
'compiled/models/WikiPage'
'compiled/views/wiki/WikiPageView'
'compiled/util/markAsDone'
'compiled/util/natcompare'
'react'
'react-dom'
'axios'
'jsx/announcements/AnnouncementList'
'instructure-ui/Spinner'
'compiled/jquery/ModuleSequenceFooter'
], ($, I18n, WikiPage, WikiPageView, MarkAsDone, React, ReactDOM, axios, AnnouncementList, { default: Spinner }) ->
], ($, I18n, WikiPage, WikiPageView, MarkAsDone, natcompare, React, ReactDOM, axios, AnnouncementList, { default: Spinner }) ->
renderReactComponent = (component, target, props) ->
ReactDOM.render(
@ -18,6 +19,11 @@ require [
document.querySelector(target)
)
sortByPosting = (a, b) ->
aPosted = a.delayed_post_at || a.posted_at
bPosted = b.delayed_post_at || b.posted_at
natcompare.strings(bPosted, aPosted)
$ ->
$('#content').on('click', '#mark-as-done-checkbox', ->
MarkAsDone.toggle(this)
@ -46,11 +52,11 @@ require [
if ENV.SHOW_ANNOUNCEMENTS
renderReactComponent Spinner, '#announcements_on_home_page', {title: I18n.t('Loading Announcements'), size: 'small'}
axios.get("/api/v1/announcements?context_codes[]=course_#{ENV.COURSE_ID}&per_page=#{ENV.ANNOUNCEMENT_LIMIT || 3}&page=1")
axios.get("/api/v1/announcements?context_codes[]=course_#{ENV.COURSE_ID}&per_page=#{ENV.ANNOUNCEMENT_LIMIT || 3}&page=1&start_date=1900-01-01&end_date=2100-12-31")
.then (response) =>
renderReactComponent AnnouncementList, '#announcements_on_home_page', announcements: response.data.map (a) ->
id: a.id,
title: a.title,
message: a.message,
posted_at: a.posted_at,
url: a.url
renderReactComponent AnnouncementList, '#announcements_on_home_page', announcements: response.data.sort(sortByPosting).map (a) ->
id: a.id,
title: a.title,
message: a.message,
posted_at: a.delayed_post_at || a.posted_at,
url: a.url

View File

@ -14,7 +14,7 @@ define([
static propTypes = {
announcements: React.PropTypes.arrayOf(
React.PropTypes.shape({
id: React.PropTypes.number.isRequired,
id: React.PropTypes.string.isRequired,
title: React.PropTypes.string.isRequired,
message: React.PropTypes.string.isRequired,
posted_at: React.PropTypes.string.isRequired,

View File

@ -564,7 +564,7 @@ class DiscussionTopic < ActiveRecord::Base
def can_unlock?
# Only used for course/account setting to lock replies to announcements
!is_announcement || (is_announcement && !self.course&.lock_all_announcements)
self.new_record? || !self.is_announcement || (self.is_announcement && !self.course&.lock_all_announcements)
end
def lock(opts = {})