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

Fix: various issues #1974

Merged
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
13 changes: 6 additions & 7 deletions app/controllers/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,15 @@ def bulk_destroy
end

def bulk_process_csv
uuid_regex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i
uuid_regex = /\b[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}\b/i

params[:csv_files].each do |csv_file|
CSV.open(csv_file.path) do |csv_stream|
csv_stream.each do |row|
sample_id, measured_signal = row[0], row[1]
next unless sample_id&.match(uuid_regex) # non uuids are ignored
sample = Sample.find_by_uuid(sample_id)
unless sample.nil?
sample.measured_signal ||= Float(measured_signal) if measured_signal.present?
csv_stream.each do |(sample_id, measured_signal)|
next unless sample_id&.match(uuid_regex) && measured_signal.present?

if sample = Sample.find_by_uuid(sample_id.strip)
sample.measured_signal ||= Float(measured_signal.strip)
sample.save!
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/samples/_form.haml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

- if @sample_form.measured_signal
= f.form_field :measured_signal do
= f.text_field :measured_signal, readonly: true
.value= @sample_form.measured_signal

.col
= render (@can_update ? 'form_assays' : 'show_assays'), f: f
Expand Down
36 changes: 19 additions & 17 deletions app/views/samples/_upload_results_js.haml
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,32 @@
// Parse the input file
var text = load_event.target.result
var lines = text.split(/\r\n|\r|\n/); // tolerate both Windows and Unix linebreaks
var samples_param = [] // params for GET call
var samples = [] // samples uuids
var duplicates = false
lines.forEach(function(line) {
var row = line.split(',');
if (line != '' && isUUID(row[0])){
if (samples.indexOf(row[0]) == -1){
samples_param.push( 'uuids[]=' + row[0] );
samples.push( row[0] );
}
else {
duplicates = true;
}
}

lines.forEach(function(line) {
var row = line
.split(",")
.map((part) => part.trim());
if (!isUUID(row[0])) return;

if (samples.indexOf(row[0]) == -1){
samples.push(row[0]);
} else {
duplicates = true;
}
});

// Retrieve found uuids
var samples_params = samples
.map((uuid) => "uuids[]=" + uuid)
.join("&");
var context = getUrlParameter('context');
var url = '/samples/existing_uuids?context='+context+"&"+samples_param.join("&")
var url = '/samples/existing_uuids?context='+context+"&"+samples_params;
var found = await fetch(url)
.then((response) => response.json())
.then((r) => {
return r.message;
})
.then((r) => r.message);

// Compute not found ones
var not_found = samples.filter(function(x) {
return found.indexOf(x) < 0;
Expand Down