Skip to content

Commit

Permalink
Now have the admin side and the wizard...
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Aug 23, 2023
1 parent 4cbf2bb commit 881f5c7
Show file tree
Hide file tree
Showing 29 changed files with 764 additions and 213 deletions.
11 changes: 6 additions & 5 deletions app/assets/javascripts/controllers/queryParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

angular.module('QuepidApp')
.controller('QueryParamsCtrl', [
'$scope','$location', '$window',
'esUrlSvc','caseTryNavSvc',
'$scope',
'esUrlSvc','caseTryNavSvc','searchEndpointSvc',
'TryFactory',
function ($scope, $location, $window,
esUrlSvc, caseTryNavSvc,
function ($scope,
esUrlSvc, caseTryNavSvc,searchEndpointSvc,
TryFactory) {

$scope.qp = {};
Expand All @@ -20,7 +20,8 @@ angular.module('QuepidApp')
$scope.showESTemplateWarning = false;

$scope.showTLSChangeWarning = false;


$scope.searchEndpoints = searchEndpointSvc.list();

$scope.validateSearchEngineUrl = function() {
if (!angular.isUndefined($scope.settings.searchUrl)){
Expand Down
115 changes: 85 additions & 30 deletions app/assets/javascripts/controllers/wizardModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,51 @@ angular.module('QuepidApp')
'$rootScope', '$scope', '$uibModalInstance', '$log', '$window', '$q', '$location',
'WizardHandler',
'settingsSvc', 'SettingsValidatorFactory',
'docCacheSvc', 'queriesSvc', 'caseTryNavSvc', 'caseSvc', 'userSvc',
'docCacheSvc', 'queriesSvc', 'caseTryNavSvc', 'caseSvc', 'userSvc','searchEndpointSvc',
function (
$rootScope, $scope, $uibModalInstance, $log, $window, $q, $location,
WizardHandler,
settingsSvc, SettingsValidatorFactory,
docCacheSvc, queriesSvc, caseTryNavSvc, caseSvc, userSvc
docCacheSvc, queriesSvc, caseTryNavSvc, caseSvc, userSvc, searchEndpointSvc
) {
$log.debug('Init Wizard settings ctrl');
$scope.wizardSettingsModel = {};

$scope.wizardSettingsModel.settingsId = function() {
return settingsSvc.settingsId();
};

$scope.haveSearchEndpoints = false;


//$scope.wizardSettingsModel.searchEndpoints = function() {
//return "hi";
// return searchEndpointSvc.list();
//}

searchEndpointSvc.list()
.then(function() {
console.log("okay, got end points")
$scope.searchEndpoints = searchEndpointSvc.searchEndpoints;
if ($scope.searchEndpoints.length > 0) {
$scope.haveSearchEndpoints = true;
}
else {
$scope.haveSearchEndpoints = false;
}
});

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

// used when you swap radio buttons for the search engine.
$scope.changeSearchEngine = function() {
// used when we first launch the wizard, and it handles reloading from http to https
$scope.updateSettingsDefaults = 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']);
// 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;
Expand All @@ -38,7 +62,9 @@ angular.module('QuepidApp')
$scope.pendingWizardSettings.customHeaders = settings.customHeaders;
$scope.pendingWizardSettings.queryParams = settings.queryParams;
$scope.pendingWizardSettings.titleField = settings.titleField;
$scope.pendingWizardSettings.urlFormat = settings.urlFormat;
$scope.pendingWizardSettings.urlFormat = settings.urlFormat;
$scope.pendingWizardSettings.searchEndpointId = null;
$scope.searchEndpoints = searchEndpointSvc.list();

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

Expand All @@ -54,11 +80,26 @@ angular.module('QuepidApp')
$scope.pendingWizardSettings.searchUrl = settings.searchUrl;
}

// if we have restarted the wizard, then grab the searchUrl, searchEngine, apiMethod,
// and caseName from the params and override the default values.
// We should pass this stuff in externally, not do it here.
if (angular.isDefined($location.search().searchEngine)){
$scope.pendingWizardSettings.searchEngine = $location.search().searchEngine;
}
if (angular.isDefined($location.search().searchUrl)){
$scope.pendingWizardSettings.searchUrl = $location.search().searchUrl;
}
if (angular.isDefined($location.search().caseName)){
$scope.pendingWizardSettings.caseName = $location.search().caseName;
}
if (angular.isDefined($location.search().apiMethod)){
$scope.pendingWizardSettings.apiMethod = $location.search().apiMethod;
}
$scope.reset();
};

// used when we first launch the wizard, and it handles reloading from http to https
$scope.updateSettingsDefaults = function() {
// 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.
Expand Down Expand Up @@ -90,28 +131,19 @@ angular.module('QuepidApp')
$scope.pendingWizardSettings.searchUrl = settings.searchUrl;
}

// if we have restarted the wizard, then grab the searchUrl, searchEngine, apiMethod,
// and caseName from the params and override the default values.
// 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;
}
if (angular.isDefined($location.search().searchUrl)){
$scope.pendingWizardSettings.searchUrl = $location.search().searchUrl;
}
if (angular.isDefined($location.search().caseName)){
$scope.pendingWizardSettings.caseName = $location.search().caseName;
}
if (angular.isDefined($location.search().apiMethod)){
$scope.pendingWizardSettings.apiMethod = $location.search().apiMethod;
}

$scope.reset();
};


// used when you click the accordion for new search endpoint
$scope.switchToCreateNewSearchEndpoint = function() {
console.log("I was just clicked");
$scope.pendingWizardSettings.searchEndpointId = null;

};

$scope.validate = validate;
$scope.skipValidation = skipValidation;
$scope.pickSearchEndpoint = pickSearchEndpoint;
$scope.setupDefaults = setupDefaults;
$scope.submit = submit;
$scope.reset = reset;
Expand All @@ -121,7 +153,6 @@ angular.module('QuepidApp')
$scope.validateHeaders = validateHeaders;
$scope.searchFields = [];


$scope.extractSolrConfigApiUrl = function(searchUrl) {
return searchUrl.substring(0, searchUrl.lastIndexOf('/')) + '/config';
};
Expand All @@ -146,6 +177,29 @@ angular.module('QuepidApp')
WizardHandler.wizard().next();
}
}

function pickSearchEndpoint() {
console.log("In pickSearchEndpoint");
searchEndpointSvc.get($scope.pendingWizardSettings.searchEndpointId)
.then( function (searchEndpoint){
console.log("Got a search endpoint");

// Maybe we should refactor to have searchEndpoint a first class object and use it
// Everywhere?

$scope.pendingWizardSettings.searchEngine = searchEndpoint.searchEngine;
$scope.pendingWizardSettings.searchUrl = searchEndpoint.endpointUrl;
$scope.pendingWizardSettings.apiMethod = searchEndpoint.apiMethod;
$scope.pendingWizardSettings.customHeaders = searchEndpoint.customHeaders;

// Are there any places wehre we do validate(true)
validate();

});
// populate $scope.pendingWizardSettings
// validate()

}

function skipValidation() {
var validator = new SettingsValidatorFactory($scope.pendingWizardSettings);
Expand Down Expand Up @@ -174,7 +228,6 @@ angular.module('QuepidApp')
if ($scope.showTLSChangeWarning || $scope.invalidHeaders){
return;
}

var validator = new SettingsValidatorFactory($scope.pendingWizardSettings);
validator.validateUrl()
.then(function () {
Expand Down Expand Up @@ -337,10 +390,12 @@ angular.module('QuepidApp')
var tempSearchUrl = $scope.pendingWizardSettings.searchUrl;
var tempApiMethod = $scope.pendingWizardSettings.apiMethod;
var tempQueryParams = $scope.pendingWizardSettings.queryParams;
var tempSearchEngine = $scope.pendingWizardSettings.searchEngine;
angular.merge($scope.pendingWizardSettings, settingsSvc.editableSettings());
$scope.pendingWizardSettings.searchUrl = tempSearchUrl;
$scope.pendingWizardSettings.apiMethod = tempApiMethod;
$scope.pendingWizardSettings.queryParams = tempQueryParams;
$scope.pendingWizardSettings.searchEngine = tempSearchEngine;
$scope.pendingWizardSettings.newQueries = [];

if(userSvc.getUser().completedCaseWizard===false){
Expand Down
101 changes: 101 additions & 0 deletions app/assets/javascripts/services/searchEndpointSvc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';
/*jshint camelcase: false */

angular.module('QuepidApp')
// AngularJS will instantiate a singleton by calling "new" on this function
.service('searchEndpointSvc', [
'$http',
function searchEndpointSvc($http) {
this.searchEndpoints = [];

var SearchEndpoint = function(id, name, searchEngine, endpointUrl, apiMethod, customHeaders) {
this.id = id;
this.name = name;
this.searchEngine = searchEngine;
this.endpointUrl = endpointUrl;
this.apiMethod = apiMethod;
this.customHeaders= customHeaders;
};

this.constructFromShallowData = function(data) {
return new SearchEndpoint(
data.search_endpoint_id,
data.name,
data.search_engine,
null,
null,
null
);
};


this.constructFromData = function(data) {
return new SearchEndpoint(
data.search_endpoint_id,
data.name,
data.search_engine,
data.endpoint_url,
data.api_method,
data.custom_headers
);
};

var contains = function(list, searchEndpoint) {
return list.filter(function(item) { return item.id === searchEndpoint.id; }).length > 0;
};

this.get = function(searchEndpointId) {
// http GET /api/search_endpoints/<int:searchEndpointId>/
var url = 'api/search_endpoints/' + searchEndpointId;
var self = this;


return $http.get(url)
.then(function(response) {
var searchEndpoint = self.constructFromData(response.data);

return searchEndpoint;
});
};


this.list = function() {
// http GET /api/search_endpoints
var url = 'api/search_endpoints?shallow=true';
var self = this;

// Clear the list just in case the data on the server changed,
// we want to have the latest list.
// TODO: write tests for this.
self.searchEndpoints = [];

return $http.get(url)
.then(function(response) {
angular.forEach(response.data.search_endpoints, function(dataSearchEndpoint) {
var searchEndpoint = self.constructFromShallowData(dataSearchEndpoint);

//if(!contains(self.searchEndpoint, search_endpoint)) {
self.searchEndpoints.push(searchEndpoint);
//}
});
});
};

this.shareEndpoint = function(team, searchEndpoint) {
// http POST api/teams/<int:teamId>/cases
var url = 'api/teams/' + team.id + '/search_endpoints';
var data = {
id: searchEndpoint.id
};

return $http.post(url, data)
.then(function(response) {
team.searchEndpoints.push(response.data);
});
};

this.filteredEndpoints = function(searchEngine){
return this.searchEndpoints.filter(function(item) { return item.searchEngine === searchEngine; })
}
}
]);
3 changes: 2 additions & 1 deletion app/assets/javascripts/services/settingsSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,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 All @@ -204,6 +204,7 @@ angular.module('QuepidApp')
}
}
else {
console.log("The serach engine is " + searchEngine);
if (newUrl === this.tmdbSettings[searchEngine].searchUrl) {
useTMDBDemoSettings = true;
}
Expand Down
11 changes: 7 additions & 4 deletions app/assets/templates/views/devQueryParams.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,29 @@ <h4>Tuning Knobs</h4>
</div>
<!-- end of Search Engine -->

<!-- Search Engine Request Handler -->
<!-- Search Endpoint -->
<div class="setting-div">
<div class="dev-header" ng-click="devSettingsUrl.toggle = !devSettingsUrl.toggle">
Search Engine Request Handler <span ng-class="{true: 'glyphicon-plus-sign', false: 'glyphicon-minus-sign'}[!devSettingsUrl.toggle]" class="glyphicon"></span>
Search Endpoint <span ng-class="{true: 'glyphicon-plus-sign', false: 'glyphicon-minus-sign'}[!devSettingsUrl.toggle]" class="glyphicon"></span>
</div>

<div class="dev-body" ng-show="devSettingsUrl.toggle">
<div class="dev-body" ng-show="devSettingsUrl.toggle">
<input type="text" class="form-control" id="" placeholder="Enter Your Search Engine URL" ng-model="settings.searchUrl" ng-change="validateSearchEngineUrl()">

<p class="help-block tip">
Tip: Your URL should look like this {{settings.urlFormat}}.
</p>
<p>
<a ng-href="search_endpoints/" target="_self">Manage Search Endpoints</a></p>
<p>

<span ng-show="showTLSChangeWarning">
You have specified a search engine url that is on a different protocol ( <code>{{protocolToSwitchTo}}</code> ) than Quepid is currently on,
so you need to reload Quepid on that protocol. This is to comply with browser security issues.
</span>
</div>
</div>
<!-- end of Search Engine Request Handler -->
<!-- end of Search Endpoint -->

<!-- Display Fields -->
<div class="setting-div" ng-init="validateSearchEngineUrl()">
Expand Down
Loading

0 comments on commit 881f5c7

Please sign in to comment.