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

Stage to lesson #40695

Merged
merged 4 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions dashboard/app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ def section_progress
section = load_section
script = load_script(section)

# stage data
stages = script.script_levels.select {|sl| sl.bonus.nil?}.group_by(&:lesson).map do |stage, levels|
# lesson data
lessons = script.script_levels.select {|sl| sl.bonus.nil?}.group_by(&:lesson).map do |lesson, levels|
{
length: levels.length,
title: ActionController::Base.helpers.strip_tags(stage.localized_title)
title: ActionController::Base.helpers.strip_tags(lesson.localized_title)
}
end

Expand Down Expand Up @@ -298,7 +298,7 @@ def section_progress
id: script.id,
name: data_t_suffix('script.name', script.name, 'title'),
levels_count: script_levels.length,
stages: stages,
stages: lessons,
}
}

Expand Down Expand Up @@ -387,8 +387,8 @@ def user_progress_for_stage
response[:signedIn] = !current_user.nil?

script = Script.get_from_cache(params[:script])
stage = script.lessons[params[:lesson_position].to_i - 1]
script_level = stage.cached_script_levels[params[:level_position].to_i - 1]
lesson = script.lessons[params[:lesson_position].to_i - 1]
script_level = lesson.cached_script_levels[params[:level_position].to_i - 1]
level = params[:level] ? Script.cache_find_level(params[:level].to_i) : script_level.oldest_active_level

if current_user
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/controllers/scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def instructions

script = Script.get_from_cache(params[:id])

render 'levels/instructions', locals: {stages: script.lessons}
render 'levels/instructions', locals: {lessons: script.lessons}
end

def vocab
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/models/plc/enrollment_unit_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def summarize_progress
}
end
else
# Otherwise, status is determined by the completion of stages
# Otherwise, status is determined by the completion of lessons
plc_course_unit.script.lesson_groups.each do |lesson_group|
summary << {
category: lesson_group.localized_display_name,
Expand Down
6 changes: 3 additions & 3 deletions dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1338,12 +1338,12 @@ def self.update_i18n(existing_i18n, lessons_i18n, script_name = '', metadata_i18
metadata_i18n['lessons'] = {}
unless lesson_descriptions.nil?
JSON.parse(lesson_descriptions).each do |lesson|
stage_name = lesson['name']
stage_data = {
lesson_name = lesson['name']
lesson_data = {
'description_student' => lesson['descriptionStudent'],
'description_teacher' => lesson['descriptionTeacher']
}
metadata_i18n['lessons'][stage_name] = stage_data
metadata_i18n['lessons'][lesson_name] = lesson_data
end
end
metadata_i18n = {'en' => {'data' => {'script' => {'name' => {script_name => metadata_i18n.to_h}}}}}
Expand Down
30 changes: 15 additions & 15 deletions dashboard/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1248,11 +1248,11 @@ def script_level_hidden?(script_level)
script_sections = sections.select {|s| s.script.try(:id) == script_level.script.id}

if !script_sections.empty?
# if we have one or more sections matching this script id, we consider a stage hidden if all of those sections
# hides the stage
# if we have one or more sections matching this script id, we consider a lesson hidden if all of those sections
# hides the lesson
script_sections.all? {|s| script_level.hidden_for_section?(s.id)}
else
# if we have no sections matching this script id, we consider a stage hidden if any of the sections we're in
# if we have no sections matching this script id, we consider a lesson hidden if any of the sections we're in
# hide it
sections.any? {|s| script_level.hidden_for_section?(s.id)}
end
Expand All @@ -1279,8 +1279,8 @@ def script_hidden?(script)

# @return {Hash<string,number[]>|number[]}
# For teachers, this will be a hash mapping from section id to a list of hidden
# stage ids for that section.
# For students this will just be a list of stage ids that are hidden for them.
# lesson ids for that section.
# For students this will just be a list of lesson ids that are hidden for them.
def get_hidden_lesson_ids(script_name)
script = Script.get_from_cache(script_name)
return [] if script.nil?
Expand Down Expand Up @@ -2330,45 +2330,45 @@ def hidden_script_ids(sections)
end

# This method will extract a list of hidden ids by section. The type of ids depends
# on the input. If hidden_stages is true, id is expected to be a script id and
# we look for stages that are hidden. If hidden_stages is false, id is expected
# on the input. If hidden_lessons is true, id is expected to be a script id and
# we look for stages that are hidden. If hidden_lessons is false, id is expected
# to be a course_id, and we look for hidden scripts.
# @param {boolean} hidden_stages - True if we're looking for hidden stages, false
# @param {boolean} hidden_lessons - True if we're looking for hidden stages, false
# if we're looking for hidden scripts.
# @return {Hash<string,number[]>
def get_teacher_hidden_ids(hidden_stages)
def get_teacher_hidden_ids(hidden_lessons)
# If we're a teacher, we want to go through each of our sections and return
# a mapping from section id to hidden stages/scripts in that section
hidden_by_section = {}
sections.each do |section|
hidden_by_section[section.id] = hidden_stages ? hidden_lesson_ids([section]) : hidden_script_ids([section])
hidden_by_section[section.id] = hidden_lessons ? hidden_lesson_ids([section]) : hidden_script_ids([section])
end
hidden_by_section
end

# This method method will go through each of the sections in which we're a member
# and determine which stages/scripts should be hidden
# @param {boolean} hidden_stages - True if we're looking for hidden stages, false
# @param {boolean} hidden_lessons - True if we're looking for hidden stages, false
# if we're looking for hidden scripts.
# @return {number[]} Set of stage/script ids that should be hidden
def get_student_hidden_ids(assign_id, hidden_stages)
def get_student_hidden_ids(assign_id, hidden_lessons)
sections = sections_as_student
return [] if sections.empty?

sections = sections.reject(&:hidden)
assigned_sections = sections.select do |section|
hidden_stages ? section.script_id == assign_id : section.course_id == assign_id
hidden_lessons ? section.script_id == assign_id : section.course_id == assign_id
end

if assigned_sections.empty?
# if we have no sections matching this assignment, we consider a stage/script
# hidden if any of our sections hides it
return (hidden_stages ? hidden_lesson_ids(sections) : hidden_script_ids(sections)).uniq
return (hidden_lessons ? hidden_lesson_ids(sections) : hidden_script_ids(sections)).uniq
else
# if we do have sections matching this assignment, we consider a stage/script
# hidden only if it is hidden in every one of the sections the student belongs
# to that match this assignment
all_ids = hidden_stages ? hidden_lesson_ids(assigned_sections) : hidden_script_ids(assigned_sections)
all_ids = hidden_lessons ? hidden_lesson_ids(assigned_sections) : hidden_script_ids(assigned_sections)

counts = all_ids.each_with_object(Hash.new(0)) {|id, hash| hash[id] += 1}
return counts.select {|_, val| val == assigned_sections.length}.keys
Expand Down
8 changes: 4 additions & 4 deletions dashboard/app/views/levels/instructions.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
}
}

- stages = local_assigns[:stages]
- lessons = local_assigns[:lessons]
.instructions_summary
- stages.each_with_index do |stage, index|
%h1= stage.localized_title
- stage.script_levels.each do |script_level|
- lessons.each_with_index do |lesson|
%h1= lesson.localized_title
- lesson.script_levels.each do |script_level|
- level = script_level.level
.script_level
= link_to "Level #{script_level.position}: #{script_level.level.name}", build_script_level_path(script_level)
Expand Down