Refactoring to git review specifications

This commit is contained in:
Zanz2 2017-10-07 22:13:31 +02:00
parent 9655c98566
commit 183c93d21b
3 changed files with 27 additions and 32 deletions

View file

@ -632,22 +632,20 @@ class ProtocolsController < ApplicationController
(before_start warning guidelines manuscript_citation publish_date
created_on vendor_name vendor_link keywords tags link)
]
description_string = Sanitize.clean(params['protocol']['description'])
description_string = sanitize_input(params['protocol']['description'])
description_array.each do |e|
if e == 'created_on' && @json_object[e].present?
new_e = e.slice(0, 1).capitalize + e.slice(1..-1)
new_e = new_e.tr('_', ' ')
description_string =
description_string + new_e.to_s + ': ' +
Sanitize.clean(params['protocol']['created_at'].to_s) + "\n"
new_e = e.humanize
description_string +=
new_e.to_s + ': ' +
sanitize_input(params['protocol']['created_at'].to_s) + "\n"
elsif e == 'tags' && @json_object[e].any? && @json_object[e] != ''
new_e = e.slice(0, 1).capitalize + e.slice(1..-1)
new_e = new_e.tr('_', ' ')
description_string = description_string + new_e.to_s + ': '
new_e = e.humanize
description_string +=
new_e.to_s + ': '
@json_object[e].each do |tag|
description_string =
description_string +
Sanitize.clean(tag['tag_name']) + ' , '
description_string +=
sanitize_input(tag['tag_name']) + ' , '
end
description_string += "\n"
# Since protocols description field doesnt show html,i just remove it
@ -655,11 +653,10 @@ class ProtocolsController < ApplicationController
# what this does is basically appends "FIELD NAME: "+" FIELD VALUE"
# to description for various fields
elsif @json_object[e].present?
new_e = e.slice(0, 1).capitalize + e.slice(1..-1)
new_e = new_e.tr('_', ' ')
new_e = e.humanize
description_string +=
new_e.to_s + ': ' +
Sanitize.clean(@json_object[e].to_s) + "\n"
sanitize_input(@json_object[e].to_s) + "\n"
end
end
@db_json['authors'] = params['protocol']['authors']
@ -667,7 +664,7 @@ class ProtocolsController < ApplicationController
@db_json['updated_at'] = params['protocol']['last_modified']
@db_json['description'] = description_string
@db_json['steps'] = {}
pos = -1
# these whitelists are there to not let some useless step components trough,
# that always have data set to null (data doesnt get imported over to json)
whitelist_simple = %w(1 6 17)
@ -678,8 +675,8 @@ class ProtocolsController < ApplicationController
# id 9 = dataset, id 15 = command, id 18 = attached sub protocol
# id 19= safety information ,
# id 20= regents (materials, like scinote samples kind of)
@json_object['steps'].each do |step| # loop over steps
pos += 1 # position of step (first, second.... etc),
@json_object['steps'].each_with_index do |step,pos| # loop over steps
# position of step (first, second.... etc),
@db_json['steps'][pos.to_s] = {} # the json we will insert into db
@db_json['steps'][pos.to_s]['position'] = pos
step['components'].each do |key, value|
@ -740,19 +737,19 @@ class ProtocolsController < ApplicationController
end
end
p_name =
if @db_json['name'].present? && !@db_json['name'].empty?
if @db_json['name'].present?
escape_input(@db_json['name'])
else
t('protocols.index.no_protocol_name')
end
if transaction_error
@protocolsio_general_error = true
# General something went wrong, upload to db failed error
# format.json {
# render json: { name: p_name, status: :bad_request },
# status: :bad_request
# }
else
# General something went wrong, upload to db failed error
@protocolsio_general_error = false
format.json do
render json:

View file

@ -35,7 +35,8 @@
</div>
<div class="form-group">
<label>
<span class="glyphicon glyphicon-user"></span>&nbsp;<%= t("protocols.import_export.import_modal.authors_label") %>
<span class="glyphicon glyphicon-user">
</span>&nbsp;<%= t("protocols.import_export.import_modal.authors_label") %>
</label>
<%= f.text_field :authors, :value => @json_object['full_name'], class:
"form-control" %>
@ -53,14 +54,15 @@
<label><%= t("protocols.import_export.import_modal.created_at_label") %></label>
<% display_created_at=Time.at(@json_object['created_on'].to_i) %>
<%= f.text_field :created_at, :value => display_created_at.to_s+"(Protocols.io value)",readonly: true, class: "form-control" %>
<%= f.text_field :created_at, :value => display_created_at.to_s,
readonly: true, class: "form-control" %>
</div>
<div class="col-xs-4">
<label><%= t("protocols.import_export.import_modal.updated_at_label") %></label>
<% display_last_modified=Time.at(@json_object['last_modified'].to_i) %>
<%= f.text_field :last_modified, :value =>
display_last_modified.to_s+"(Protocols.io value)",readonly: true, class:
display_last_modified.to_s,readonly: true, class:
"form-control" %>
</div>
</div>
@ -119,18 +121,14 @@
<span class="step-panel-collapse-link" data-toggle="collapse">
<span class="glyphicon collapse-step-icon glyphicon-collapse-up"></span>
<% title=nil %>
<% title = nil %>
<% step["components"].each do |key1,value1| #finding section (title of step) %>
<% key1 = value1 if value1.class == Hash %>
<% if(key1["component_type_id"]=="6") %>
<% title = key1["data"] if key1["data"].present? %>
<% end %>
<% end %>
<% if title.nil? %>
<% title =t('protocols.protocols_io_import.comp_append.missing_step') %>
<% end %>
<% title ||=t('protocols.protocols_io_import.comp_append.missing_step') %>
<strong data-val="name"><%= title %></strong>
</span>
</div>
@ -140,7 +138,7 @@
<div class="tab-pane active" role="tabpanel">
<div data-val="description" class="ql-editor">
<% step["components"].each do |key,value| %>
<% step["components"].each do |key,value| %>
<%#here i made an if to distinguish the first step from the
others, because the first step #sometimes has index values as keys instead of
hashes, you might see this elsewhere %>
@ -217,7 +215,7 @@
<% end #inner if%>
<% end #step component loop %>
<% end #step component loop %>
</div>
<hr>

View file

@ -1389,7 +1389,7 @@ en:
preview:
b_s_p: "Before starting protocol information:"
warn: "Protocol warning:"
guideln: "<strong>Guidelines:"
guideln: "Guidelines:"
p_link: "Supplied link:"
s_nobr_link: "Link:"
s_link: "Link:"