Skip to content

Commit

Permalink
better description handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jambun committed Jun 16, 2024
1 parent 7fcf0e0 commit bbad1dc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
14 changes: 13 additions & 1 deletion backend/model/reftracker_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class RefTrackerClient
end


def self.strip_markup(text)
Nokogiri::XML.fragment(Nokogiri::XML.fragment(text).text.gsub('&', '&')).text
end


def self.get_question(question_no)
resp = ASUtils.json_parse(self.get('getQuestion', {:parameters => {:key => 'question_no', :value => question_no, :format => 'json'}.to_json}))

Expand All @@ -21,7 +26,7 @@ def self.get_question(question_no)
end

# decode and strip markup - phewee - reftracker is not being friendly here
Hash[resp.map {|k, v| [k, Nokogiri::XML.fragment(Nokogiri::XML.fragment(v).text.gsub('&', '&')).text]}]
Hash[resp.map {|k, v| [k, strip_markup(v)]}]
end


Expand Down Expand Up @@ -74,6 +79,13 @@ def self.manuscript_offers(page = 1)

# then filter out the found ids, and any offers without an id
offers.select{|offer| !offer['bib_udf_tb03'].empty? && !found_ids.include?(offer['bib_udf_tb03'])}
.map do |offer|
offer['question_text_stripped'] = strip_markup(offer['question_text'])
if offer['question_text_stripped'].length > 400
offer['short_description'] = offer['question_text_stripped'][0..400]
end
offer
end
end


Expand Down
4 changes: 4 additions & 0 deletions frontend/assets/reftracker_offers.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
.rto-td {
vertical-align: middle !important;
}

.rto-full-description-pane {
display: none;
}
16 changes: 15 additions & 1 deletion frontend/views/reftracker_offers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@
<%= offer['bib_title'].html_safe %>
</td>
<td class="rto-td">
<%= offer['question_text'].html_safe %>
<% if offer['short_description'] %>
<%= offer['short_description'].html_safe %>
...
<a class="pull-right btn btn-sm btn-default rto-more-btn" onclick="reftrackerMoreButtonClick(this);">View full description</a>
<div data-offer="<%= offer['question_no'] %>" class="rto-full-description-pane">
<%= offer['question_text'].html_safe %>
</div>
<% else %>
<%= offer['question_text_stripped'].html_safe %>
<% end %>
</td>
</tr>
<% end %>
Expand Down Expand Up @@ -110,5 +119,10 @@
$('#rto-submit').prop('disabled', true);
}
};

var reftrackerMoreButtonClick = function(btn) {
var fullDesc = btn.nextElementSibling;
AS.openQuickModal(fullDesc.dataset.offer + ' full description', fullDesc.innerText);
};
</script>

0 comments on commit bbad1dc

Please sign in to comment.