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

Rethink how we handle TMDB Demo case settings for various engines #582

Merged
merged 10 commits into from
Nov 22, 2022
Merged
48 changes: 26 additions & 22 deletions app/assets/javascripts/controllers/queryParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,37 @@ angular.module('QuepidApp')
$scope.showTLSChangeWarning = false;

$scope.validateSearchEngineUrl = function() {
if ($scope.settings.searchEngine === 'es' || $scope.settings.searchEngine === 'os'){
var uri = esUrlSvc.parseUrl($scope.settings.searchUrl);
$scope.showESTemplateWarning = esUrlSvc.isTemplateCall(uri);
}

if ($scope.settings.searchEngine !== ''){
// Figure out if we need to redirect based on our search engine's url.
var quepidStartsWithHttps = $location.protocol() === 'https';
var searchEngineStartsWithHttps = $scope.settings.searchUrl.startsWith('https');

if ((quepidStartsWithHttps.toString() === searchEngineStartsWithHttps.toString())){
$scope.showTLSChangeWarning = false;
if (!angular.isUndefined($scope.settings.searchUrl)){
if ($scope.settings.searchEngine === 'es' || $scope.settings.searchEngine === 'os'){
var uri = esUrlSvc.parseUrl($scope.settings.searchUrl);
$scope.showESTemplateWarning = esUrlSvc.isTemplateCall(uri);
}
else {
$scope.showTLSChangeWarning = true;
$scope.quepidUrlToSwitchTo = $location.protocol() + '://' + $location.host() + $location.path();

$scope.quepidUrlToSwitchTo = $scope.quepidUrlToSwitchTo + '?searchEngine=' + $scope.settings.searchEngine + '&searchUrl=' + $scope.settings.searchUrl + '&showWizard=false&apiMethod=' + $scope.settings.apiMethod;

if ($scope.settings.searchEngine !== '' && !angular.isUndefined($scope.settings.searchUrl)){
// Figure out if we need to redirect based on our search engine's url.
var quepidStartsWithHttps = $location.protocol() === 'https';
var searchEngineStartsWithHttps = $scope.settings.searchUrl.startsWith('https');

if (searchEngineStartsWithHttps){
$scope.protocolToSwitchTo = 'https';
$scope.quepidUrlToSwitchTo = $scope.quepidUrlToSwitchTo.replace('http', 'https');
if ((quepidStartsWithHttps.toString() === searchEngineStartsWithHttps.toString())){
$scope.showTLSChangeWarning = false;
}
else {
$scope.protocolToSwitchTo = 'http';
$scope.quepidUrlToSwitchTo = $scope.quepidUrlToSwitchTo.replace('https', 'http');
$scope.showTLSChangeWarning = true;
$scope.quepidUrlToSwitchTo = $location.protocol() + '://' + $location.host() + $location.path();

$scope.quepidUrlToSwitchTo = $scope.quepidUrlToSwitchTo + '?searchEngine=' + $scope.settings.searchEngine + '&searchUrl=' + $scope.settings.searchUrl + '&showWizard=false&apiMethod=' + $scope.settings.apiMethod;
$scope.quepidUrlToSwitchTo = $scope.quepidUrlToSwitchTo + '&fieldSpec=' + $scope.settings.fieldSpec;



if (searchEngineStartsWithHttps){
$scope.protocolToSwitchTo = 'https';
$scope.quepidUrlToSwitchTo = $scope.quepidUrlToSwitchTo.replace('http', 'https');
}
else {
$scope.protocolToSwitchTo = 'http';
$scope.quepidUrlToSwitchTo = $scope.quepidUrlToSwitchTo.replace('https', 'http');
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions app/assets/javascripts/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ angular.module('QuepidApp')
var reset = function() {
var currSettings = settingsSvc.editableSettings();
if ( this.searchEngine !== currSettings.searchEngine) {
currSettings = settingsSvc.defaults[$scope.pendingSettings.searchEngine];
currSettings = settingsSvc.pickSettingsToUse($scope.pendingSettings.searchEngine, null);
currSettings.fieldSpec = currSettings.fieldSpec + ', ' + currSettings.additionalFields.join(', ');
$scope.pendingSettings.urlFormat = currSettings.urlFormat;
}
this.searchEngine = currSettings.searchEngine;
this.apiMethod = currSettings.apiMethod;
Expand Down Expand Up @@ -55,10 +57,11 @@ angular.module('QuepidApp')
$scope.pendingSettings.reset = reset;

if ( angular.isDefined($scope.pendingSettings.searchEngine) ) {
$scope.pendingSettings.urlFormat = settingsSvc.defaults[$scope.pendingSettings.searchEngine].urlFormat;
var settingsToUse = settingsSvc.pickSettingsToUse($scope.pendingSettings.searchEngine, $scope.pendingSettings.searchUrl);
$scope.pendingSettings.urlFormat = settingsToUse.urlFormat;
}

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

Expand Down
92 changes: 64 additions & 28 deletions app/assets/javascripts/controllers/wizardModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,51 @@ angular.module('QuepidApp')
return settingsSvc.settingsId();
};

// used when you swap radio buttons for the search engine.
$scope.changeSearchEngine = function() {

if (angular.isUndefined($scope.pendingWizardSettings)){
// When we run the case wizard, we assume that you want to use our Solr based TMDB demo setup.
// We then give you options to change from there.
$scope.pendingWizardSettings = angular.copy(settingsSvc.tmdbSettings['solr']);
}
var settings = settingsSvc.pickSettingsToUse($scope.pendingWizardSettings.searchEngine, $scope.pendingWizardSettings.searchUrl);
$scope.pendingWizardSettings.additionalFields = settings.additionalFields;
$scope.pendingWizardSettings.fieldSpec = settings.fieldSpec;
$scope.pendingWizardSettings.idField = settings.idField;
$scope.pendingWizardSettings.searchEngine = settings.searchEngine;
$scope.pendingWizardSettings.apiMethod = settings.apiMethod;
$scope.pendingWizardSettings.customHeaders = settings.customHeaders;
$scope.pendingWizardSettings.queryParams = settings.queryParams;
$scope.pendingWizardSettings.titleField = settings.titleField;
$scope.pendingWizardSettings.urlFormat = settings.urlFormat;

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

if ($scope.pendingWizardSettings.searchEngine === 'solr') {
if (quepidStartsWithHttps === true){
$scope.pendingWizardSettings.searchUrl = settings.secureSearchUrl;
}
else {
$scope.pendingWizardSettings.searchUrl = settings.insecureSearchUrl;
}
}
else {
$scope.pendingWizardSettings.searchUrl = settings.searchUrl;
}

$scope.reset();
};

// used when we first launch the wizard, and it handles reloading from http to https
$scope.updateSettingsDefaults = function() {

if (angular.isUndefined($scope.pendingWizardSettings)){
$scope.pendingWizardSettings = angular.copy(settingsSvc.defaults['solr']);
// When we run the case wizard, we assume that you want to use our Solr based TMDB demo setup.
// We then give you options to change from there.
$scope.pendingWizardSettings = angular.copy(settingsSvc.tmdbSettings['solr']);
}
var settings = angular.copy(settingsSvc.defaults[$scope.pendingWizardSettings.searchEngine]);
var settings = settingsSvc.pickSettingsToUse($scope.pendingWizardSettings.searchEngine, $scope.pendingWizardSettings.searchUrl);
$scope.pendingWizardSettings.additionalFields = settings.additionalFields;
$scope.pendingWizardSettings.fieldSpec = settings.fieldSpec;
$scope.pendingWizardSettings.idField = settings.idField;
Expand Down Expand Up @@ -56,7 +95,7 @@ angular.module('QuepidApp')
// We should pass this stuff in externally, not do it here.
if (angular.isDefined($location.search().searchEngine)){
$scope.pendingWizardSettings.searchEngine = $location.search().searchEngine;
$scope.pendingWizardSettings.queryParams = settingsSvc.defaults[$scope.pendingWizardSettings.searchEngine].queryParams;
// $scope.pendingWizardSettings.queryParams = settingsSvc.defaults[$scope.pendingWizardSettings.searchEngine].queryParams;
}
if (angular.isDefined($location.search().searchUrl)){
$scope.pendingWizardSettings.searchUrl = $location.search().searchUrl;
Expand Down Expand Up @@ -91,7 +130,11 @@ angular.module('QuepidApp')
function reset() {
$scope.validating = false;
$scope.urlValid = $scope.urlInvalid = $scope.invalidHeaders = false;
$scope.checkTLSForSearchEngineUrl();
//$scope.pendingWizardSettings = angular.copy(settingsSvc.tmdbSettings['solr']);
// when you reset back to Solr, we actually don't have a url due to a glitch in picking the right one, sigh.
if ($scope.pendingWizardSettings.searchUrl){
$scope.checkTLSForSearchEngineUrl();
}
}

function resetUrlValid() {
Expand Down Expand Up @@ -190,6 +233,7 @@ angular.module('QuepidApp')
}
}


function setupDefaults(validator) {
$scope.validating = false;
$scope.urlValid = true;
Expand All @@ -199,33 +243,18 @@ angular.module('QuepidApp')
// Since the defaults are being overridden by the editableSettings(),
// make sure the default id, title, and additional fields are set
// if the URL is still set as the default

var searchEngine = $scope.pendingWizardSettings.searchEngine;
var defaults = settingsSvc.defaults[searchEngine];
var newUrl = $scope.pendingWizardSettings.searchUrl;
var useDefaultSettings = false;
if ($scope.pendingWizardSettings.searchEngine === 'solr'){
if (newUrl === defaults.insecureSearchUrl || newUrl === defaults.secureSearchUrl ){
useDefaultSettings = true;
}
}
else {
if (newUrl === defaults.searchUrl) {
useDefaultSettings = true;
}
}

if ( useDefaultSettings ) {
$scope.pendingWizardSettings.idField = defaults.idField;
$scope.pendingWizardSettings.titleField = defaults.titleField;
$scope.pendingWizardSettings.additionalFields = defaults.additionalFields;
} else {
$scope.pendingWizardSettings.idField = '';
if (searchEngine === 'es' || searchEngine === 'os') {
$scope.pendingWizardSettings.idField = '_id';
}
$scope.pendingWizardSettings.titleField = '';
$scope.pendingWizardSettings.additionalFields = '';
}
var settingsToUse = settingsSvc.pickSettingsToUse(searchEngine, newUrl);

$scope.pendingWizardSettings.idField = settingsToUse.idField;
$scope.pendingWizardSettings.titleField = settingsToUse.titleField;
$scope.pendingWizardSettings.additionalFields = settingsToUse.additionalFields;
$scope.pendingWizardSettings.queryParams = settingsToUse.queryParams;
$scope.pendingWizardSettings.apiMethod = settingsToUse.apiMethod;

}

$scope.validateFieldSpec = validateFieldSpec;
Expand Down Expand Up @@ -364,6 +393,13 @@ angular.module('QuepidApp')
$scope.pendingWizardSettings.submit = function() {
$log.debug('Submitting settings (from wizard modal)');

// if we aren't using a demo, then lets finalize our queryParams with our title field.
if (!settingsSvc.demoSettingsChosen($scope.pendingWizardSettings.searchEngine, $scope.pendingWizardSettings.searchUrl)){
if ($scope.pendingWizardSettings.searchEngine === 'os' || $scope.pendingWizardSettings.searchEngine === 'es'){
$scope.pendingWizardSettings.queryParams = $scope.pendingWizardSettings.queryParams.replace('REPLACE_ME', $scope.pendingWizardSettings.titleField);
}
}

settingsSvc.update($scope.pendingWizardSettings)
.then(function() {
var latestSettings = settingsSvc.editableSettings();
Expand Down
122 changes: 120 additions & 2 deletions app/assets/javascripts/services/settingsSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,94 @@ angular.module('QuepidApp')
broadcastSvc
) {

// Used by the wizard
this.defaults = {
/* jshint ignore:start */
// Used by the wizard for any search engine.
this.defaultSettings = {
solr: {
queryParams: [
'q=#$query##',
'&tie=1.0',
].join('\n'),

escapeQuery: true,
customHeaders: '',
headerType: 'None',
apiMethod: 'JSONP',
fieldSpec: 'id:id',
idField: 'id',
titleField: '',
additionalFields: [],
numberOfRows: 10,
searchEngine: 'solr',
// perfect world we wouldn't have this here and we would instead populate with urlFormat instead.
insecureSearchUrl:'http://quepid-solr.dev.o19s.com:8985/solr/tmdb/select',
secureSearchUrl: 'https://quepid-solr.dev.o19s.com/solr/tmdb/select',
urlFormat: 'http(s?)://yourdomain.com:8983/<index>/select',
customHeaders: '',
},
es: {
queryParams: [
'{',
' "query": {',
' "multi_match": {',
' "query": "#$query##",',
' "type": "best_fields",',
' "fields": ["REPLACE_ME"]',
' }',
' }',
'}',
].join('\n'),

escapeQuery: true,
apiMethod: 'POST',
customHeaders: '',
headerType: 'None',
fieldSpec: 'id:_id',
idField: '_id',
titleField: '',
additionalFields: [],
numberOfRows: 10,
searchEngine: 'es',
searchUrl: 'http://quepid-elasticsearch.dev.o19s.com:9206/tmdb/_search',
urlFormat: 'http(s?)://yourdomain.com:9200/<index>/_search',
customHeaders: '',
},
os: {
queryParams: [
'{',
' "query": {',
' "multi_match": {',
' "query": "#$query##",',
' "type": "best_fields",',
' "fields": ["REPLACE_ME"]',
' }',
' }',
'}',
].join('\n'),

escapeQuery: true,
apiMethod: 'POST',
fieldSpec: 'id:_id',
idField: '_id',
titleField: '',
additionalFields: [],
numberOfRows: 10,
searchEngine: 'os',
searchUrl: 'https://reader:[email protected]:9000/tmdb/_search',
urlFormat: 'http(s?)://yourdomain.com:9200/<index>/_search',
customHeaders: '',
}
};
// used by the wizard for TMDB demo search engine
this.tmdbSettings = {
solr: {
queryParams: [
'q=#$query##',
'&defType=edismax',
'&qf=text_all',
'&pf=title',
'&tie=1.0',
'&bf=vote_average',
].join('\n'),

escapeQuery: true,
Expand All @@ -41,6 +121,7 @@ angular.module('QuepidApp')
insecureSearchUrl:'http://quepid-solr.dev.o19s.com:8985/solr/tmdb/select',
secureSearchUrl: 'https://quepid-solr.dev.o19s.com/solr/tmdb/select',
urlFormat: 'http(s?)://yourdomain.com:8983/<index>/select',
customHeaders: '',
},
es: {
queryParams: [
Expand Down Expand Up @@ -71,6 +152,7 @@ angular.module('QuepidApp')
searchEngine: 'es',
searchUrl: 'http://quepid-elasticsearch.dev.o19s.com:9206/tmdb/_search',
urlFormat: 'http(s?)://yourdomain.com:9200/<index>/_search',
customHeaders: '',
},
os: {
queryParams: [
Expand Down Expand Up @@ -99,12 +181,48 @@ angular.module('QuepidApp')
searchEngine: 'os',
searchUrl: 'https://reader:[email protected]:9000/tmdb/_search',
urlFormat: 'http(s?)://yourdomain.com:9200/<index>/_search',
customHeaders: '',
}
};

/* jshint ignore:end */

var Settings = SettingsFactory;
var currSettings = null;

this.demoSettingsChosen = function(searchEngine, newUrl){
var useTMDBDemoSettings = false;
if (searchEngine === 'solr'){
if (newUrl === null || angular.isUndefined(newUrl)){
useTMDBDemoSettings = true;
}
else if (newUrl === this.tmdbSettings['solr'].insecureSearchUrl || newUrl === this.tmdbSettings['solr'].secureSearchUrl ){
useTMDBDemoSettings = true;
}
else {
useTMDBDemoSettings = false;
}
}
else {
if (newUrl === this.tmdbSettings[searchEngine].searchUrl) {
useTMDBDemoSettings = true;
}
else {
useTMDBDemoSettings = false;
}
}
return useTMDBDemoSettings;
};

this.pickSettingsToUse = function(searchEngine, newUrl) {
if (this.demoSettingsChosen(searchEngine, newUrl)){
return angular.copy(this.tmdbSettings[searchEngine]);
}
else {
return angular.copy(this.defaultSettings[searchEngine]);
}
};

this.setCaseTries = function(tries) {
currSettings = new Settings(tries);
};
Expand Down
Loading