fixes to make importing a canvas cartridge from ui work
this commit fixes a bunch of problems with importing a whole export package and updates the UI refs #3396 Change-Id: Ia344b385e06df2f08bb75878234a7712a036e4b3 Reviewed-on: https://gerrit.instructure.com/3085 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
parent
61771933bb
commit
cf6908801a
|
@ -1246,18 +1246,15 @@ class Course < ActiveRecord::Base
|
|||
attr_accessor :assignment_group_no_drop_assignments
|
||||
|
||||
def import_settings_from_migration(data)
|
||||
return unless data[:course_settings]
|
||||
settings = data[:course_settings]
|
||||
self.name = settings['title']
|
||||
dates = ['conclude_at', 'start_at']
|
||||
settings.slice(*Course.clonable_attributes.map(&:to_s)).each do |key, val|
|
||||
if dates.member? key
|
||||
self.send("#{key}=", Canvas::MigratorHelper.get_utc_time_from_timestamp(val))
|
||||
elsif key == 'syllabus_body'
|
||||
self.syllabus_body = ImportedHtmlConverter.convert(val, self)
|
||||
else
|
||||
self.send("#{key}=", val)
|
||||
end
|
||||
return unless data[:course]
|
||||
settings = data[:course]
|
||||
self.conclude_at = Canvas::MigratorHelper.get_utc_time_from_timestamp(settings[:conclude_at]) if settings[:conclude_at]
|
||||
self.start_at = Canvas::MigratorHelper.get_utc_time_from_timestamp(settings[:start_at]) if settings[:start_at]
|
||||
self.syllabus_body = ImportedHtmlConverter.convert(settings[:syllabus_body], self) if settings[:syllabus_body]
|
||||
atts = Course.clonable_attributes
|
||||
atts -= Canvas::MigratorHelper::COURSE_NO_COPY_ATTS
|
||||
settings.slice(*atts.map(&:to_s)).each do |key, val|
|
||||
self.send("#{key}=", val)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -290,6 +290,11 @@ class Rubric < ActiveRecord::Base
|
|||
|
||||
context.imported_migration_items << item if context.imported_migration_items && item.new_record?
|
||||
item.save!
|
||||
|
||||
unless context.rubric_associations.find_by_rubric_id(item.id)
|
||||
item.associate_with(context, context)
|
||||
end
|
||||
|
||||
item
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
<div class="migration_config"></div>
|
||||
|
||||
<% js_block do %>
|
||||
<script>
|
||||
$(function() {
|
||||
|
||||
$("#plugin_common_cartridge_importer").bind("pluginShown", function(event, enableFileUpload) {
|
||||
enableFileUpload();
|
||||
enableFileUpload(".imscc");
|
||||
$(".qti_settings").hide();
|
||||
$(".migration_part_selection").hide();
|
||||
});
|
||||
|
||||
$("#plugin_common_cartridge_importer").bind("pluginHidden", function(event) {
|
||||
$(".qti_settings").show();
|
||||
$(".migration_part_selection").show();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
<p>
|
||||
<h4>You can also:</h4>
|
||||
<div>
|
||||
<p><a class="button" href="<%= context_url(@context, :context_import_copy_url) %>"> Copy content from <b>another Canvas course</b></a></p>
|
||||
|
||||
<% if exports_enabled? %>
|
||||
<a class="button" href="<%= context_url(@context, :context_import_migrate_url) %>"> Migrate content from <b>another system</b> into Canvas</a>
|
||||
or
|
||||
<p><a class="button" href="<%= context_url(@context, :context_import_migrate_url) %>"> Import content from a <b>content package</b> or from <b>another system</b></a></p>
|
||||
<% end %>
|
||||
<a class="button" href="<%= context_url(@context, :context_import_copy_url) %>"> Copy content from <b>another Canvas course</b></a>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<div id="migration_config"></div>
|
||||
|
||||
<fieldset id="file_upload" style="display:none;">
|
||||
<legend>Choose a .zip file to import</legend>
|
||||
<legend>Choose a <span id="upload_extension">.zip</span> file to import</legend>
|
||||
<input type="file" id="export_file_input" name="export_file" class="export_file_input"/>
|
||||
<br/><span class="error zip_error ui-state-error" style="display:none; font-size: 16px">You must choose a .zip file to upload</span>
|
||||
</fieldset>
|
||||
|
|
|
@ -29,7 +29,7 @@ class Canvas::Migrator
|
|||
@manifest = nil
|
||||
@error_count = 0
|
||||
@errors = []
|
||||
@course = {:file_map=>{}, :wikis=>[]}
|
||||
@course = {:file_map=>{}, :wikis=>[]}.with_indifferent_access
|
||||
@course[:name] = @settings[:course_name]
|
||||
|
||||
return if settings[:testing]
|
||||
|
|
|
@ -23,6 +23,8 @@ module Canvas::MigratorHelper
|
|||
ERROR_FILENAME = "errors.json"
|
||||
OVERVIEW_JSON = "overview.json"
|
||||
|
||||
COURSE_NO_COPY_ATTS = [:name, :course_code, :start_at, :conclude_at, :grading_standard_id, :hidden_tabs, :tab_configuration, :syllabus_body, :storage_quota]
|
||||
|
||||
attr_reader :overview
|
||||
|
||||
def self.get_utc_time_from_timestamp(timestamp)
|
||||
|
@ -129,8 +131,8 @@ module Canvas::MigratorHelper
|
|||
@overview[:end_timestamp] = nil
|
||||
dates = []
|
||||
if @overview[:course] = @course[:course]
|
||||
@overview[:start_timestamp] = @course[:course][:start_timestamp]
|
||||
@overview[:end_timestamp] = @course[:course][:end_timestamp]
|
||||
@overview[:start_timestamp] = @course[:course][:start_timestamp] || @course[:course][:start_at]
|
||||
@overview[:end_timestamp] = @course[:course][:end_timestamp] || @course[:course][:conclude_at]
|
||||
end
|
||||
@overview[:role] = @course[:role]
|
||||
@overview[:base_url] = @course[:base_url]
|
||||
|
|
|
@ -84,10 +84,11 @@ module CC
|
|||
"xsi:schemaLocation"=> "#{CCHelper::CANVAS_NAMESPACE} #{CCHelper::XSD_URI}"
|
||||
) do |c|
|
||||
c.title @course.name
|
||||
c.course_code @course.course_code
|
||||
c.start_at ims_datetime(@course.start_at) if @course.start_at
|
||||
c.conclude_at ims_datetime(@course.conclude_at) if @course.conclude_at
|
||||
atts = Course.clonable_attributes
|
||||
atts -= [:name, :start_at, :conclude_at, :grading_standard_id, :hidden_tabs, :tab_configuration, :syllabus_body]
|
||||
atts -= Canvas::MigratorHelper::COURSE_NO_COPY_ATTS
|
||||
atts.each do |att|
|
||||
c.tag!(att, @course.send(att)) unless @course.send(att).nil? || @course.send(att) == ''
|
||||
end
|
||||
|
|
|
@ -80,12 +80,12 @@ module CCHelper
|
|||
|
||||
def self.ims_date(date=nil)
|
||||
date ||= Time.now
|
||||
date.utc.strftime(IMS_DATE)
|
||||
date.respond_to?(:utc) ? date.utc.strftime(IMS_DATE) : date.strftime(IMS_DATE)
|
||||
end
|
||||
|
||||
def self.ims_datetime(date=nil)
|
||||
date ||= Time.now
|
||||
date.utc.strftime(IMS_DATETIME)
|
||||
date.respond_to?(:utc) ? date.utc.strftime(IMS_DATETIME) : date.strftime(IMS_DATETIME)
|
||||
end
|
||||
|
||||
def self.html_page(html, title, course, user)
|
||||
|
|
|
@ -26,7 +26,7 @@ module Canvas
|
|||
settings[:user_id] = cm.user_id
|
||||
settings[:attachment_id] = cm.attachment.id rescue nil
|
||||
|
||||
converter = CC::Importer.CCConverter.new(settings)
|
||||
converter = CC::Importer::CCConverter.new(settings)
|
||||
course = converter.export
|
||||
export_folder_path = course[:export_folder_path]
|
||||
overview_file_path = course[:overview_file_path]
|
||||
|
|
|
@ -35,6 +35,7 @@ module CC::Importer
|
|||
@course[:grading_standards] = convert_grading_standards(settings_doc(GRADING_STANDARDS))
|
||||
@course[:learning_outcomes] = convert_learning_outcomes(settings_doc(LEARNING_OUTCOMES))
|
||||
@course[:modules] = convert_modules(settings_doc(MODULE_META))
|
||||
@course[:rubrics] = convert_rubrics(settings_doc(RUBRICS))
|
||||
end
|
||||
|
||||
def convert_course_settings(doc)
|
||||
|
@ -61,8 +62,6 @@ module CC::Importer
|
|||
course[date_type] = val unless val.nil?
|
||||
end
|
||||
|
||||
course['storage_quota'] = get_int_val(doc, 'storage_quota')
|
||||
|
||||
course
|
||||
end
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#
|
||||
|
||||
require 'canvas/plugin'
|
||||
require 'cc/importer/cc_worker'
|
||||
Rails.configuration.to_prepare do
|
||||
require 'cc/importer/cc_worker'
|
||||
Canvas::Plugin.register :common_cartridge_importer, :export_system, {
|
||||
:name => 'Common Cartridge Importer',
|
||||
:author => 'Instructurecon',
|
||||
|
@ -27,7 +27,7 @@ Rails.configuration.to_prepare do
|
|||
:settings => {
|
||||
:worker=>'CCWorker',
|
||||
:migration_partial => 'cc_config',
|
||||
:select_text => "Canvas Course Export (.imscc)"
|
||||
:select_text => "Canvas Course Export"
|
||||
}
|
||||
}
|
||||
end
|
|
@ -23,7 +23,6 @@
|
|||
<xs:element name="allow_student_organized_groups" type="xs:boolean" minOccurs="0"/>
|
||||
<xs:element name="show_all_discussion_entries" type="xs:boolean" minOccurs="0"/>
|
||||
<xs:element name="open_enrollment" type="xs:boolean" minOccurs="0"/>
|
||||
<xs:element name="storage_quota" type="xs:integer" minOccurs="0"/>
|
||||
<xs:element name="allow_wiki_comments" type="xs:boolean" minOccurs="0"/>
|
||||
<xs:element name="self_enrollment" type="xs:boolean" minOccurs="0"/>
|
||||
<xs:element name="turnitin_comments" type="xs:string" minOccurs="0"/>
|
||||
|
|
|
@ -22,12 +22,15 @@ $(function(){
|
|||
$migration_form = $('#migration_form'),
|
||||
$submit_button = $migration_form.find(".submit_button"),
|
||||
$file_upload = $migration_form.find("#file_upload"),
|
||||
$upload_extension = $migration_form.find("#upload_extension"),
|
||||
$export_file_input = $migration_form.find("#export_file_input"),
|
||||
$migration_config = $migration_form.find("#migration_config"),
|
||||
$migration_configs = $("#migration_configs"),
|
||||
$migration_alt_div = $("#migration_alt_div");
|
||||
|
||||
function enableFileUpload(){
|
||||
function enableFileUpload(file_type){
|
||||
file_type = typeof(file_type) != 'undefined' ? file_type : ".zip";
|
||||
$upload_extension.text(file_type);
|
||||
$export_file_enabled.val("1");
|
||||
$file_upload.show();
|
||||
}
|
||||
|
@ -78,7 +81,7 @@ $(function(){
|
|||
}).change();
|
||||
|
||||
$("#export_file_input").change(function() {
|
||||
if($(this).val().match(/\.zip$/i)) {
|
||||
if($(this).val().match(/\.zip$|\.imscc$/i)) {
|
||||
$submit_button.attr('disabled', false);
|
||||
$('.zip_error').hide();
|
||||
} else {
|
||||
|
|
|
@ -6,6 +6,8 @@ describe "Common Cartridge importing" do
|
|||
@copy_from = course_model
|
||||
@from_teacher = @user
|
||||
@copy_to = course_model
|
||||
@copy_to.name = "alt name"
|
||||
@copy_to.course_code = "alt name"
|
||||
|
||||
exporter = CC::CCExporter.new(nil, :course=>@copy_from, :user=>@from_teacher)
|
||||
manifest = CC::Manifest.new(exporter)
|
||||
|
@ -55,15 +57,18 @@ describe "Common Cartridge importing" do
|
|||
hash[:syllabus_body] = @converter.convert_syllabus(syl_doc)
|
||||
#import json into new course
|
||||
hash = hash.with_indifferent_access
|
||||
@copy_to.import_settings_from_migration({:course_settings=>hash})
|
||||
@copy_to.import_settings_from_migration({:course=>hash})
|
||||
@copy_to.save!
|
||||
|
||||
#compare settings
|
||||
@copy_to.conclude_at.to_i.should == @copy_from.conclude_at.to_i
|
||||
@copy_to.start_at.to_i.should == @copy_from.start_at.to_i
|
||||
@copy_to.syllabus_body.should == body_with_link % @copy_to.id
|
||||
@copy_to.storage_quota.should_not == @copy_from.storage_quota
|
||||
@copy_to.name.should_not == @copy_from.name
|
||||
@copy_to.course_code.should_not == @copy_from.course_code
|
||||
atts = Course.clonable_attributes
|
||||
atts -= [:start_at, :conclude_at, :grading_standard_id, :hidden_tabs, :tab_configuration, :syllabus_body]
|
||||
atts -= Canvas::MigratorHelper::COURSE_NO_COPY_ATTS
|
||||
atts.each do |att|
|
||||
@copy_to.send(att).should == @copy_from.send(att)
|
||||
end
|
||||
|
@ -305,6 +310,7 @@ describe "Common Cartridge importing" do
|
|||
Rubric.process_migration({'rubrics'=>hash}, @migration)
|
||||
@copy_to.save!
|
||||
|
||||
@copy_to.rubric_associations.count.should == 1
|
||||
lo_2 = @copy_to.learning_outcomes.find_by_migration_id(CC::CCHelper.create_key(lo))
|
||||
lo_2.should_not be_nil
|
||||
rubric_2 = @copy_to.rubrics.find_by_migration_id(CC::CCHelper.create_key(rubric))
|
||||
|
|
Loading…
Reference in New Issue