Skip to content

Commit 6a3c4a0

Browse files
committed
add file delete feature for ownership table
1 parent 1596587 commit 6a3c4a0

4 files changed

Lines changed: 40 additions & 10 deletions

File tree

app/assets/javascripts/exercise_uploader.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
var allfiles = [];
1+
var allfiles = []
2+
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+
}
8+
9+
createTextAndButton(oldfiles)
10+
}
211

312
function removeEle(arr,ele){
413
for( var i = 0; i < arr.length; i++){
@@ -17,8 +26,9 @@ function addButtonListener(allfiles){
1726
text.nextSibling.remove()
1827
text.remove()
1928
button.remove()
20-
document.getElementById("exercise_name").value = allfiles.toString()
29+
document.getElementById("exercise_fileList").value = allfiles.toString()
2130
});
31+
2232
}
2333

2434
// update file name and delete button
@@ -40,14 +50,17 @@ function createTextAndButton(allfiles){
4050
// listener for upload button
4151
$("#exercise_files").bind("change", function (e)
4252
{
43-
allfiles = [];
53+
allfiles = []
54+
for (var i of oldfiles) {
55+
allfiles.push(i);
56+
}
4457
var file = document.getElementById("exercise_files")
4558
for (var i = 0; i < file.files.length; i++) {
4659
filename = file.files[i].name
4760
if(allfiles.indexOf(filename) === -1) {
4861
allfiles.push(filename.trim());
4962
}
5063
}
51-
document.getElementById("exercise_name").value = allfiles.toString()
64+
document.getElementById("exercise_fileList").value = allfiles.toString()
5265
createTextAndButton(allfiles)
5366
});

app/controllers/exercises_controller.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ def new
137137
# GET /exercises/1/edit
138138
def edit
139139
@exercise_version = @exercise.current_version
140+
@ownerships_all = Array.new
141+
@exercise_version.ownerships.each do |e|
142+
@ownerships_all.push e.filename
143+
end
144+
140145
@text_representation = @exercise_version.text_representation ||
141146
ExerciseRepresenter.new(@exercise).to_hash.to_yaml
142147
@user_groups = current_user.user_groups
@@ -332,8 +337,10 @@ def upload_create
332337
edit_rights = 0 # Personal exercise
333338
end
334339
files = exercise_params[:files]
335-
fileList = exercise_params[:name]
336-
files = cleanFile(files,fileList)
340+
fileList = exercise_params[:fileList]
341+
if fileList != "" && !files.nil?
342+
files = cleanFile(files,fileList)
343+
end
337344
if !hash.kind_of?(Array)
338345
hash = [hash]
339346
end
@@ -383,9 +390,15 @@ def upload_create
383390
if !e.exercise_versions.offset(1).first.nil?
384391
oldversion = e.exercise_versions.offset(1).first
385392
oldversion.ownerships.each do |ownerentry|
386-
ownertable = ex_ver.ownerships.create(filename: ownerentry.filename, resource_file_id: ownerentry.resource_file_id)
393+
if fileList != ""
394+
if fileList.include? ownerentry.filename
395+
ownertable = ex_ver.ownerships.create(filename: ownerentry.filename, resource_file_id: ownerentry.resource_file_id)
396+
end
397+
end
387398
end
388399
end
400+
# p "&&&&&&&&&&&&&"
401+
# p ex_ver.ownerships
389402
# add new ownertable
390403
unless files.nil?
391404
files.each do |file|
@@ -401,6 +414,8 @@ def upload_create
401414
end
402415
end
403416
end
417+
# p "current added akll ownership"
418+
# p ex_ver.ownerships
404419
exercise_collection.andand.add(e, override: true)
405420
e.current_version.update(text_representation: text_representation)
406421
success_msgs <<

app/views/exercises/_oneblockform.html.haml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
input_html: { class: 'code', autofocus: true, data: { lang: 'text/x-yaml' },
1818
value: @text_representation.present? ? @text_representation : '' },
1919
label: 'YAML Representation of the Exercise:'
20-
20+
%p
2121
%p
2222
.inputWrapper
2323
= f.file_field :files, multiple: true,:class => "fileInput"
24-
= f.text_field :name, value: nil, :type => "hidden"
25-
24+
= f.text_field :fileList, value: nil, :type => "hidden"
25+
= f.text_field :oldfileList, value: @ownerships_all, :type => "hidden"
2626
#fileName
2727
= stylesheet_link_tag "exercise_uploader.scss"
2828
= javascript_include_tag 'exercise_uploader.js'
@@ -31,3 +31,5 @@
3131
.row
3232
.col-md-9
3333
= f.submit class: 'btn btn-primary', value: 'Submit'
34+
35+
-9.05 KB
Binary file not shown.

0 commit comments

Comments
 (0)