Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DS improvements #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 73 additions & 10 deletions bin/github-to-canvas
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,43 @@ OptionParser.new do |opts|
"Removes top lesson header and any Learn.co specific footer links before converting to HTML") do |r|
options[:remove_header_and_footer] = true
end
opts.on("-d", "--ds-assignment",
"Configure the following options: --header-only --illumidesk --grading-type points --submission-type external_tool --points-possible 0") do
options[:header_only] = true
options[:illumidesk] = true
options[:grading_type] = 'points'
options[:submission_type] = 'external_tool'
options[:points_possible] = 0
end
opts.on("--header-only",
"Only generate the HTML header") do
options[:header_only] = true
end
opts.on("--grading-type TYPE",
"Sets the 'grading_type' for an assignment. Default: pass_fail. Valid options: pass_fail, percent, letter_grade, gpa_scale, points, not_graded") do |grading_type|
valid_types = %w[pass_fail percent letter_grade gpa_scale points not_graded]
unless valid_types.include? grading_type
raise "Invalid grading type: #{grading_type}"
end
options[:grading_type] = grading_type
end
opts.on("--submission-type TYPE",
"Sets the 'submission_type' for an assignment. Default: online_url. Valid options: online_quiz, none, on_paper, discussion_topic, external_tool, online_upload, online_text_entry, online_url, media_recording, student_annotation") do |submission_type|
valid_types = %w[online_quiz none on_paper discussion_topic external_tool online_upload online_text_entry online_url media_recording student_annotation]
unless valid_types.include? submission_type
raise "Invalid submission type: #{submission_type}"
end
options[:submission_type] = submission_type
end
opts.on("--points-possible POINTS",
Integer,
"Sets the 'points_possible' for an assignment. Default: 1.") do |points_possible|
options[:points_possible] = points_possible
end
opts.on("--illumidesk",
"Configure assignment to use IllumiDesk for submission") do
options[:illumidesk] = true
end
opts.on("--course COURSE",
"For align functionality only - updates the HTML content of a lesson using the provided course ID. Use with --id.") do |course_id|
options[:course_id] = course_id
Expand Down Expand Up @@ -240,7 +277,8 @@ if options[:read_from_github]
forkable: !!options[:forkable],
fis_links: !!options[:fis],
aaq: !!options[:aaq],
prework: !!options[:prework])
prework: !!options[:prework],
header_only: !!options[:header_only])
abort
end

Expand All @@ -251,11 +289,16 @@ if options[:create_from_github]
course_id: options[:course_id],
type: options[:type],
name: options[:name],
illumidesk: !!options[:illumidesk],
grading_type: options.fetch(:grading_type, 'pass_fail'),
submission_type: options.fetch(:submission_type, 'online_url'),
points_possible: options.fetch(:points_possible, 1),
remove_header_and_footer: !!options[:remove_header_and_footer],
forkable: !!options[:forkable],
fis_links: !!options[:fis],
aaq: !!options[:aaq],
prework: !!options[:prework])
prework: !!options[:prework],
header_only: !!options[:header_only])
else
puts 'Canvas course ID and lesson type required. Example: github-to-canvas --create-from-github URL --course ID --type TYPE'
end
Expand All @@ -270,11 +313,16 @@ if options[:align_from_github]
type: options[:type],
id: options[:id],
name: options[:name],
illumidesk: !!options[:illumidesk],
grading_type: options.fetch(:grading_type, 'pass_fail'),
submission_type: options.fetch(:submission_type, 'online_url'),
points_possible: options.fetch(:points_possible, 1),
remove_header_and_footer: !!options[:remove_header_and_footer],
forkable: !!options[:forkable],
fis_links: !!options[:fis],
aaq: !!options[:aaq],
prework: !!options[:prework])
prework: !!options[:prework],
header_only: !!options[:header_only])
else
puts 'Canvas course ID, lesson ID, and type required. Example: github-to-canvas --create-from-github URL --course COURSE_ID --id LESSON_ID --type TYPE'
end
Expand Down Expand Up @@ -308,7 +356,8 @@ if options[:csv_build]
aaq: !!options[:aaq],
forkable: !!options[:forkable],
branch: options[:branch],
git_links: !!options[:git_links])
git_links: !!options[:git_links],
header_only: !!options[:header_only])
abort
end

Expand All @@ -321,7 +370,8 @@ if options[:csv_align]
aaq: !!options[:aaq],
forkable: !!options[:forkable],
branch: options[:branch],
git_links: !!options[:git_links])
git_links: !!options[:git_links],
header_only: !!options[:header_only])
abort
end

Expand All @@ -333,7 +383,8 @@ if options[:build_course]
aaq: !!options[:aaq],
prework: !!options[:prework],
forkable: !!options[:forkable],
git_links: !!options[:git_links])
git_links: !!options[:git_links],
header_only: !!options[:header_only])
abort
end

Expand All @@ -347,7 +398,8 @@ if options[:add_to_course]
forkable: !!options[:forkable],
aaq: !!options[:aaq],
prework: !!options[:prework],
git_links: !!options[:git_links])
git_links: !!options[:git_links],
header_only: !!options[:header_only])
else
puts '--course required'
end
Expand All @@ -362,7 +414,8 @@ if options[:update_course_lessons]
forkable: !!options[:forkable],
aaq: !!options[:aaq],
prework: !!options[:prework],
git_links: !!options[:git_links])
git_links: !!options[:git_links],
header_only: !!options[:header_only])
abort
end

Expand Down Expand Up @@ -420,14 +473,19 @@ if options[:create_lesson]
branch: options[:branch],
name: options[:name],
type: options[:type],
illumidesk: !!options[:illumidesk],
grading_type: options.fetch(:grading_type, 'pass_fail'),
submission_type: options.fetch(:submission_type, 'online_url'),
points_possible: options.fetch(:points_possible, 1),
save_to_github: !!options[:save_to_github],
fis_links: !!options[:fis],
git_links: !!options[:git_links],
remove_header_and_footer: !!options[:remove_header_and_footer],
only_update_content: !!options[:only_content],
forkable: !!options[:forkable],
aaq: !!options[:aaq],
prework: !!options[:prework])
prework: !!options[:prework],
header_only: !!options[:header_only])
end

if options[:align]
Expand All @@ -439,12 +497,17 @@ if options[:align]
branch: options[:branch],
name: options[:name],
type: options[:type],
illumidesk: !!options[:illumidesk],
grading_type: options.fetch(:grading_type, 'pass_fail'),
submission_type: options.fetch(:submission_type, 'online_url'),
points_possible: options.fetch(:points_possible, 1),
save_to_github: !!options[:save_to_github],
fis_links: !!options[:fis],
git_links: !!options[:git_links],
remove_header_and_footer: !!options[:remove_header_and_footer],
only_update_content: !!options[:only_content],
forkable: !!options[:forkable],
aaq: !!options[:aaq],
prework: !!options[:prework])
prework: !!options[:prework],
header_only: !!options[:header_only])
end
10 changes: 8 additions & 2 deletions lib/github-to-canvas/canvas_dotfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def self.update_assignment_data(response, course, type)
id: response['id'],
course_id: course.to_i,
canvas_url: response['html_url'],
type: type
type: type,
grading_type: response['grading_type'],
points_possible: response['points_possible'],
submission_type: response['submission_types'][0],
}
canvas_data[:lessons] << lesson_data
end
Expand All @@ -56,7 +59,10 @@ def self.create_assignment_data(response, course, type)
id: response['id'],
course_id: course.to_i,
canvas_url: response['html_url'],
type: type
type: type,
grading_type: response['grading_type'],
submission_type: response['submission_types'][0],
points_possible: response['points_possible']
}
]
}
Expand Down
50 changes: 46 additions & 4 deletions lib/github-to-canvas/canvas_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def self.update_all_related_lessons(options, name, html)
options[:id] = lesson[:id]
options[:course_id] = lesson[:course_id]
options[:type] = lesson[:type]

options[:submission_type] = lesson.fetch(:submission_type, 'online_url')
options[:grading_type] = lesson.fetch(:grading_type, 'pass_fail')
options[:points_possible] = lesson.fetch(:points_possible, 1)
}
RepositoryInterface.local_repo_post_submission(options, response)
puts "Canvas lesson updated. Lesson available at #{response['html_url']}"
Expand Down Expand Up @@ -389,10 +391,13 @@ def self.build_payload(options, name, html)
payload = {
'assignment[name]' => name,
'assignment[description]' => html,
'assignment[submission_types][]' => "online_url",
'assignment[grading_type]' => 'pass_fail',
'assignment[points_possible]' => 1
'assignment[submission_types][]' => options.fetch(:submission_type, 'online_url'),
'assignment[grading_type]' => options.fetch(:grading_type, 'pass_fail'),
'assignment[points_possible]' => options.fetch(:points_possible, 1)
}
if options[:illumidesk]
payload.merge!(self.illumidesk_payload(options))
end
elsif options[:type] == "discussion"
payload = {
'title' => name,
Expand All @@ -406,6 +411,7 @@ def self.build_payload(options, name, html)
}
end
end
payload
end

def self.read_lesson(url)
Expand Down Expand Up @@ -452,6 +458,42 @@ def self.read_lesson(url)
lesson_info.to_yaml
end

def self.illumidesk_payload(options)
# get content ID: query API for external tools/Illumidesk
content_id = self.get_illumidesk_id(options[:course_id])

# compose URL with repo data: learn-co-curriculum, dsc-json-lab-v2-1, index.ipynb, master
repo_info = RepositoryConverter.get_repo_info(options[:filepath])
url = "https://flatiron.illumidesk.com/hub/lti/launch?next=%2Fhub%2Fuser-redirect%2Fgit-pull%3Frepo%3Dhttps%253A%252F%252Fgithub.jparrowsec.cn%252F#{repo_info[:repo_org]}%252F#{repo_info[:repo_name]}%26urlpath%3Dtree%252F#{repo_info[:repo_name]}%252Findex.ipynb%26branch%3D#{options.fetch(:branch, 'master')}"

{
'assignment[external_tool_tag_attributes]' => {
content_id: content_id,
content_type: "context_external_tool",
custom_params: "",
external_data: "",
new_tab: "1",
url: url
}
}
end

def self.get_illumidesk_id(course_id)
url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/external_tools?search_term=IllumiDesk"
response = RestClient.get(url, headers={
"Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
})
external_tools = JSON.parse(response)
if external_tools.empty?
raise "IllumiDesk not enabled for course ID: #{course_id}"
else
external_tools[0]['id']
end
rescue
puts "IllumiDesk not enabled for course ID: #{course_id}"
abort
end

def self.create_lesson_from_remote(course_id, module_id, lesson_type, raw_url, yaml_file)
url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/modules/#{module_id}/items"
if yaml_file
Expand Down
2 changes: 2 additions & 0 deletions lib/github-to-canvas/repository_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def self.convert_to_html(markdown)
end

def self.adjust_converted_html(options, html)
return self.add_fis_links(options, "") if options[:header_only]

if options[:remove_header_and_footer]
html = self.remove_header_and_footer(html)
end
Expand Down