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

KG - Related Service Search Display Bug and Optimization #1714

Merged
merged 3 commits into from
Feb 14, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 16 additions & 7 deletions app/assets/javascripts/catalog_manager/catalog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,19 @@ window.initialize_related_services_search = () ->
source: services_bloodhound,
limit: 100,
templates: {
suggestion: Handlebars.compile('<button class="text-left">
<strong><span class="text-service">Service</span><span>: {{name}}</span></strong><br>
{{{breadcrumb}}}<br>
<span>{{cpt_code}}</span><br>
suggestion: Handlebars.compile('<button class="service text-left" data-container="body" data-placement="right" data-toggle="tooltip" data-animation="false" data-html="true" title="{{description}}">
<h5 class="service-name col-sm-12 no-padding no-margin"><span class="text-service">Service</span><span>: {{label}}</span></h5>
<span class="col-sm-12 no-padding">{{{breadcrumb}}}</span>
<span class="col-sm-12 no-padding"><strong>Abbreviation:</strong> {{abbreviation}}</span>
{{#if cpt_code_text}}
{{{cpt_code_text}}}
{{/if}}
{{#if eap_id_text}}
{{{eap_id_text}}}
{{/if}}
{{#if pricing_text}}
{{{pricing_text}}}
{{/if}}
</button>')
notFound: '<div class="tt-suggestion">No Results</div>'
}
Expand All @@ -290,14 +299,14 @@ window.initialize_related_services_search = () ->
existing_services = $("[id*='service-relation-id-']").map ->
return $(this).data('related-service-id')

if suggestion['id'] in existing_services
$('#new_related_services_search').parent().prepend("<div class='alert alert-danger alert-dismissable'>#{suggestion['name']} #{I18n['catalog_manager']['related_services_form']['service_in_list']}</div>")
if suggestion.value in existing_services
$('#new_related_services_search').parent().prepend("<div class='alert alert-danger alert-dismissable'>#{suggestion.label} #{I18n['catalog_manager']['related_services_form']['service_in_list']}</div>")
$('.alert-dismissable').delay(3000).fadeOut()
else
$.ajax
type: 'post'
url: '/catalog_manager/services/add_related_service'
data:
service_id: $(this).data('service-id')
related_service_id: suggestion.id
related_service_id: suggestion.value
);
5 changes: 3 additions & 2 deletions app/controllers/catalog_manager/app_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# named AppController because Devise was having problems when it was named the same as the main ApplicationController
class CatalogManager::AppController < ActionController::Base
class CatalogManager::AppController < ApplicationController
layout 'catalog_manager/application'

protect_from_forgery

helper_method :current_user

before_action :authenticate_identity!
before_action :set_user
before_action :set_highlighted_link
before_action :check_access_rights

def set_highlighted_link
Expand Down
18 changes: 13 additions & 5 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,24 @@ class SearchController < ApplicationController

def services_search
term = params[:term].strip
results = Service.where("is_available=1 AND (name LIKE '%#{term}%' OR abbreviation LIKE '%#{term}%' OR cpt_code LIKE '%#{term}%')").to_a
results = Service.
eager_load(:pricing_maps, organization: [:pricing_setups, parent: [:pricing_setups, parent: [:pricing_setups, :parent]]]).
where("(services.name LIKE ? OR services.abbreviation LIKE ? OR services.cpt_code LIKE ? OR services.eap_id LIKE ?) AND services.is_available = 1", "%#{term}%", "%#{term}%", "%#{term}%", "%#{term}%").to_a

results.map!{ |service|
{
name: service.name,
id: service.id,
cpt_code: cpt_code_text(service),
breadcrumb: breadcrumb_text(service)
breadcrumb: breadcrumb_text(service),
label: service.name,
value: service.id,
description: raw(service.description),
abbreviation: service.abbreviation,
cpt_code_text: cpt_code_text(service),
eap_id_text: eap_id_text(service),
pricing_text: service_pricing_text(service),
term: term
}
}

render json: results.to_json
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
fake_login_for_each_test

before :each do
@institution = create(:institution)
@provider = create(:provider, parent: @institution)
@program = create(:program, parent: @provider)
@service = create(:service, organization: @program)
@rel_serv = create(:service, organization: @program)
@institution = create(:institution, :with_pricing_setup)
@provider = create(:provider, :with_pricing_setup, parent: @institution)
@program = create(:program, :with_pricing_setup, parent: @provider)
@service = create(:service, :with_pricing_map, organization: @program)
@rel_serv = create(:service, :with_pricing_map, organization: @program)
create(:catalog_manager, organization: @institution, identity: jug2)

visit catalog_manager_catalog_index_path
Expand Down