Skip to content

Commit

Permalink
progress!
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Sep 8, 2023
1 parent dbe933b commit 434d5f3
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 109 deletions.
Binary file added app/assets/images/es-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/os-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/solr-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ angular.module('QuepidApp')
controller: 'WizardModalCtrl',
backdrop: 'static'
});
console.log("have we completed case wizrd?" + $rootScope.currentUser.completedCaseWizard);

if (!$rootScope.currentUser.completedCaseWizard) {
modalInstance.result.then(function() {
/* global setupAndStartTour */
console.log("about to fire up the tour! have we completed case wizrd?" + $rootScope.currentUser.completedCaseWizard);
$timeout(setupAndStartTour, 1500);
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/controllers/queryParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
angular.module('QuepidApp')
.controller('QueryParamsCtrl', [
'$scope',
'esUrlSvc','caseTryNavSvc',
'esUrlSvc','caseTryNavSvc','searchEndpointSvc',
'TryFactory',
function ($scope,
esUrlSvc, caseTryNavSvc,
esUrlSvc, caseTryNavSvc,searchEndpointSvc,
TryFactory) {

$scope.qp = {};
Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/controllers/wizardCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ angular.module('QuepidApp')

modalInstance.result.then(function() {
/* global setupAndStartTour */
$timeout(setupAndStartTour, 1500);
if (!$rootScope.currentUser.completedCaseWizard) {
$timeout(setupAndStartTour, 1500);
}
});
};

Expand Down
12 changes: 6 additions & 6 deletions app/assets/javascripts/controllers/wizardModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ angular.module('QuepidApp')
}
});

$scope.filterEndpointsByType = function() {
return searchEndpointSvc.filteredEndpoints($scope.pendingWizardSettings.searchEngine);
}
$scope.listSearchEndpoints = function() {
return $scope.searchEndpoints;
}

// used when we first launch the wizard, and it handles reloading from http to https
$scope.updateSettingsDefaults = function() {
Expand All @@ -64,7 +64,7 @@ angular.module('QuepidApp')
$scope.pendingWizardSettings.titleField = settings.titleField;
$scope.pendingWizardSettings.urlFormat = settings.urlFormat;
$scope.pendingWizardSettings.searchEndpointId = null;
$scope.searchEndpoints = searchEndpointSvc.list();
//$scope.searchEndpoints = searchEndpointSvc.list();

var quepidStartsWithHttps = $location.protocol() === 'https';

Expand Down Expand Up @@ -246,8 +246,8 @@ angular.module('QuepidApp')
function validateHeaders () {
$scope.invalidHeaders = false;

if ($scope.pendingWizardSettings.searchEngine !== 'solr'&&
$scope.pendingWizardSettings.customHeaders.length > 0) {
if (
$scope.pendingWizardSettings.customHeaders && $scope.pendingWizardSettings.customHeaders.length > 0) {
try {
JSON.parse($scope.pendingWizardSettings.customHeaders);
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/services/searchEndpointSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ angular.module('QuepidApp')
angular.forEach(response.data.search_endpoints, function(dataSearchEndpoint) {
var searchEndpoint = self.constructFromShallowData(dataSearchEndpoint);

//if(!contains(self.searchEndpoint, search_endpoint)) {
if(!contains(self.searchEndpoints, searchEndpoint)) {
self.searchEndpoints.push(searchEndpoint);
//}
}
});
});
};
Expand Down
76 changes: 47 additions & 29 deletions app/assets/javascripts/services/settingsSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ angular.module('QuepidApp')

this.demoSettingsChosen = function(searchEngine, newUrl){
var useTMDBDemoSettings = false;
if (searchEngine === 'solr'){
if (searchEngine === 'solr'){
if (newUrl === null || angular.isUndefined(newUrl)){
useTMDBDemoSettings = true;
}
Expand Down Expand Up @@ -335,24 +335,32 @@ angular.module('QuepidApp')
// (4) possibly modified curator vars
// probably could be a bit more restful
// Note that we map between camelCase in JS and snake_case in API here.
var sentData = {};

var currCaseNo = caseTryNavSvc.getCaseNo();

var payload = {};
var payloadTry = {};
var payloadSearchEndpoint = {};
payload.try = payloadTry;
payload.search_endpoint = payloadSearchEndpoint;

payload.parent_try_number = settingsToSave.selectedTry.tryNo;
payload.curator_vars = settingsToSave.selectedTry.curatorVarsDict();

// We create the default name on the server side
//sentData.name = settingsToSave.selectedTry.name;
sentData.curator_vars = settingsToSave.selectedTry.curatorVarsDict();
sentData.escape_query = settingsToSave.escapeQuery;
sentData.api_method = settingsToSave.apiMethod;
sentData.custom_headers = settingsToSave.customHeaders;
//sentData.fields = settingsToSave.createFieldSpec().fields;
sentData.field_spec = settingsToSave.fieldSpec;
sentData.number_of_rows = settingsToSave.numberOfRows;
sentData.query_params = settingsToSave.selectedTry.queryParams;
sentData.search_engine = settingsToSave.searchEngine;
sentData.search_url = settingsToSave.searchUrl;
sentData.parent_try_number = settingsToSave.selectedTry.tryNo;

return $http.post('api/cases/' + currCaseNo + '/tries', sentData)
//payloadTry.name = settingsToSave.selectedTry.name;

payloadTry.escape_query = settingsToSave.escapeQuery;
payloadTry.field_spec = settingsToSave.fieldSpec;
payloadTry.number_of_rows = settingsToSave.numberOfRows;
payloadTry.query_params = settingsToSave.selectedTry.queryParams;
payloadSearchEndpoint.search_engine = settingsToSave.searchEngine;
payloadSearchEndpoint.endpoint_url = settingsToSave.searchUrl;
payloadSearchEndpoint.api_method = settingsToSave.apiMethod;
payloadSearchEndpoint.custom_headers = settingsToSave.customHeaders;


return $http.post('api/cases/' + currCaseNo + '/tries', payload)
.then(function(response) {
var tryJson = response.data;
var newTry = currSettings.addTry(tryJson);
Expand Down Expand Up @@ -392,26 +400,36 @@ angular.module('QuepidApp')
// (4) possibly modified curator vars
// probably could be a bit more restful
// Note that we map between camelCase in JS and snake_case in API here.
var sentData = {};
var currCaseNo = caseTryNavSvc.getCaseNo();
var currTryNo = caseTryNavSvc.getTryNo();

// because this is only called at the end of the case creation wizard
// we don't have a sentData.name = settingsToSave.selectedTry.name
// for completeness we should. If we enable more edit of existing try
// tries are odd, cause we pretty much only create new ones!
sentData.curatorVars = settingsToSave.selectedTry.curatorVarsDict();
sentData.escape_query = settingsToSave.escapeQuery;
sentData.api_method = settingsToSave.apiMethod;
sentData.custom_headers = settingsToSave.customHeaders;
sentData.field_spec = settingsToSave.fieldSpec;
sentData.number_of_rows = settingsToSave.numberOfRows;
sentData.query_params = settingsToSave.selectedTry.queryParams;
sentData.search_engine = settingsToSave.searchEngine;
sentData.search_url = settingsToSave.searchUrl;
sentData.parent_try_number = settingsToSave.selectedTry.tryNo;

return $http.put('api/cases/' + currCaseNo + '/tries/' + currTryNo, sentData)

var payload = {};
var payloadTry = {};
var payloadSearchEndpoint = {};
payload.try = payloadTry;
payload.search_endpoint = payloadSearchEndpoint;

payload.parent_try_number = settingsToSave.selectedTry.tryNo;
payload.curator_vars = settingsToSave.selectedTry.curatorVarsDict();

// We create the default name on the server side
//payloadTry.name = settingsToSave.selectedTry.name;

payloadTry.escape_query = settingsToSave.escapeQuery;
payloadTry.field_spec = settingsToSave.fieldSpec;
payloadTry.number_of_rows = settingsToSave.numberOfRows;
payloadTry.query_params = settingsToSave.selectedTry.queryParams;
payloadSearchEndpoint.search_engine = settingsToSave.searchEngine;
payloadSearchEndpoint.endpoint_url = settingsToSave.searchUrl;
payloadSearchEndpoint.api_method = settingsToSave.apiMethod;
payloadSearchEndpoint.custom_headers = settingsToSave.customHeaders;

return $http.put('api/cases/' + currCaseNo + '/tries/' + currTryNo, payload)
.then(function() {

// Broadcast that settings for case have been updated
Expand Down
11 changes: 5 additions & 6 deletions app/assets/templates/views/wizardModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ <h2>Name Your Case!</h2>
<br><br><br><br><br>
</div>
</wz-step>
<wz-step title="Engine" id="step-three">
<h2>Solr, Elasticsearch, or OpenSearch?</h2>
<wz-step title="Endpoint" id="step-three">
<h2>What Search Endpoint do you want to connect to?</h2>
<div>
<uib-accordion>
<div uib-accordion-group class="panel-default" heading="Use an existing Search Endpoint" >
Expand All @@ -36,11 +36,10 @@ <h2>Solr, Elasticsearch, or OpenSearch?</h2>
<select
id="searchEndpoint"
ng-model="pendingWizardSettings.searchEndpointId"
ng-options="searchEndpoint.id as searchEndpoint.name for searchEndpoint in filterEndpointsByType()"
ng-options="searchEndpoint.id as searchEndpoint.name for searchEndpoint in listSearchEndpoints()"
>
<option value="">Create a new Search Endpoint<option>
</select>
SEP:{{pendingWizardSettings.searchEndpointId}}

<button class="btn btn-primary pull-right continue" ng-click="pickSearchEndpoint()" ng-disabled="pendingWizardSettings.searchEndpointId == null">Continue</button>

Expand All @@ -56,11 +55,11 @@ <h2>Solr, Elasticsearch, or OpenSearch?</h2>
</label>
<label style="margin-right: 25px;">
<input type="radio" value="es" ng-model="pendingWizardSettings.searchEngine" ng-change="changeSearchEngine()">
<img ng-src="images/elasticsearch.png" alt='Elasticsearch' width="150px" />
<img ng-src="images/es.png" alt='Elasticsearch' width="150px" />
</label>
<label>
<input type="radio" value="os" ng-model="pendingWizardSettings.searchEngine" ng-change="changeSearchEngine()">
<img ng-src="images/opensearch.png" alt='OpenSearch' width="150px" />
<img ng-src="images/os.png" alt='OpenSearch' width="150px" />
</label>
</div>

Expand Down
63 changes: 36 additions & 27 deletions app/controllers/api/v1/tries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ def show
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def create
parameters_to_use = try_params
try_parameters_to_use = try_params

if params[:parent_try_number] # We need special translation from try_number to the try.id
parameters_to_use[:parent_id] = @case.tries.where(try_number: params[:parent_try_number]).first.id
try_parameters_to_use[:parent_id] = @case.tries.where(try_number: params[:parent_try_number]).first.id
end

@try = @case.tries.build parameters_to_use
@try = @case.tries.build try_parameters_to_use

search_endpoint_params_to_use = search_endpoint_params
puts 'Here are the search_endpoint_params_to_use'
# puts 'Here are the search_endpoint_params_to_use'
# not quite right because it could be via team, needs to be a scope.
search_endpoint_params_to_use['owner_id'] = @case.owner_id
puts search_endpoint_params_to_use
# puts search_endpoint_params_to_use

unless search_endpoint_params_to_use['search_engine'].nil?
search_endpoint = SearchEndpoint.find_or_create_by search_endpoint_params_to_use
search_endpoint = @current_user.search_endpoints_involved_with.find_or_create_by search_endpoint_params_to_use
@try.search_endpoint = search_endpoint
end

Expand Down Expand Up @@ -61,23 +62,30 @@ def create
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize

# rubocop:disable Metrics/MethodLength
def 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}"
search_endpoint_params_to_use = search_endpoint_params
search_endpoint_params_to_use = convert_blank_values_to_nil search_endpoint_params_to_use
unless search_endpoint_params_to_use.empty?
puts 'Here are the params'
puts search_endpoint_params_to_use.except :name
# really hsould be a search_endpoint_id
search_endpoint = @current_user.search_endpoints_involved_with
.find_by search_endpoint_params_to_use.except :name
if search_endpoint.nil?
search_endpoint = SearchEndpoint.create search_endpoint_params_to_use
search_endpoint.owner = @current_user
end
@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
end
end
# rubocop:enable Metrics/MethodLength

def destroy
@try.destroy
Expand All @@ -87,6 +95,16 @@ def destroy

private

def convert_blank_values_to_nil hash
hash.each do |key, value|
if value.is_a?(Hash)
convert_blank_values_to_nil(value) # Recursively call the method for nested hashes
elsif value.blank?
hash[key] = nil
end
end
end

def set_try
# We always refer to a try as a incrementing linear number within the scope of
# a case. We don't use the internal try_id in the API.
Expand All @@ -98,31 +116,22 @@ def set_try
def try_params
params.require(:try).permit(
:escape_query,
# :api_method,
# :custom_headers,
:field_spec,
:name,
:number_of_rows,
:query_params,
# :search_engine,
# :search_url,
:parent_id
:parent_id # need this one?
)
end

def search_endpoint_params
# params_to_return = params.require(:try).permit(
params_to_return = params.permit(
params.require(:search_endpoint).permit(
:name,
:api_method,
:custom_headers,
:search_engine,
:search_url
:endpoint_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
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/search_endpoints_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SearchEndpointsController < ApplicationController
respond_to :html

def index
@search_endpoints = SearchEndpoint.all
@search_endpoints = @current_user.search_endpoints_involved_with
respond_with(@search_endpoints)
end

Expand All @@ -24,6 +24,7 @@ def edit

def create
@search_endpoint = SearchEndpoint.new(search_endpoint_params)
@search_endpoint.owner = @current_user
@search_endpoint.save
respond_with(@search_endpoint)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/search_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SearchEndpoint < ApplicationRecord
}

scope :for_user, ->(user) {
ids = for_user_via_teams(user).pluck(:id) + for_user_directly_owned(user).pluck(:id)
ids = for_user_via_teams(user).distinct.pluck(:id) + for_user_directly_owned(user).distinct.pluck(:id)
where(id: ids.uniq)
}

Expand Down
12 changes: 9 additions & 3 deletions app/views/api/v1/tries/_try.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# frozen_string_literal: true

json.args try.args
json.custom_headers try.search_endpoint&.custom_headers
json.curator_vars try.curator_vars_map
json.escape_query try.escape_query
json.api_method try.search_endpoint&.api_method
json.field_spec try.field_spec
json.name try.name
json.number_of_rows try.number_of_rows
json.query_params try.query_params
json.search_endpoint_id try.search_endpoint&.id
json.endpoint_name try.search_endpoint&.fullname
json.custom_headers try.search_endpoint&.custom_headers
json.api_method try.search_endpoint&.api_method
json.search_engine try.search_endpoint&.search_engine
json.search_url try.search_endpoint&.endpoint_url
json.try_number try.try_number
json.endpoint_name try.search_endpoint&.fullname
if try.search_endpoint.present?
json.search_endpoint do
json.partial! 'api/v1/search_endpoints/search_endpoint', search_endpoint: try.search_endpoint
end
end
Loading

0 comments on commit 434d5f3

Please sign in to comment.