Skip to content

Commit 1da8ffa

Browse files
committed
pre-populate start/end dates in new migration UI if possible
If the new or old course has start/end dates, they will be pre-populated in the date shift form Test Plan: * with a course that has start/end dates and with one that doesn't: * go to migration page * view date shift forms for any type; there should dates or no dates as expected for the course, and no error * for a course copy type, choose courses with/without start/end dates * the date shift fields should populate/clear as appropriate closes CNVS-7241 Change-Id: I0f427da5962c945314fd5efd19f543adec8cbb3a Reviewed-on: https://gerrit.instructure.com/22815 Reviewed-by: Bracken Mosbacker <bracken@instructure.com> Product-Review: Bracken Mosbacker <bracken@instructure.com> QA-Review: Bracken Mosbacker <bracken@instructure.com> Tested-by: Jenkins <jenkins@instructure.com>
1 parent 366857f commit 1da8ffa

9 files changed

Lines changed: 76 additions & 5 deletions

File tree

app/coffeescripts/bundles/content_migration.coffee

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ require [
9292
model: ConverterViewControl.getModel()
9393
collection: daySubCollection
9494
daySubstitution: daySubCollectionView
95+
oldStartDate: ENV.OLD_START_DATE
96+
oldEndDate: ENV.OLD_END_DATE
97+
9598

9699
ConverterViewControl.register
97100
key: 'moodle_converter'
@@ -110,6 +113,8 @@ require [
110113
model: ConverterViewControl.getModel()
111114
collection: daySubCollection
112115
daySubstitution: daySubCollectionView
116+
oldStartDate: ENV.OLD_START_DATE
117+
oldEndDate: ENV.OLD_END_DATE
113118

114119
ConverterViewControl.register
115120
key: 'canvas_cartridge_importer'
@@ -124,6 +129,8 @@ require [
124129
model: ConverterViewControl.getModel()
125130
collection: daySubCollection
126131
daySubstitution: daySubCollectionView
132+
oldStartDate: ENV.OLD_START_DATE
133+
oldEndDate: ENV.OLD_END_DATE
127134

128135
ConverterViewControl.register
129136
key: 'common_cartridge_importer'
@@ -142,6 +149,8 @@ require [
142149
model: ConverterViewControl.getModel()
143150
collection: daySubCollection
144151
daySubstitution: daySubCollectionView
152+
oldStartDate: ENV.OLD_START_DATE
153+
oldEndDate: ENV.OLD_END_DATE
145154

146155
ConverterViewControl.register
147156
key: 'qti_converter'

app/coffeescripts/bundles/copy_course.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ require [
2525
model: new ContentMigration
2626
collection: daySubCollection
2727
daySubstitution: daySubCollectionView
28+
oldStartDate: ENV.OLD_START_DATE
29+
oldEndDate: ENV.OLD_END_DATE
2830

2931
$('#date_shift').html dateShiftView.render().el
3032
dateShiftView.$oldStartDate.val ENV.OLD_START_DATE
@@ -34,4 +36,4 @@ require [
3436
dateShiftView.$newStartDate.val $(this).val()
3537

3638
$('#course_conclude_at').on 'change', ->
37-
dateShiftView.$newEndDate.val $(this).val()
39+
dateShiftView.$newEndDate.val $(this).val()

app/coffeescripts/views/content_migrations/CopyCourseView.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ define [
1010
@child 'courseFindSelect', '.courseFindSelect'
1111
@child 'dateShift', '.dateShift'
1212
@child 'selectContent', '.selectContent'
13+
14+
initialize: ->
15+
super
16+
@courseFindSelect.on 'course_changed', (course) =>
17+
@dateShift.updateNewDates(course)

app/coffeescripts/views/content_migrations/subviews/CourseFindSelectView.coffee

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ define [
1919
'change [name=include_completed_courses]' : 'toggleConcludedCourses'
2020

2121
render: ->
22+
super
2223
dfd = @getManageableCourses()
24+
@$el.disableWhileLoading dfd
2325
dfd.done (data) =>
2426
@courses = data
2527
@coursesByTerms = _.groupBy data, (course) -> course.term
2628
super
27-
29+
2830
afterRender: ->
2931
@$courseSearchField.autocomplete
3032
source: @manageableCourseUrl()
@@ -102,8 +104,11 @@ define [
102104
# @input int
103105
# @api private
104106

105-
setSourceCourseId: (id) -> @model.set('settings', {source_course_id: id})
106-
107+
setSourceCourseId: (id) ->
108+
@model.set('settings', {source_course_id: id})
109+
if course = _.find(@courses, (c) -> c.id == id)
110+
@trigger 'course_changed', course
111+
107112
# Validates this form element. This validates method is a convention used
108113
# for all sub views.
109114
# ie:

app/coffeescripts/views/content_migrations/subviews/DateShiftView.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ define [
99
template: template
1010

1111
@child 'daySubstitution', '#daySubstitution'
12+
@optionProperty 'oldStartDate'
13+
@optionProperty 'oldEndDate'
1214

1315
els:
1416
".dateShiftContent" : "$dateShiftContent"
@@ -37,6 +39,8 @@ define [
3739
@$oldEndDate.on 'change', (event) => @model.setDateShiftOptions property:'old_end_date', value: event.target.value
3840
@$newStartDate.on 'change', (event) => @model.setDateShiftOptions property: 'new_start_date', value: event.target.value
3941
@$newEndDate.on 'change', (event) => @model.setDateShiftOptions property: 'new_end_date', value: event.target.value
42+
@$newStartDate.val @oldStartDate
43+
@$newEndDate.val @oldEndDate
4044

4145
# Toggle content. Show's content when checked
4246
# and hides content when unchecked. Sets date_shift_options
@@ -59,3 +63,7 @@ define [
5963
createDaySubView: (event) =>
6064
event.preventDefault()
6165
@collection.add new DaySubModel
66+
67+
updateNewDates: (course) =>
68+
@$oldStartDate.val course.start_at
69+
@$oldEndDate.val course.end_at

app/controllers/content_migrations_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def index
107107
js_env :QUESTION_BANKS => @context.assessment_question_banks.except(:include).select([:title, :id]).active
108108
js_env :COURSE_ID => @context.id
109109
js_env :CONTENT_MIGRATIONS => content_migration_json_hash
110+
js_env(:OLD_START_DATE => datetime_string(@context.start_at, :verbose, nil, true))
111+
js_env(:OLD_END_DATE => datetime_string(@context.conclude_at, :verbose, nil, true))
110112
end
111113
end
112114

app/controllers/users_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,11 @@ def manageable_courses
492492
render :json => @courses.map { |c|
493493
{ :label => c.name, :id => c.id, :term => c.enrollment_term.name,
494494
:enrollment_start => c.enrollment_term.start_at,
495-
:account_name => c.enrollment_term.root_account.name, :account_id => c.enrollment_term.root_account.id }
495+
:account_name => c.enrollment_term.root_account.name,
496+
:account_id => c.enrollment_term.root_account.id,
497+
:start_at => datetime_string(c.start_at, :verbose, nil, true),
498+
:end_at => datetime_string(c.conclude_at, :verbose, nil, true)
499+
}
496500
}.to_json
497501
end
498502

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
define [
2+
'Backbone'
3+
'compiled/views/content_migrations/CopyCourseView'
4+
'compiled/views/content_migrations/subviews/DateShiftView'
5+
], (Backbone, CopyCourseView, DateShiftView) ->
6+
module 'CopyCourseView: Initializer'
7+
test 'after init, calls updateNewDates when @courseFindSelect.triggers "course_changed" event', ->
8+
9+
copyCourseView = new CopyCourseView
10+
courseFindSelect: new Backbone.View
11+
dateShift: new DateShiftView
12+
13+
$('#fixtures').html copyCourseView.render().el
14+
sinonSpy = sinon.spy(copyCourseView.dateShift, 'updateNewDates')
15+
course = {start_at: 'foo', end_at: 'bar'}
16+
copyCourseView.courseFindSelect.trigger 'course_changed', course
17+
ok sinonSpy.calledWith(course), "Called updateNewDates with passed in object"
18+
19+
copyCourseView.remove()
20+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
define [
2+
'Backbone'
3+
'compiled/views/content_migrations/subviews/CourseFindSelectView'
4+
], (Backbone, CourseFindSelectView) ->
5+
module 'CourseFindSelectView: #setSourceCourseId'
6+
test 'Triggers "course_changed" when course is found by its id', ->
7+
courseFindSelectView = new CourseFindSelectView
8+
model: new Backbone.Model
9+
10+
course = {id: 42}
11+
courseFindSelectView.courses = [course]
12+
13+
sinonSpy = sinon.spy(courseFindSelectView, 'trigger')
14+
courseFindSelectView.setSourceCourseId 42
15+
16+
ok sinonSpy.calledWith('course_changed', course), "Triggered course_changed with a course"

0 commit comments

Comments
 (0)