Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
264 changes: 0 additions & 264 deletions app/views/api/scratch/projects/show.json

This file was deleted.

6 changes: 2 additions & 4 deletions lib/tasks/for_education.rake
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ namespace :for_education do

school = create_school(creator_id, TEST_SCHOOL)
verify_school(school)
school.update!(scratch_enabled: true)
assign_a_teacher(teacher_id, school)

school_class = create_school_class(creator_id, school)
assign_students(school_class, school)

lessons = create_lessons(creator_id, school, school_class)
lessons.each do |lesson|
create_project(creator_id, school, lesson)
end
create_lessons(creator_id, school, school_class)
Rails.logger.info 'Done...'
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/project_preview_seeds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ProjectPreviewSeedsHelper
PROJECT_PREVIEW_LOCALE_FR = 'fr-FR'
PROJECT_PREVIEW_NAME = 'Experience CS Preview Starter'
PROJECT_PREVIEW_NAME_FR = 'Démo Aperçu Experience CS'
PROJECT_PREVIEW_CONTENT_PATH = Rails.root.join('lib/tasks/seed_data/excs_preview_starter.json')
PROJECT_PREVIEW_CONTENT_PATH = Rails.root.join('lib/tasks/seed_data/scratch_starter_example.json')
PROJECT_PREVIEW_INSTRUCTIONS_PATH = Rails.root.join('lib/tasks/seed_data/excs_preview_starter_instructions.json')
PROJECT_PREVIEW_INSTRUCTIONS_FR_PATH = Rails.root.join('lib/tasks/seed_data/excs_preview_starter_instructions_fr.json')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
{
"isStage": true,
"name": "Stage",
"variables": {
"`jEk@4|i[#Fk?(8x)AV.-my variable": ["my variable", 0]
},
"variables": { "`jEk@4|i[#Fk?(8x)AV.-my variable": ["my variable", 0] },
"lists": {},
"broadcasts": {},
"blocks": {},
Expand Down
54 changes: 42 additions & 12 deletions lib/tasks/seeds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative 'project_preview_seeds_helper'

# rubocop:disable Metrics/ModuleLength
module SeedsHelper
include ProjectPreviewSeedsHelper

Expand Down Expand Up @@ -93,31 +94,60 @@ def assign_students(school_class, school)
end
end

LESSON_PROJECT_TYPES = ['python', 'html/css', 'scratch'].freeze

LESSON_SCRATCH_CONTENT_PATH = Rails.root.join('lib/tasks/seed_data/scratch_starter_example.json')

LESSON_HTML_CONTENT = <<~HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Heading</h1>
<p>Paragraph</p>
</body>
</html>
HTML

def create_lessons(user_id, school, school_class, visibility = 'students')
Array.new(2) do |i|
lesson_name = "Lesson #{i + 1}: #{Faker::ProgrammingLanguage.name}"
Lesson.find_or_create_by!(school:, school_class:, name: lesson_name, user_id:) do |lesson|
LESSON_PROJECT_TYPES.each_with_index.map do |project_type, i|
lesson_name = "Lesson #{i + 1} #{project_type}"
lesson = Lesson.find_or_create_by!(school:, school_class:, name: lesson_name, user_id:) do |l|
Rails.logger.info "Seeding Lesson #{i + 1}..."
lesson.user_id = user_id
lesson.school = school
lesson.school_class = school_class
lesson.name = lesson_name
lesson.visibility = visibility
l.user_id = user_id
l.school = school
l.school_class = school_class
l.name = lesson_name
l.visibility = visibility
end
create_project(user_id, school, lesson, project_type)
lesson
end
end

def create_project(user_id, school, lesson, code = '')
def create_project(user_id, school, lesson, project_type)
Project.find_or_create_by!(user_id:, school:, lesson:) do |project|
Rails.logger.info "Seeding a project for #{lesson.name}..."
project.name = lesson.name
project.user_id = user_id
project.school = school
project.lesson = lesson
project.locale = 'en'
project.project_type = Project::Types::PYTHON
project.components << Component.new({ extension: 'py', name: 'main',
content: code })

case project_type
when 'scratch'
project.project_type = Project::Types::CODE_EDITOR_SCRATCH
project.build_scratch_component(content: JSON.parse(File.read(LESSON_SCRATCH_CONTENT_PATH)))
when 'html/css'
project.project_type = Project::Types::HTML
project.components << Component.new(extension: 'html', name: 'index', content: LESSON_HTML_CONTENT)
project.components << Component.new(extension: 'css', name: 'style', content: "h1 {\n color: blue;\n}")
else
project.project_type = Project::Types::PYTHON
project.components << Component.new(extension: 'py', name: 'main', content: 'print("Hello World!")')
end
end
end
end
# rubocop:enable Metrics/ModuleLength
Loading
Loading