From 0cf82915cc591e232064d2523e04371947a66aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Czkewei19=E2=80=9D?= Date: Thu, 14 Mar 2024 17:06:07 -0400 Subject: [PATCH] update the way to get external id --- app/assets/javascripts/simple.js | 4 +++- app/controllers/exercises_controller.rb | 22 ++++------------------ app/models/exercise.rb | 2 +- app/models/parsons.rb | 1 + app/models/parsons_prompt.rb | 3 +++ 5 files changed, 12 insertions(+), 20 deletions(-) create mode 100644 app/models/parsons_prompt.rb diff --git a/app/assets/javascripts/simple.js b/app/assets/javascripts/simple.js index 45b279c5..3be7cf16 100644 --- a/app/assets/javascripts/simple.js +++ b/app/assets/javascripts/simple.js @@ -7,7 +7,7 @@ $(document).ready(function () { // console.log(data) // }); // }) - + var index = window.location.pathname.split('/').pop().split('.')[0]; var parson = new ParsonsWidget({ 'sortableId': 'sortable', @@ -62,6 +62,8 @@ $(document).ready(function () { //parson.loadProgress() parson.shuffleLines(); parsedTrace = parson.parseTrace(trace) + var externalId = $('#exercise-data').data('external-id'); + console.log(externalId); }); $("#newInstanceLink").click(function (event) { event.preventDefault() diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 0484a921..e3c9e9ea 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -34,24 +34,10 @@ def show_exercise def get_external_id(step) - case step - when 's0' - 'Eoixhdpqs' - when 's1' - 'Eofijhegv' - when 's2' - 'Eyprnjgub' - when 's3' - 'Eqvrwfkcl' - when 's4' - 'Epvtmlkzf' - when 's5' - 'Eiesgmxhy' - when 's6' - 'Ebezfkxvm' - else - nil - end + full_name = "parsons_#{step}" + exercise = Exercise.where('name LIKE ?', "%#{full_name}%").first + puts "exercise = #{exercise.inspect}" + exercise ? exercise.external_id : nil end protect_from_forgery with: :null_session # if API CSRF protection is not needed,use null_session instead diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 1320a9a0..b2569a02 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -95,7 +95,7 @@ class Exercise < ActiveRecord::Base TYPE_NAMES = { Q_MC => 'Multiple Choice Question', Q_CODING => 'Coding Question', - Q_BLANKS => 'Fill in the blanks' + Q_BLANKS => 'Fill in the blanks', Q_PARSONS => 'Parsons Problem' } diff --git a/app/models/parsons.rb b/app/models/parsons.rb index 3be6c185..d0ef602f 100644 --- a/app/models/parsons.rb +++ b/app/models/parsons.rb @@ -12,6 +12,7 @@ class Parsons < ActiveRecord::Base #~ Relationships ............................................................ + has_many :parsons_prompts, dependent: :destroy serialize :concepts, Array serialize :parsonsConfig, Hash diff --git a/app/models/parsons_prompt.rb b/app/models/parsons_prompt.rb new file mode 100644 index 00000000..369d0587 --- /dev/null +++ b/app/models/parsons_prompt.rb @@ -0,0 +1,3 @@ +class ParsonsPrompt < ActiveRecord::Base + belongs_to :parsons + end \ No newline at end of file