Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Nov 4, 2024
1 parent 3c8615b commit 4c5f14d
Show file tree
Hide file tree
Showing 28 changed files with 130 additions and 209 deletions.
25 changes: 7 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ Runs tests for the Angular side. There are two modes for the karma tests:
* Single run: `bin/docker r rails karma:run`
* Continuous/watched run: `bin/docker r bin/rake karma:start`

**Note:** The karma tests require the assets to be precompiled, which adds a significant amount of time to the test run. If you are only making changes to the test/spec files, then it is recommended you run the tests in watch mode (`bin/docker r bin/rake karma:start`). The caveat is that any time you make a change to the app files, you will have to restart the process (or use the single run mode).
**Note:** The karma tests require the assets to be precompiled, which adds a significant amount of time to the test run.
If you are only making changes to the test/spec files, then it is recommended you run the tests in watch mode (`bin/docker r bin/rake karma:start`).
The caveat is that any time you make a change to the app files, you will have to restart the process (or use the single run mode).

### Rubocop

Expand Down Expand Up @@ -298,20 +300,6 @@ JavaScript and CSS dependencies via the Rails Asset pipeline. If you are debug
you will want individual files. So replace `//= require sprockets` with `//= require bootstrap-sprockets`.


### Webpacker
To use webpacker, that will compile javascript code into packs and will load changes faster,
you need to

```bash
bin/rails webpacker:install
```

Prior to that I had to install:

```bash
brew install mysql
```

### Debugging Splainer and other NPM packages

`docker-compose.override.yml.example` can be copied to `docker-compose.override.yml` and use it to override environment variables or work with a local copy of the splainer-search JS library during development defined in `docker-compose.yml`. Example is included. Just update the path to `splainer-search` with your local checkout! https://docs.docker.com/compose/extends/
Expand Down Expand Up @@ -517,10 +505,11 @@ You will see a updated `Gemfile.lock`, go ahead and check it and `Gemfile` into
## How does the Frontend work?

We use Angular 1 for the front end, and as part of that we use the `angular-ui-bootstrap` package
for all our UI components. This package is tied to Bootstrap version 3. We import the Bootstrap 3
CSS directly via the file `bootstrap.css`.
for all our UI components. This package is tied to Bootstrap version 3.
We import the Bootstrap 3 CSS directly via the file `bootstrap.css`.

For the various Admin pages, we actually are using Bootstrap 5! That is included via the `package.json` using NPM. See `admin.js` for the line `//= require bootstrap/dist/js/bootstrap.bundle` which is where we are including.
For the various Admin pages, we actually are using Bootstrap 5! That is included via the `package.json` using NPM.
See `admin.js` for the line `//= require bootstrap/dist/js/bootstrap.bundle` which is where we are including.

We currently use Rails Sprockets to compile everything, but do have dreams of moving the JavaScript
over to Webpacker.
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ angular.module('QuepidApp', [
'angular-flash.flash-alert-directive',
'ngTagsInput',
'ng-rails-csrf',
'templates',
'ngAnimate',
'countUp',
'ngclipboard',
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
//= require angular-ui-bootstrap/dist/ui-bootstrap
//= require angular-ui-bootstrap/dist/ui-bootstrap-tpls
//= require angular-wizard/dist/angular-wizard
//= require angular-rails-templates
//= require splainer-search/splainer-search
//= require ng-json-explorer/dist/angular-json-explorer
//= require angular-ui-ace/src/ui-ace
Expand Down
14 changes: 0 additions & 14 deletions app/assets/javascripts/factories/MapperFactory.js

This file was deleted.

31 changes: 31 additions & 0 deletions app/assets/javascripts/interceptors/rails-csrf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
'use strict';

angular.module('ng-rails-csrf', [] )
.config(['$provide', function($provide) {
// This method lets us modify the default behavior of $templateRequest to hit a
// custom Rails controller "pages_controller" to look up templates. Previously we
// used the angular-rails-templates project to include all the templates in the app.js
// file that was produced by Sprockets. However, we don't have this with Propshaft.
// If we can go BACK to including the templates in the big javascript load, well, that avoids
// all the sha stamping of the files.

// node_module provided files start with these paths
const patterns = ['angularUtils', 'uib'];
$provide.decorator('$templateRequest', ['$delegate', function($delegate) {
// Store the original handleRequestFn method
var originalHandleRequestFn = $delegate;

// Override the handleRequestFn method
$delegate = function(tpl, ignoreRequestError) {

var internalResource = patterns.some(pattern => tpl.startsWith(pattern));

if (!internalResource) {
// Route to custom Rails end point for reading in the file.
tpl = '/angularjs/' + tpl;
}

// Call the original handleRequestFn with the modified tpl
return originalHandleRequestFn(tpl, ignoreRequestError);
};

return $delegate;
}]);
}])
.config([
'$httpProvider',
function($httpProvider) {
Expand Down
31 changes: 30 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,38 @@ class PagesController < ApplicationController
# def show
# render template: "pages/#{params[:page]}"
# end

# This is how we handle AngularJS wanting to load assets without us moving them on disk.
def angularjs
puts "hi"
puts params

path = request.path
# Get the full request path (with query parameters, if any)
full_path = request.fullpath

# this is how we deal with the ACE editor wanting this specific file.
# For demonstration, you can log or use the path
puts "Request path: #{path}"
puts "Full request path: #{full_path}"

#full_path = "/angularjs/new_case/new_case.html"
relative_path = "/" + params[:path] + ".html" #full_path.sub(/^\/angularjs\/?/, '')
path_components = relative_path.split('/')

#file_path = Rails.root.join('app', 'assets', 'javascripts','components','new_case','new_case.html') # adjust the path accordingly
file_path_loc_a = Rails.root.join('app', 'assets', 'javascripts', 'components', *path_components)
file_path_loc_b = Rails.root.join('app', 'assets', 'templates', *path_components)

file_path = File.exist?(file_path_loc_a) ? file_path_loc_a : file_path_loc_b

if File.exist?(file_path)
render html: File.read(file_path).html_safe
else
render plain: "File not found", status: :not_found
end
end

# this is how we deal with the ACE editor wanting this specific file.
def theme_textmate
path = 'node_modules/ace-builds/src-min-noconflict/theme-textmate.js'
file_contents = File.read(path)
Expand Down
12 changes: 6 additions & 6 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@
config.web_console.permissions = '192.168.0.0/16'

config.after_initialize do
Bullet.enable = true
Bullet.alert = false
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.add_footer = true
# Bullet.enable = true
# Bullet.alert = false
# Bullet.bullet_logger = true
# Bullet.console = true
# Bullet.rails_logger = true
# Bullet.add_footer = true
end

config.log_formatter = TruncatingFormatter.new
Expand Down
9 changes: 7 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

root 'home#show'

get 'home/sparklines', to: 'home#sparklines'
get 'home/sparklines'#, to: 'home#sparklines'
get 'home/case_prophet/:case_id', to: 'home#case_prophet', as: :home_case_prophet
# get 'tries_visualization/:case_id' => 'tries_visualization#show', as: :tries_visualization
get 'proxy/fetch'
Expand Down Expand Up @@ -187,7 +187,10 @@

# Case Metadata/Scores
resource :metadata, only: [ :update ], controller: :case_metadata
resource :scores, only: [ :index, :update, :show ], controller: :case_scores

# Weird rails 8 warning about :only and :except must include only [:show, :create, :update, :destroy, :new, :edit], but also included [:index]
#resource :scores, only: [ :index, :update, :show ], controller: :case_scores
resource :scores, controller: :case_scores
get '/scores/all' => 'case_scores#index'

resources :annotations, except: [ :show ]
Expand Down Expand Up @@ -269,6 +272,8 @@
# Static pages
# get '*page' => 'pages#show'
#

get '/angularjs/*path.html' => 'pages#angularjs'

# Deal with ACE Editor really really wanting this file here
get '/javascripts/ace/theme-textmate.js' => 'pages#theme_textmate'
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"@fortawesome/fontawesome-free": "^6.6.0",
"@fortawesome/free-regular-svg-icons": "^6.6.0",
"@popperjs/core": "^2.11.6",
"@rails/actioncable": "7.2.101",
"@rails/activestorage": "7.2.101",
"@rails/actioncable": "8.0.0-rc2",
"@rails/activestorage": "8.0.0-rc2",
"ace-builds": "^1.32.2",
"angular": "~1.8.3",
"angular-animate": "^1.8.3",
Expand Down
3 changes: 2 additions & 1 deletion spec/javascripts/angular/controllers/promptSnapshot_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ describe('Controller: PromptSnapshotCtrl', function () {
docResolverSvc = new MockDocResolverSvc();
$provide.value('docResolverSvc', docResolverSvc);
settingsSvc = new MockSettingsSvc();
$provide.value('settingsSvc', settingsSvc);
$provide.value('settingsSvc', settingsSvc);
});
/* jshint camelcase: false */
inject(function ($controller, $rootScope, _$uibModal_, _querySnapshotSvc_, $injector) {
scope = $rootScope.$new();
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/angularjs/views/404.html').respond(200, "");
querySnapshotSvc = _querySnapshotSvc_;

modalInstance = _$uibModal_.open({
Expand Down
1 change: 1 addition & 0 deletions spec/javascripts/angular/controllers/queryParams_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Controller: QueryparamsCtrl', function () {
scope = $rootScope.$new();

$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/angularjs/views/404.html').respond(200, "");

var queryParams = 'q=#$query##';
var curatorVars = {};
Expand Down
1 change: 1 addition & 0 deletions spec/javascripts/angular/controllers/wizardModal_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('Controller: WizardModalCtrl', function () {
scope = $rootScope.$new();
settingsSvc = _settingsSvc_;
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/angularjs/views/404.html').respond(200, "");
WizardModalCtrl = $controller('WizardModalCtrl', {
$scope: scope
});
Expand Down
1 change: 1 addition & 0 deletions spec/javascripts/angular/services/annotationsSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Service: annotationsSvc', function () {
annotationsSvc = _annotationsSvc_;

$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/angularjs/views/404.html').respond(200, "");
}));

afterEach(function() {
Expand Down
1 change: 1 addition & 0 deletions spec/javascripts/angular/services/caseSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('Service: caseSvc', function () {
inject(function (_caseSvc_, $injector) {
caseSvc = _caseSvc_;
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/angularjs/views/404.html').respond(200, "");
});
});

Expand Down
1 change: 1 addition & 0 deletions spec/javascripts/angular/services/diffResultsSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('Service: diffResultsSvc', function() {
});
inject(function (_$rootScope_, _$q_, _diffResultsSvc_, _fieldSpecSvc_, _ratingsStoreSvc_, _docResolverSvc_, $injector) {
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/angularjs/views/404.html').respond(200, "");
$q = _$q_;
$rootScope = _$rootScope_;
diffResultsSvc = _diffResultsSvc_;
Expand Down
4 changes: 3 additions & 1 deletion spec/javascripts/angular/services/docCacheSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ describe('Service: docCacheSvc', function () {
};

beforeEach(function() {
inject(function(_$rootScope_, _$q_, _docCacheSvc_, _docResolverSvc_) {
inject(function(_$rootScope_, _$q_, _docCacheSvc_, _docResolverSvc_, $injector) {
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/angularjs/views/404.html').respond(200, "");
$rootScope = _$rootScope_;
$q = _$q_;
docCacheSvc = _docCacheSvc_;
Expand Down
1 change: 1 addition & 0 deletions spec/javascripts/angular/services/importRatingsSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Service: importRatingsSvc', function () {
beforeEach(function() {
inject(function ($injector, _importRatingsSvc_) {
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/angularjs/views/404.html').respond(200, "");
importRatingsSvc = _importRatingsSvc_;
});
});
Expand Down
Loading

0 comments on commit 4c5f14d

Please sign in to comment.