Skip to content

Commit b18d89c

Browse files
committed
assignment publishing ui
closes CNVS-5686 test plan: - click the cloud icon on the new assignment index page to publish and unpublish an assignment. - click the publish button on the assignment show page to publish and unpublish an assignment. - make sure that no other assignment fields (especially overrides and turniting settings) change when an assignment is published. - try all the above a few times in a row without a page reload. - check the assignment show page without the enable_draft? flag set and make sure the publish button doesn't show up. Change-Id: I14cfd7145a9a58f18165a4242a492de0335e0187 Reviewed-on: https://gerrit.instructure.com/22466 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Cameron Sutter <csutter@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
1 parent 6036657 commit b18d89c

21 files changed

Lines changed: 276 additions & 40 deletions

app/coffeescripts/bundles/assignment_edit.coffee

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require [
33
'compiled/models/Section'
44
'compiled/models/Assignment'
5+
'compiled/views/assignments/EditHeaderView'
56
'compiled/views/assignments/EditView'
67
'compiled/collections/SectionCollection'
78
'compiled/models/DueDateList'
@@ -13,9 +14,9 @@ require [
1314
'compiled/views/assignments/PeerReviewsSelector'
1415
'grading_standards'
1516
'manage_groups'
16-
], (Section,Assignment, EditView, SectionCollection, DueDateList, DueDateListView,
17-
OverrideView, AssignmentGroupSelector, GradingTypeSelector,
18-
GroupCategorySelector, PeerReviewsSelector) ->
17+
], (Section,Assignment, EditHeaderView, EditView, SectionCollection,
18+
DueDateList, DueDateListView, OverrideView, AssignmentGroupSelector,
19+
GradingTypeSelector, GroupCategorySelector, PeerReviewsSelector) ->
1920

2021
ENV.ASSIGNMENT.assignment_overrides = ENV.ASSIGNMENT_OVERRIDES
2122

@@ -38,6 +39,10 @@ GroupCategorySelector, PeerReviewsSelector) ->
3839
peerReviewsSelector = new PeerReviewsSelector
3940
parentModel: assignment
4041

42+
editHeaderView = new EditHeaderView
43+
el: '#edit_assignment_header'
44+
model: assignment
45+
4146
editView = new EditView
4247
el: '#edit_assignment_form'
4348
model: assignment
@@ -51,4 +56,5 @@ GroupCategorySelector, PeerReviewsSelector) ->
5156
views:
5257
'due-date-overrides': new DueDateListView(model: dueDateList)
5358

59+
editHeaderView.render()
5460
editView.render()

app/coffeescripts/bundles/assignment_show.coffee

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@ require [
22
'INST'
33
'i18n!assignment'
44
'jquery'
5+
'compiled/models/Assignment',
6+
'compiled/views/PublishButtonView',
57
'jquery.instructure_forms'
6-
], (INST, I18n, $) ->
8+
], (INST, I18n, $, Assignment, PublishButtonView) ->
9+
10+
$ ->
11+
$el = $('#assignment_publish_button')
12+
if $el.length > 0
13+
model = new Assignment
14+
id: $el.attr('data-id')
15+
publishable: true
16+
published: $el.hasClass('published')
17+
model.doNotParse()
18+
19+
new PublishButtonView(model: model, el: $el).render()
720

821
# -- This is all for the _grade_assignment sidebar partial
922
$ ->

app/coffeescripts/bundles/teacher_assignments.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ require [
3232

3333
assignmentGroups = new AssignmentGroupCollection [],
3434
course: course
35+
params:
36+
include: ["assignments"]
37+
override_assignment_dates: false
3538

3639
assignmentSettingsView = new AssignmentSettingsView
3740
model: course

app/coffeescripts/models/Assignment.coffee

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ define [
1313

1414
urlRoot: -> @_defaultUrl()
1515

16+
defaults:
17+
"publishable": true
18+
1619
initialize: ->
17-
overrides = @get('assignment_overrides')
18-
@set 'assignment_overrides',
19-
new AssignmentOverrideCollection(overrides)
20-
@set 'turnitin_settings', new TurnitinSettings(@get 'turnitin_settings'),
21-
silent: true
20+
if (overrides = @get('assignment_overrides'))?
21+
@set 'assignment_overrides', new AssignmentOverrideCollection(overrides)
22+
if (turnitin_settings = @get('turnitin_settings'))?
23+
@set 'turnitin_settings', new TurnitinSettings(turnitin_settings),
24+
silent: true
2225

2326
isQuiz: => @_hasOnlyType 'online_quiz'
2427
isDiscussionTopic: => @_hasOnlyType 'discussion_topic'
@@ -172,12 +175,13 @@ define [
172175
@set 'external_tool_tag_attributes', tagAttributes
173176

174177
isSimple: =>
178+
overrides = @get('assignment_overrides')
175179
@gradingType() == 'points' and
176180
@submissionType() == 'none' and
177181
!@groupCategoryId() and
178182
!@peerReviews() and
179183
!@frozen() and
180-
@get('assignment_overrides').isSimple()
184+
(!overrides or overrides.isSimple())
181185

182186
isLetterGraded: =>
183187
@gradingType() == 'letter_grade'
@@ -208,7 +212,7 @@ define [
208212
'gradingStandardId', 'isLetterGraded', 'assignmentGroupId', 'iconType',
209213
'published', 'htmlUrl'
210214
]
211-
hash = {}
215+
hash = id: @get 'id'
212216
for field in fields
213217
hash[field] = @[field]()
214218
hash
@@ -219,15 +223,21 @@ define [
219223
if @alreadyScoped then data else { assignment: data }
220224

221225
parse: (data) ->
222-
overrides = data.assignment_overrides
223-
if overrides?
224-
data.assignment_overrides =
225-
new AssignmentOverrideCollection overrides
226-
else
227-
data.assignment_overrides = new AssignmentOverrideCollection
228-
data.turnitin_settings = new TurnitinSettings data.turnitin_settings
226+
data = super data
227+
if (overrides = data.assignment_overrides)?
228+
data.assignment_overrides = new AssignmentOverrideCollection overrides
229+
if (turnitin_settings = data.turnitin_settings)?
230+
data.turnitin_settings = new TurnitinSettings turnitin_settings
229231
data
230232

233+
# Update the Assignment model instance to not parse results from the
234+
# server. This is a hack to work around the fact that the server will
235+
# always return an overridden due date after a successful PUT request. If
236+
# that is parsed and set on the model, and then another save() is called,
237+
# the assignments default due date will be updated accidentally. Ugh.
238+
doNotParse: ->
239+
@parse = -> {}
240+
231241
# @api private
232242
_submissionTypes: =>
233243
@get('submission_types') || []
@@ -266,3 +276,6 @@ define [
266276
@lockAt null
267277
@unlockAt null
268278
this
279+
280+
publish: -> @save("published", true)
281+
unpublish: -> @save("published", false)

app/coffeescripts/models/DiscussionTopic.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ define [
3535
@entries.participants = @participants
3636

3737
@set 'set_assignment', @get('assignment')?
38-
assign = new Assignment(@get('assignment') or {})
38+
assign_attributes = @get('assignment') or {}
39+
assign_attributes.assignment_overrides or= []
40+
assign_attributes.turnitin_settings or= {}
41+
assign = new Assignment(assign_attributes)
3942
assign.alreadyScoped = true
4043
@set 'assignment', assign
4144

app/coffeescripts/views/assignments/AssignmentGroupListItemView.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ define [
1212
], (I18n, _, Cache, AssignmentCollection, CollectionView, AssignmentListItemView, CreateAssignmentView, CreateGroupView, DeleteGroupView, template) ->
1313

1414
class AssignmentGroupListItemView extends CollectionView
15-
1615
tagName: "li"
1716
className: "item-group-condensed"
1817
itemView: AssignmentListItemView
@@ -57,6 +56,7 @@ define [
5756

5857
initialize: ->
5958
@collection = new AssignmentCollection @model.get('assignments')
59+
@collection.each (assign) -> assign.doNotParse()
6060
@collection.on('add remove', @refreshDeleteDialog)
6161
super
6262

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
define [
22
'Backbone'
3+
'compiled/views/PublishIconView'
34
'jst/assignments/teacher_index/AssignmentListItem'
4-
], (Backbone, template) ->
5+
], (Backbone, PublishIconView, template) ->
56

67
class AssignmentListItemView extends Backbone.View
78
tagName: "li"
89
template: template
9-
toJSON: -> @model.toView()
10+
11+
@child 'publishIconView', '[data-view=publish-icon]'
12+
13+
initialize: ->
14+
super
15+
@publishIconView = new PublishIconView(model: @model)
16+
@model.on('change:published', @upatePublishState)
17+
18+
toJSON: ->
19+
@model.toView()
20+
21+
upatePublishState: =>
22+
@$('.ig-row').toggleClass('ig-published', @model.get('published'))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
define [
2+
'i18n!assignments'
3+
'Backbone'
4+
'jquery'
5+
'jst/assignments/EditHeaderView'
6+
'jquery.disableWhileLoading'
7+
], (I18n, Backbone, $, template) ->
8+
9+
class EditHeaderView extends Backbone.View
10+
11+
template: template
12+
13+
events:
14+
'click .delete_assignment_link': 'onDelete'
15+
16+
messages:
17+
confirm: I18n.t('confirms.delete_assignment', 'Are you sure you want to delete this assignment?')
18+
19+
onDelete: (e) =>
20+
e.preventDefault()
21+
@delete() if confirm(@messages.confirm)
22+
23+
delete: ->
24+
disablingDfd = new $.Deferred()
25+
destroyDfd = @model.destroy()
26+
destroyDfd.then(@onSaveSuccess)
27+
destroyDfd.fail -> disablingDfd.reject()
28+
$('#content').disableWhileLoading disablingDfd
29+
30+
onDeleteSuccess: ->
31+
location.href = ENV.ASSIGNMENT_INDEX_URL
32+
33+
toJSON: -> @model.toView()

app/coffeescripts/views/assignments/TeacherIndexView.coffee

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ define [
44
], (Backbone, template) ->
55

66
class TeacherIndexView extends Backbone.View
7-
87
template: template
9-
108
el: '#content'
119

1210
@child 'assignmentGroupsView', '[data-view=assignmentGroups]'
13-
1411
@child 'inputFilterView', '[data-view=inputFilter]'
15-
1612
@child 'createGroupView', '[data-view=createGroup]'
17-
1813
@child 'assignmentSettingsView', '[data-view=assignmentSettings]'
1914

2015
els:

app/controllers/assignment_groups_api_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ class AssignmentGroupsApiController < ApplicationController
2828
# Returns the assignment group with the given id.
2929
#
3030
# @argument include[] ["assignments","discussion_topic"] Associations to include with the group. "discussion_topic" is only valid if "assignments" is also included
31+
# @argument override_assignment_dates [Optional, Boolean]
32+
# Apply assignment overrides for each assignment, defaults to true.
3133
#
3234
# @returns Assignment Group
3335
def show
3436
if authorized_action(@assignment_group, @current_user, :read)
3537
includes = Array(params[:include])
36-
render :json => assignment_group_json(@assignment_group, @current_user, session, includes)
38+
override_dates = value_to_boolean(params[:override_assignment_dates] || true)
39+
render :json => assignment_group_json(@assignment_group, @current_user, session, includes, {
40+
override_dates: override_dates
41+
})
3742
end
3843
end
3944

@@ -116,4 +121,4 @@ def process_assignment_group
116121
end
117122
end
118123

119-
end
124+
end

0 commit comments

Comments
 (0)