Skip to content

Commit

Permalink
dm-4213 fix practice card images (#715)
Browse files Browse the repository at this point in the history
* edit practice search js

logic handling identifying placeholder images and calling replace function is now its own function `replaceImagePlaceholders`

* add js include tag for 'shared/_signed_resource' to crh show

* add call for new `replaceImagePlaceholders` function in crh show js

* update `.dm-practice-card-img-container` height

* edit visn show view to utilize `replaceImagePlaceholders` function

with new changes to practice card images it is necessary to use the function to replace placeholder background with s3 images
  • Loading branch information
PhilipDeFraties authored Oct 12, 2023
1 parent 262f0a3 commit fbe56db
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/dm/components/_practice_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
}

.dm-practice-card-img-container {
height: 165px;
min-width: 100%;
height: auto;
display: flex;
justify-content: center;
align-items: center;
Expand Down
1 change: 1 addition & 0 deletions app/views/clinical_resource_hubs/_crh_show.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function searchPracticesByCrh() {
moreText: 'Load more',
noMoreText: 'No more results'
});
replaceImagePlaceholders('#search-results .dm-practice-card');
}
// Search practices and populate the page
function search(query, category, radioVal) {
Expand Down
1 change: 1 addition & 0 deletions app/views/clinical_resource_hubs/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<% provide :head_tags do %>
<%= javascript_include_tag '_practice_card_utilities', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'shared/_signed_resource', 'data-turbolinks-track': 'false', defer: true %>
<%= javascript_tag 'data-turbolinks-track': 'reload' do %>

<%= render partial: 'crh_show', formats: [:js] %>
Expand Down
31 changes: 17 additions & 14 deletions app/views/practices/_search.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ function buildPracticeCard(result) {
return cardHtml;
}

function replaceImagePlaceholders(parentSelector) {
$(parentSelector).each(function() {
// If either the 'src' or the hidden input are undefined, return an empty string
var imageSelector = $(this).find('.practice-card-img-placeholder');
var imagePracticeId = imageSelector ? imageSelector.attr('data-practice-id') : null;
var practiceImagePath = imageSelector ? imageSelector.attr('data-practice-image') : null;
var practiceName = $(this).find('.dm-practice-title').text();

if (imagePracticeId && practiceImagePath) {
fetchSignedResource(practiceImagePath).then(signedImgUrl => {
replacePlaceholderWithImage(signedImgUrl, imagePracticeId, practiceName);
});
}
});
}

function replacePlaceholderWithImage(imageUrl, practiceId, practiceName) {
loadImage(imageUrl, function(loadedImageSrc) {
var imgTag =
Expand Down Expand Up @@ -279,20 +295,7 @@ function searchPracticesPage() {
// Print results to the page
document.querySelector('#search-results').innerHTML = finalResults;
// After the html for the card has been built and applied to the DOM, replace the image 'src' based on the signed url
$('#search-results .dm-practice-card').each(function() {
// If either the 'src' or the hidden input are undefined, return an empty string
var imageSelector = $(this).find('.practice-card-img-placeholder');
var imagePracticeId = imageSelector ? imageSelector.attr('data-practice-id') : null;
var practiceImagePath = imageSelector ? imageSelector.attr('data-practice-image') : null;
var practiceName = $(this).find('.dm-practice-title').text();
if (imagePracticeId && practiceImagePath) {
fetchSignedResource(
practiceImagePath,
).then(signedImgUrl => {
replacePlaceholderWithImage(signedImgUrl, imagePracticeId, practiceName)
});
}
});
replaceImagePlaceholders('#search-results .dm-practice-card');

$(SEARCH_RESULTS).showMoreItems({
startNum: 12,
Expand Down
3 changes: 2 additions & 1 deletion app/views/visns/_show.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ function searchPracticesByVisn() {
$(SEARCH_RESULTS).removeClass('display-none');
// Print results to the page
document.querySelector('#search-results').innerHTML = finalResults;

$(SEARCH_RESULTS).showMoreItems({
startNum: 6,
afterNum: 6,
moreText: 'Load more',
noMoreText: 'No more results'
});
replaceImagePlaceholders('#search-results .dm-practice-card');
}
// Search practices and populate the page
function search(query, category, radioVal) {
Expand Down
1 change: 1 addition & 0 deletions app/views/visns/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<% provide :footer_classes, 'bg-gray-2' %>
<% provide :head_tags do %>
<%= javascript_include_tag '_practice_card_utilities', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'shared/_signed_resource', 'data-turbolinks-track': 'false', defer: true %>
<%= javascript_tag 'data-turbolinks-track': 'reload' do %>
<%= render partial: 'show', formats: [:js] %>
<%# set visnNumber before loading the visns/show file %>
Expand Down

0 comments on commit fbe56db

Please sign in to comment.