Skip to content

Commit

Permalink
Bug Fixing Round! (#793)
Browse files Browse the repository at this point in the history
* don't validate ssl certs ;-)

* fix routing issues by using proper rails path!

* nicer complete links

* no longer needed since we use complete links

* Deal with Ace Editor really really really wanting certain files in certain places.

* fix fonts

* Now distingushing between a "reload TLS" issue and a "You don't have access to case" issue.

* rubocop!
  • Loading branch information
epugh authored Aug 24, 2023
1 parent 1f8648e commit a3cc40e
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 53 deletions.
14 changes: 0 additions & 14 deletions app/assets/javascripts/controllers/bootstrap.js

This file was deleted.

27 changes: 20 additions & 7 deletions app/assets/javascripts/controllers/mainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ angular.module('QuepidApp')
var bootstrapCase = function() {
return caseSvc.get(caseNo)
.then(function(acase) {
if (angular.isUndefined(acase)){
throw new Error('Could not retrieve case ' + caseNo + '. Confirm that the case has been shared with you via a team you are a member of!');
}

caseSvc.selectTheCase(acase);
settingsSvc.setCaseTries(acase.tries);
Expand Down Expand Up @@ -142,15 +145,25 @@ angular.module('QuepidApp')
loadSnapshots();
updateCaseMetadata();
paneSvc.refreshElements();
}).catch(function() {
var resultsTuple = caseTryNavSvc.swapQuepidUrlTLS();
}).catch(function(error) {
// brittle logic, but check if we throw the TLS error or if it's from something else.'
var message = error.message;
if (message === 'Need to change to different TLS'){
var resultsTuple = caseTryNavSvc.swapQuepidUrlTLS();

var quepidUrlToSwitchTo = resultsTuple[0];
var protocolToSwitchTo = resultsTuple[1];
var quepidUrlToSwitchTo = resultsTuple[0];
var protocolToSwitchTo = resultsTuple[1];

flash.to('search-error').error = '<a href="' + quepidUrlToSwitchTo + '" class="btn btn-primary form-control">Click Here to <span class="glyphicon glyphicon-refresh"></span> Reload Quepid in <code>' + protocolToSwitchTo + '</code> Protocol!';
loadSnapshots();
updateCaseMetadata();
flash.to('search-error').error = '<a href="' + quepidUrlToSwitchTo + '" class="btn btn-primary form-control">Click Here to <span class="glyphicon glyphicon-refresh"></span> Reload Quepid in <code>' + protocolToSwitchTo + '</code> Protocol!';
}
else if (message.startsWith('Could not retrieve case')){
flash.to('search-error').error = message;
}
else {
flash.to('search-error').error = 'Could not load the case ' + caseNo + ' due to: ' + message;
}
//loadSnapshots();
//updateCaseMetadata();
paneSvc.refreshElements();
});

Expand Down
29 changes: 17 additions & 12 deletions app/assets/javascripts/controllers/queriesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,23 @@ angular.module('QuepidApp')
if ( isNaN(tryNo) ) { // If we didn't specify a try, then we need to get the latest
caseSvc.get(caseNo)
.then(function(acase) {

tryNo = acase.lastTry;
console.log('We do not have a tryNo, so we grabbed the lastTry from the case, and using it as the id:' + tryNo);
lastScoreTracker = {
'score': $scope.queries.avgQuery.currentScore.score,
'all_rated': $scope.queries.avgQuery.currentScore.allRated,
'try_number': tryNo,
'queries': $scope.queries.avgQuery.currentScore.queries,
};

$log.info('sending score information to mothership');
caseSvc.trackLastScore(caseNo, lastScoreTracker);
if (angular.isUndefined(acase)){
$log.info('Did not find a case for ' + caseNo + ' and therefore not scoring');
}
else {
tryNo = acase.lastTry;

$log.info('We do not have a tryNo, so we grabbed the lastTry from the case, and using it as the id:' + tryNo);
lastScoreTracker = {
'score': $scope.queries.avgQuery.currentScore.score,
'all_rated': $scope.queries.avgQuery.currentScore.allRated,
'try_number': tryNo,
'queries': $scope.queries.avgQuery.currentScore.queries,
};

$log.info('sending score information to mothership');
caseSvc.trackLastScore(caseNo, lastScoreTracker);
}
});
}
else {
Expand Down
8 changes: 8 additions & 0 deletions app/assets/javascripts/mode-json.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions app/assets/javascripts/services/bootstrapSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

angular.module('UtilitiesModule')
.service('bootstrapSvc', [
'$http',
'$location',
'$rootScope',
'userSvc', 'caseSvc', 'caseTryNavSvc',
function bootstrapSvc($http, $location, $rootScope, userSvc, caseSvc, caseTryNavSvc) {
'userSvc',
function bootstrapSvc($rootScope, userSvc) {
var self = this;

// Public Functions
self.run = run;

function run(caseNo, tryNo) {
function run() {
// Fetch the current user who is logged in
userSvc.getCurrentUser()
.then(function() {
Expand All @@ -26,9 +24,6 @@ angular.module('UtilitiesModule')
// instead of having to call the userSvc.getUser() function all the time.
$rootScope.currentUser = user;

if (user && angular.isDefined(caseNo) && angular.isDefined(tryNo)) {
caseTryNavSvc.pathRequested({caseNo: caseNo, tryNo: tryNo});
}
});
}
}
Expand Down
9 changes: 4 additions & 5 deletions app/assets/javascripts/services/caseSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
angular.module('QuepidApp')
.service('caseSvc', [
'$http', '$filter', '$q', '$rootScope',
'flash',
'$log',
'caseTryNavSvc', 'queriesSvc', 'settingsSvc',
'broadcastSvc',
function caseSvc(
$http, $filter, $q, $rootScope,
flash,
$log,
caseTryNavSvc, queriesSvc, settingsSvc,
broadcastSvc
) {
Expand Down Expand Up @@ -478,9 +478,8 @@ angular.module('QuepidApp')

svc.allCases[index] = acase;
return acase;
}, function(response) {
flash.to('search-error').error = 'Either the case does not exist or you do not have permissions to access it!';
return response;
}, function() {
$log.info('Did not find the case ' + id);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/views/wizardModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h2>Solr, Elasticsearch, or OpenSearch?</h2>
If you are using a version of Solr between 8.4 and 9.0, you may need to tweak the content-type being set by <code>wt=json</code>.
You can do this via the below curl command:
<pre>
curl -X POST -H 'Content-type:application/json' -d '{
curl -k -X POST -H 'Content-type:application/json' -d '{
"update-queryresponsewriter": {
"name": "json",
"class": "solr.JSONResponseWriter",
Expand Down
16 changes: 13 additions & 3 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

class PagesController < ApplicationController
skip_before_action :require_login
before_action :check_page
skip_before_action :verify_authenticity_token, only: [ :theme_textmate ]
# before_action :check_page, only: [:show]

def show
render template: "pages/#{params[:page]}"
# def show
# render template: "pages/#{params[:page]}"
# end

# this is how we deal with the ACE editor wanting this specific file.
# There is another mode-json.js file that it wants from /assets/mode-json.js,
# and that we are able to just add to /app/assets/javascripts.
def theme_textmate
path = 'node_modules/ace-builds/src-min-noconflict/theme-textmate.js'
file_contents = File.read(path)
render js: file_contents
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/_case.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
<% end %>
</td>

<td><%= link_to 'View', case_core_path(kase), class: 'btn btn-sm btn-primary', role: 'button' %></td>
<td><%= link_to 'View', case_core_path(kase, kase.last_try_number), class: 'btn btn-sm btn-primary', role: 'button' %></td>
</tr>
2 changes: 1 addition & 1 deletion app/views/home/_case_summary.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="col-12 col-md-6 mb-4 mb-lg-0 col-lg-3">
<div class="card">
<h5 class="card-header">
<%= link_to case_title(kase), case_core_path(kase) %>
<%= link_to case_title(kase), case_core_path(kase, kase.last_try_number) %>
</h5>

<div class="card-body">
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ https://getbootstrap.com/docs/5.2/examples/navbars-offcanvas/# for example of of
var yourVlSpec = {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"url": "http://localhost:3000/analytics/sparkline/vega_data.csv",
"url": "<%= analytics_sparkline_vega_data_path format: :csv %>",
"name": "dataset",
"format": {"type": "csv"}
},
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
ng-tags-input/build/ng-tags-input.min.css
ng-tags-input/build/ng-tags-input.bootstrap.min.css
]

# For some reason the mapping in core.css.scss isn't working, so do this.'
Rails.application.config.assets.paths << Rails.root.join('node_modules/bootstrap-icons/font')
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,9 @@

# Static pages
# get '*page' => 'pages#show'
#

# Deal with ACE Editor really really wanting this file here
get '/javascripts/ace/theme-textmate.js' => 'pages#theme_textmate'
end
# rubocop:enable Metrics/BlockLength
4 changes: 4 additions & 0 deletions lib/jshint/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def javascript_files
# I am skipping them via this terrible way because I can't get JSHint exclude_paths to work.
# They should be fixed to pass jshint!
files_to_skip = [ 'user_pulse.js', 'tour.js' ]

# This file is a copied from node_modules/ace-builds to make Ace happy, so ignore
files_to_skip << 'mode-json.js'

js_asset_files = []
file_paths.each do |path|
Dir.glob(path) do |file|
Expand Down

0 comments on commit a3cc40e

Please sign in to comment.