Skip to content

Commit

Permalink
fix ups
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Aug 21, 2023
1 parent 9157925 commit 7c49352
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
12 changes: 9 additions & 3 deletions app/assets/javascripts/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ angular.module('QuepidApp')
var reset = function() {
var currSettings = settingsSvc.editableSettings();
if ( this.searchEngine !== currSettings.searchEngine) {
console.log("Location A");
currSettings = settingsSvc.pickSettingsToUse($scope.pendingSettings.searchEngine, null);
currSettings.fieldSpec = currSettings.fieldSpec + ', ' + currSettings.additionalFields.join(', ');
$scope.pendingSettings.urlFormat = currSettings.urlFormat;
Expand Down Expand Up @@ -56,13 +57,18 @@ angular.module('QuepidApp')
$scope.pendingSettings = settingsSvc.editableSettings();
$scope.pendingSettings.reset = reset;

if ( angular.isDefined($scope.pendingSettings.searchEngine) ) {
//if ( angular.isDefined($scope.pendingSettings.searchEngine) ) {
if ( angular.isDefined($scope.pendingSettings.searchEngine) && $scope.pendingSettings.searchEngine !== null ) {
console.log("In settings, search engine is " + $scope.pendingSettings.searchEngine );
console.log("In settings, search url is " + $scope.pendingSettings.searchUrl );
var settingsToUse = settingsSvc.pickSettingsToUse($scope.pendingSettings.searchEngine, $scope.pendingSettings.searchUrl);
$scope.pendingSettings.urlFormat = settingsToUse.urlFormat;

// pass pending settings onward to be saved
$scope.pendingSettings.submit = submit;
}

// pass pending settings onward to be saved
$scope.pendingSettings.submit = submit;

});

function submit () {
Expand Down
23 changes: 17 additions & 6 deletions app/controllers/api/v1/tries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ def create
# rubocop:enable Metrics/AbcSize

def update
try_update = @try.update try_params
search_endpoint_update = @try.search_endpoint.update search_endpoint_params
if try_update && search_endpoint_update
puts "About to look up search end point for #{search_endpoint_params}"
puts "Is it empty? #{search_endpoint_params.empty?}"
#
# if (search_endpoint_params['endpoint_url'] )
unless search_endpoint_params.empty?
search_endpoint = SearchEndpoint.find_or_create_by search_endpoint_params
puts "Found search end point with id #{search_endpoint.id} and name #{search_endpoint.fullname}"
@try.search_endpoint = search_endpoint
end
# search_endpoint_update =
if @try.update try_params
respond_with @try
else
render json: @try.errors, status: :bad_request
Expand Down Expand Up @@ -103,14 +111,17 @@ def try_params
end

def search_endpoint_params
params_to_return = params.require(:try).permit(
# params_to_return = params.require(:try).permit(
params_to_return = params.permit(
:api_method,
:custom_headers,
:search_engine,
:search_url
)
# map from the old name to the new name
params_to_return['endpoint_url'] = params_to_return.delete 'search_url'
if params_to_return.key? 'search_url'
# map from the old name to the new name
params_to_return['endpoint_url'] = params_to_return.delete 'search_url'
end
params_to_return
end
end
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/core_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ def populate_from_params
if @try.present?
# Deal with front end UI changes to search engine being stored in backend
if params[:searchEngine].present?
# Reset the default queries
@try.search_engine = params[:searchEngine] if @try.search_engine != params[:searchEngine]
@try.search_url = params[:searchUrl]
@try.api_method = params[:apiMethod]

search_endpoint_params = {
search_engine: params[:searchEngine],
endpoint_url: params[:searchUrl],
api_method: params[:apiMethod]

}
search_endpoint = SearchEndpoint.find_or_create_by search_endpoint_params
puts "Found search end point with id #{search_endpoint.id} and name #{search_endpoint.fullname}"
@try.search_endpoint = search_endpoint
@try.field_spec = params[:fieldSpec]
end
@try.save
Expand Down

0 comments on commit 7c49352

Please sign in to comment.