Skip to content

Commit 03bb4fc

Browse files
committed
add missing migration file and fix bugs
1 parent 6a3c4a0 commit 03bb4fc

6 files changed

Lines changed: 63 additions & 20 deletions

File tree

app/assets/javascripts/exercise_uploader.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
var allfiles = []
22
var oldfiles = []
3-
oldfileList = document.getElementById("exercise_oldfileList").value.split(' ')
4-
for( var i = 0; i < oldfileList.length; i++){
5-
if(oldfileList[i].replace(/\s/g, '').length){
6-
oldfiles.push(oldfileList[i])
7-
}
3+
var oldfileList
4+
var oldfiles
5+
checkoudFile()
86

9-
createTextAndButton(oldfiles)
7+
function checkoudFile(){
8+
oldfiles = []
9+
oldfileList = document.getElementById("exercise_oldfileList").value.split(' ')
10+
for( var i = 0; i < oldfileList.length; i++){
11+
if(oldfileList[i].replace(/\s/g, '').length){
12+
oldfiles.push(oldfileList[i])
13+
}
14+
createTextAndButton(oldfiles)
15+
}
1016
}
1117

18+
1219
function removeEle(arr,ele){
20+
arr = arr.split(",")
1321
for( var i = 0; i < arr.length; i++){
14-
if ( arr[i].trim() == ele.trim()) {
22+
if ( arr[i] == ele.trim()) {
1523
arr.splice(i, 1);
1624
}
1725
}
1826
return arr
1927
}
2028

2129
function addButtonListener(allfiles){
30+
2231
document.querySelector('#fileName').addEventListener('click', function(event) {
23-
var text= document.getElementById(event.target.id.match(/\d*/g)[0])
24-
allfiles = removeEle(allfiles, text.innerHTML.toString())
25-
var button = document.getElementById(event.target.id)
26-
text.nextSibling.remove()
27-
text.remove()
28-
button.remove()
29-
document.getElementById("exercise_fileList").value = allfiles.toString()
32+
allfiles = document.getElementById("exercise_fileList").value
33+
allfiles += oldfileList
34+
var text= document.getElementById(event.target.id.match(/\d*/g)[0])
35+
allfiles = removeEle(allfiles, text.innerHTML.toString().trim())
36+
var button = document.getElementById(event.target.id)
37+
text.nextSibling.remove()
38+
text.remove()
39+
button.remove()
40+
document.getElementById("exercise_fileList").value = allfiles.toString()
41+
document.getElementById("exercise_oldfileList").value = allfiles.toString()
3042
});
3143

3244
}
@@ -51,6 +63,7 @@ function createTextAndButton(allfiles){
5163
$("#exercise_files").bind("change", function (e)
5264
{
5365
allfiles = []
66+
checkoudFile()
5467
for (var i of oldfiles) {
5568
allfiles.push(i);
5669
}

app/controllers/exercises_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ def new
137137
# GET /exercises/1/edit
138138
def edit
139139
@exercise_version = @exercise.current_version
140-
@ownerships_all = Array.new
140+
@ownerships_all = []
141141
@exercise_version.ownerships.each do |e|
142-
@ownerships_all.push e.filename
142+
@ownerships_all.push(e.filename)
143143
end
144144

145145
@text_representation = @exercise_version.text_representation ||
@@ -414,8 +414,8 @@ def upload_create
414414
end
415415
end
416416
end
417-
# p "current added akll ownership"
418-
# p ex_ver.ownerships
417+
p "current added akll ownership"
418+
p ex_ver.ownerships
419419
exercise_collection.andand.add(e, override: true)
420420
e.current_version.update(text_representation: text_representation)
421421
success_msgs <<

app/views/exercises/_oneblockform.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
%p
2222
.inputWrapper
2323
= f.file_field :files, multiple: true,:class => "fileInput"
24-
= f.text_field :fileList, value: nil, :type => "hidden"
24+
= f.text_field :fileList, value: "", :type => "hidden"
2525
= f.text_field :oldfileList, value: @ownerships_all, :type => "hidden"
2626
#fileName
2727
= stylesheet_link_tag "exercise_uploader.scss"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddHashvalToResourceFile < ActiveRecord::Migration
2+
def change
3+
add_column :resource_files, :hashval, :string
4+
end
5+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CreateOwnerships < ActiveRecord::Migration
2+
def change
3+
create_table :ownerships do |t|
4+
t.string :filename
5+
t.references :resource_file, index: true, foreign_key: true
6+
t.references :exercise_version, index: true, foreign_key: true
7+
8+
t.timestamps null: false
9+
end
10+
end
11+
end

db/schema.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20201216191207) do
14+
ActiveRecord::Schema.define(version: 20210201051643) do
1515

1616
create_table "active_admin_comments", force: :cascade do |t|
1717
t.string "namespace", limit: 255
@@ -402,6 +402,17 @@
402402

403403
add_index "organizations", ["slug"], name: "index_organizations_on_slug", unique: true, using: :btree
404404

405+
create_table "ownerships", force: :cascade do |t|
406+
t.string "filename", limit: 255
407+
t.integer "resource_file_id", limit: 4
408+
t.integer "exercise_version_id", limit: 4
409+
t.datetime "created_at", null: false
410+
t.datetime "updated_at", null: false
411+
end
412+
413+
add_index "ownerships", ["exercise_version_id"], name: "index_ownerships_on_exercise_version_id", using: :btree
414+
add_index "ownerships", ["resource_file_id"], name: "index_ownerships_on_resource_file_id", using: :btree
415+
405416
create_table "prompt_answers", force: :cascade do |t|
406417
t.integer "attempt_id", limit: 4
407418
t.integer "prompt_id", limit: 4
@@ -437,6 +448,7 @@
437448
t.boolean "public", default: true
438449
t.datetime "created_at"
439450
t.datetime "updated_at"
451+
t.string "hashval", limit: 255
440452
end
441453

442454
add_index "resource_files", ["token"], name: "index_resource_files_on_token", using: :btree
@@ -736,6 +748,8 @@
736748
add_foreign_key "identities", "users", name: "identities_user_id_fk"
737749
add_foreign_key "lms_instances", "lms_types", name: "lms_instances_lms_type_id_fk"
738750
add_foreign_key "lti_workouts", "lms_instances"
751+
add_foreign_key "ownerships", "exercise_versions"
752+
add_foreign_key "ownerships", "resource_files"
739753
add_foreign_key "prompt_answers", "attempts", name: "prompt_answers_attempt_id_fk"
740754
add_foreign_key "prompt_answers", "prompts", name: "prompt_answers_prompt_id_fk"
741755
add_foreign_key "prompts", "exercise_versions", name: "prompts_exercise_version_id_fk"

0 commit comments

Comments
 (0)