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

Splice embed - Implement Exercise Collection Page with iFrame and LTI Embeds #227

Open
wants to merge 20 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
24 changes: 24 additions & 0 deletions .github/workflows/deploy-acos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: deploy-acos
on:
push:
branches:
- keweizhan

jobs:
build:
name: deploy-acos
runs-on: self-hosted
steps:
- name: ssh
uses: fifsky/ssh-action@master
with:
host: ${{ secrets.STAGING_HOST }}
user: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.STAGING_KEY }}
port: ${{ secrets.STAGING_PORT }}
args: "-tt"
command: |
cd /home/deploy/code-workout/
docker compose pull
docker-compose down
docker-compose up -d
32 changes: 32 additions & 0 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: image-build
on:
push:
branches:
- keweizhan
jobs:
build:
name: code-workout-image
runs-on: self-hosted
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: opendsa/code-workout:latest
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ gem 'coffee-script-source'
gem 'test-unit', '~> 3.0.9'
gem 'nokogiri', '~> 1.10.4'
gem 'csv_shaper'
gem 'andand', github: 'raganwald/andand'
gem 'andand', git: 'https://github.com/raganwald/andand'
gem 'responders' # Can't move above 1.1 until migrating to rails 4.2+
gem 'friendly_id', '~> 5'
gem 'active_record-acts_as'
Expand Down Expand Up @@ -50,7 +50,7 @@ group :development, :test do
gem 'sqlite3', '~> 1.3.0'
gem 'rspec-rails'
gem 'annotate'
gem 'rails-erd', github: 'voormedia/rails-erd'
gem 'rails-erd', git: 'https://github.com/voormedia/rails-erd'
gem 'faker'
# Needed for debugging support in Aptana Studio. Disabled, since these
# two gems do not support Ruby 2.0 yet :-(.
Expand Down Expand Up @@ -113,7 +113,8 @@ group :deploy do
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'capistrano3-puma', github: 'seuros/capistrano-puma'
gem 'capistrano3-puma', '~> 4.0.0',
git: 'https://github.com/seuros/capistrano-puma', branch: 'v4.x'
end

#for multi-color progress bar
Expand Down
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
GIT
remote: git://github.com/raganwald/andand.git
remote: https://github.com/raganwald/andand
revision: d6c4545b6649c70495c26e2038206c5fdb2d14d6
specs:
andand (1.3.3)

GIT
remote: git://github.com/seuros/capistrano-puma.git
revision: 6112323390cff15539d947882d72d937622cfdf4
remote: https://github.com/seuros/capistrano-puma
revision: b148515f78476b68ab8e09bcc494e82ceb53eba0
branch: v4.x
specs:
capistrano3-puma (4.0.0)
capistrano (~> 3.7)
capistrano-bundler
puma (~> 4.0)

GIT
remote: git://github.com/voormedia/rails-erd.git
revision: 0fbb1cdf2c84b06afd12974baace8d512bb798da
remote: https://github.com/voormedia/rails-erd
revision: 7c66258b6818c47b4d878c2ad7ff6decebdf834a
specs:
rails-erd (1.6.0)
rails-erd (1.7.2)
activerecord (>= 4.2)
activesupport (>= 4.2)
choice (~> 0.2.0)
Expand Down Expand Up @@ -391,6 +392,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.6)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
Expand All @@ -408,7 +410,8 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
ruby-graphviz (1.2.4)
ruby-graphviz (1.2.5)
rexml
ruby_parser (3.13.1)
sexp_processor (~> 4.9)
rubyzip (1.3.0)
Expand Down Expand Up @@ -510,7 +513,7 @@ DEPENDENCIES
capistrano-bundler
capistrano-rails
capistrano-rvm
capistrano3-puma!
capistrano3-puma (~> 4.0.0)!
capybara
carrierwave (= 1.3.2)
cocoon
Expand Down
30 changes: 30 additions & 0 deletions app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,33 @@ ul.ui-autocomplete {
max-height: 5em;
height: auto;
}

// syling for embed collection page for SPLICE
.exercise-container.card {
width: 200%; // Adjust width as needed
// padding-left: 0 //
}

.iframe-label-container {
clear: both; // Clear floats to ensure this container stays below preceding content
margin-top: 8px; // Add margin at the top to create space between this container and the preceding content
margin-bottom: 8px; // Adjust spacing below the label
// padding-left: 0
}

.iframe-label-container label {
display: block;
font-size: 11px;
margin-bottom: 5px;

}

.exercise-details {
margin-bottom: 10px; // Adds space before the button
padding-left: 20px;

input.form-control {
width: 40%; // text field the same width as the thumbnail
font-size: 9px;
}
}
42 changes: 41 additions & 1 deletion app/controllers/exercises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ExercisesController < ApplicationController


load_and_authorize_resource
skip_authorize_resource only: [:practice, :call_open_pop]
skip_authorize_resource only: [:practice, :call_open_pop, :embed_collection, :export]

#~ Action methods ...........................................................
after_action :allow_iframe, only: [:practice, :embed]
Expand All @@ -26,6 +26,46 @@ def index
@exercises = @exercises.page params[:page]
end

# This embed_collection fetches all exercises for the embed_collections page and provides a simplified iframe urls of exercises for SPLICE
def embed_collection
if current_user
@exercises = Exercise.visible_to_user(current_user)
else
@exercises = Exercise.publicly_visible
end

@exercises = @exercises.page(params[:page])
end

# The export function gets all exercises metadata for SPLICE
def export
# filter out stop/connector words for keywords from workout phrases or names
stop_words = ['the', 'and', 'a', 'to', 'of', 'in', 'for', 'on', 'with', 'as', 'by', 'at', 'from', 'is', 'that', 'which', 'it', 'an', 'be', 'this', 'are', 'we', 'can', 'if', 'has', 'but']

@exercises = Exercise.all
export_data = @exercises.map do |exercise|
workout_names = exercise.exercise_workouts.map { |ew| ew.workout.name }.uniq.push(exercise.name)
# split phrases into words, remove stop/connector words
keywords_array = workout_names.map { |phrase| phrase.downcase.split(/\W+/) }.flatten.uniq.reject { |word| stop_words.include?(word) || word.empty? }

{
"Platform_name": "Code-Workout",
"URL": "https://codeworkout.cs.vt.edu", # hardcoded URL for now
"LTI_Instructions_URL": "https://opendsa-server.cs.vt.edu/guides/opendsa-canvas",
"Exercise_type": Exercise::TYPE_NAMES[exercise.question_type],
"License": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)",
"Description": exercise.exercise_collection&.description,
"Author": "Edwards",
"Institution": "VT",
"Keywords": keywords_array,
"Exercise_Name": exercise.name,
"Iframe_URL": exercise.iframe_url,
"LTI_URL": exercise.lti_launch_url
}
end
render json: export_data
end


# -------------------------------------------------------------
# GET /exercises/download.csv
Expand Down
42 changes: 39 additions & 3 deletions app/jobs/code_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ def perform(attempt_id)
# compile and evaluate the attempt in a temporary location
attempt_dir = "usr/attempts/active/#{current_attempt}"
# puts "DIRECTORY",attempt_dir,"DIRECTORY"
FileUtils.mkdir_p(attempt_dir)
if !Dir[attempt_dir].empty?
puts 'WARNING, OVERWRITING EXISTING DIRECTORY = ' + attempt_dir
FileUtils.remove_dir(attempt_dir, true)
FileUtils.mkdir_p(attempt_dir)
end
FileUtils.mkdir_p(attempt_dir)
if !File.exist?(prompt.test_file_name)
# Workaround for bug in correctly pre-generating test file
# on exercise creation. If it doesn't exist, force regeneration
Expand Down Expand Up @@ -198,8 +197,45 @@ def perform(attempt_id)
def execute_javatest(class_name, attempt_dir, pre_lines, answer_lines)
if CodeWorkout::Config::CMD[:java].key? :daemon_url
url = CodeWorkout::Config::CMD[:java][:daemon_url] % {attempt_dir: attempt_dir}
response = Net::HTTP.get_response(URI.parse(url))
uri = URI.parse(url)

# response = Net::HTTP.get_response(URI.parse(url))
# puts "%{url} => response %{response.code}"

response = nil

max_retries = 3
for a in 1..max_retries do
begin
Net::HTTP.new(uri.hostname, uri.port).start do |http|
http.open_timeout = 4
response = http.request_get(uri.request_uri)

if response.nil?
puts "GET #{url} => try #{a} no response"
elsif response.kind_of? Net::HTTPSuccess # response.code == 200
break
else
puts "GET #{url} => try #{a} bad response: #{response.code}"
end
# puts "%{url} => response %{response.code}"

# pause before retrying
sleep(4)
end
rescue => e
puts "GET #{url} => try #{a} error: #{e.message}"
end
end
if response.nil? then
puts "Server backend error [no response] for #{attempt_dir}"
return "Server backend error [no response]. Please resubmit your answer."
elsif !(response.kind_of? Net::HTTPSuccess) # response.code != 200
puts "Server backend error #{response.code} for #{attempt_dir}:"
puts response.body
return "Server backend error #{response.code}. Please resubmit your answer."
end

else
cmd = CodeWorkout::Config::CMD[:java][:cmd] % {attempt_dir: attempt_dir}
# puts(cmd + '>> err.log 2>> err.log')
Expand Down
10 changes: 6 additions & 4 deletions app/models/attempt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#
# Indexes
#
# index_attempts_on_active_score_id (active_score_id)
# index_attempts_on_exercise_version_id (exercise_version_id)
# index_attempts_on_user_id (user_id)
# index_attempts_on_workout_score_id (workout_score_id)
# idx_attempts_on_user_exercise_version (user_id,exercise_version_id)
# idx_attempts_on_workout_score_exercise_version (workout_score_id,exercise_version_id)
# index_attempts_on_active_score_id (active_score_id)
# index_attempts_on_exercise_version_id (exercise_version_id)
# index_attempts_on_user_id (user_id)
# index_attempts_on_workout_score_id (workout_score_id)
#
# Foreign Keys
#
Expand Down
Loading