Skip to content

Commit

Permalink
Fix links and clean up helpers in show obs specimen stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Mar 18, 2024
1 parent d605d92 commit 2f0120a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 42 deletions.
6 changes: 3 additions & 3 deletions app/helpers/tabs/collection_numbers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def collection_numbers_index_tab(c_n)
end

def show_collection_number_tab(c_n, obs)
# This is passed in to show_collection_number, allowing users to do prev,
# next and index from there to navigate through all the rest for this obs.
cn_query = Query.lookup(:CollectionNumber, :all, observations: obs.id)
q_id = cn_query.id&.alphabetize

[tag.i(c_n.format_name.t),
collection_number_path(id: c_n.id, q: q_id),
[tag.i(c_n.format_name.t), add_query_param(c_n.show_link_args, cn_query),
{ class: "#{tab_id(__method__.to_s)}_#{c_n.id}" }]
end

Expand Down
14 changes: 9 additions & 5 deletions app/helpers/tabs/herbarium_records_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def herbarium_records_index_tabs(obs:)
if obs.present?
links = [
object_return_tab(obs),
new_herbarium_record_tab
new_herbarium_record_tab(obs)
]
end
links << new_herbarium_tab
Expand Down Expand Up @@ -67,15 +67,19 @@ def herbarium_record_form_edit_tabs(back:, back_object:)
links << nonpersonal_herbaria_index_tab
end

def show_herbarium_record_tab(h_r)
def show_herbarium_record_tab(h_r, obs)
# This is passed in to show_herbarium_record, allowing users to do prev,
# next and index from there to navigate through all the rest for this obs.
hr_query = Query.lookup(:HerbariumRecord, :all, observations: obs.id)

[h_r.accession_at_herbarium.t,
herbarium_record_path(id: h_r.id, q: get_query_param),
add_query_param(h_r.show_link_args, hr_query),
{ class: "#{tab_id(__method__.to_s)}_#{h_r.id}" }]
end

def new_herbarium_record_tab
def new_herbarium_record_tab(obs)
[:create_herbarium_record.l,
new_herbarium_record_path(observation_id: params[:id]),
add_query_param(new_herbarium_record_path(observation_id: obs.id)),
{ class: tab_id(__method__.to_s), icon: :add }]
end

Expand Down
25 changes: 25 additions & 0 deletions app/helpers/tabs/sequences_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ def sequence_form_tabs(obj:)
[object_return_tab(obj)]
end

def show_sequence_tab(seq, obs)
# This is passed in to show_sequence, allowing users to do prev,
# next and index from there to navigate through all the rest for this obs.
sq_query = Query.lookup(:Sequence, :all, observations: obs.id)
locus = seq.locus.truncate(seq.locus_width)
txt = if seq.deposit?
"#{locus} - #{seq.archive} ##{seq.accession}"
else
"#{locus} - MO ##{seq.id}"
end

[txt.t, add_query_param(seq.show_link_args, sq_query),
{ class: "#{tab_id(__method__.to_s)}_#{seq.id}" }]
end

def sequence_archive_tab(seq)
[:show_observation_archive_link.t, seq.accession_url,
{ class: "#{tab_id(__method__.to_s)}_#{seq.id}", target: "_blank" }]
end

def sequence_blast_tab(seq)
[:show_observation_blast_link.t, seq.blast_url,
{ class: "#{tab_id(__method__.to_s)}_#{seq.id}", target: "_blank" }]
end

def sequence_mod_tabs(seq)
[edit_sequence_and_back_tab(seq),
destroy_sequence_tab(seq)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<%
numbers = obs.collection_numbers
can_edit = in_admin_mode? || obs.can_edit?
obs_id = obs.id
# This is passed in to show_collection_number, allowing users to do prev,
# next and index from there to navigate through all the rest for this obs.
# cn_query = Query.lookup(:CollectionNumber, :all, observations: obs.id)
%>
<%=
Expand Down
14 changes: 6 additions & 8 deletions app/views/controllers/observations/show/_herbarium_records.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
records = obs.herbarium_records
can_add = in_admin_mode? || obs.can_edit? ||
@user && @user.curated_herbaria.any?
obs_id = obs.id
# This is passed in to show_herbarium_record, allowing users to do prev,
# next and index from there to navigate through all the rest for this obs.
query = Query.lookup(:HerbariumRecord, :all, observations: obs.id)
%>
<%=
Expand All @@ -25,15 +21,16 @@ unless @user.try(&:hide_specimen_stuff?) || obs.user.try(&:hide_specimen_stuff?)
"#{:Herbarium_records.t}:",
[ # any html helper has to be safe_joined separately
"[",
modal_link_to("herbarium_record", *new_herbarium_record_tab),
modal_link_to("herbarium_record",
*new_herbarium_record_tab(obs)),
"]"
].safe_join
].safe_join(" ")
end,
tag.ul(class: "tight-list") do
records.map do |record|
tag.li(id: "herbarium_record_#{record.id}") do
concat(link_to(*show_herbarium_record_tab(record)))
concat(link_to(*show_herbarium_record_tab(record, obs)))
if record.can_edit? || in_admin_mode?
concat(
[
Expand All @@ -60,7 +57,7 @@ unless @user.try(&:hide_specimen_stuff?) || obs.user.try(&:hide_specimen_stuff?)
end,
tag.ul(class: "tight-list") do
records.map do |record|
tag.li { link_to(*show_herbarium_record_tab(record)) }
tag.li { link_to(*show_herbarium_record_tab(record, obs)) }
end.safe_join
end
].safe_join(" ")
Expand All @@ -69,7 +66,8 @@ unless @user.try(&:hide_specimen_stuff?) || obs.user.try(&:hide_specimen_stuff?)
[
:show_observation_no_herbarium_records.t,
" [",
modal_link_to("herbarium_record", *new_herbarium_record_tab),
modal_link_to("herbarium_record",
*new_herbarium_record_tab(obs)),
"]"
].safe_join
end
Expand Down
25 changes: 3 additions & 22 deletions app/views/controllers/observations/show/_sequences.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<%
sequences = obs.sequences
can_edit = in_admin_mode? || obs.can_edit?

# This is passed in to show_sequence, allowing users to do prev,
# next and index from there to navigate through all the rest for this obs.
query = Query.lookup(:Sequence, :all, observations: obs.id)
%>
<% unless @user.try(&:hide_specimen_stuff?) ||
Expand All @@ -28,25 +24,11 @@ query = Query.lookup(:Sequence, :all, observations: obs.id)
concat(tag.ul(class:"tight-list") do
sequences.each do |sequence|
concat(tag.li(id: "sequence_#{sequence.id}") do
locus = sequence.locus.truncate(sequence.locus_width)
if sequence.deposit?
concat(link_to(
"#{locus} - #{sequence.archive} ##{sequence.accession}".t,
add_query_param(sequence.show_link_args, query),
class: "show_sequence_link_#{sequence.id}"
))
else
concat(link_to(
"#{locus} - MO ##{sequence.id}".t,
add_query_param(sequence.show_link_args, query),
class: "show_sequence_link_#{sequence.id}"
))
end
concat(link_to(*show_sequence_tab(sequence, obs)))

links = []
if sequence.deposit?
links << link_to(:show_observation_archive_link.t,
sequence.accession_url, target: "_blank")
links << link_to(*sequence_archive_tab(sequence))
end
if in_admin_mode? || sequence.can_edit?(@user)
links << modal_link_to(
Expand All @@ -61,8 +43,7 @@ query = Query.lookup(:Sequence, :all, observations: obs.id)
)
end
if sequence.blastable?
links << link_to(:show_observation_blast_link.t,
sequence.blast_url, target: "_blank")
links << link_to(*sequence_blast_tab(sequence))
end
concat(" [#{links.safe_join(' | ')}]".html_safe) if links.any?
end)
Expand Down

0 comments on commit 2f0120a

Please sign in to comment.