Skip to content

Commit ca29b29

Browse files
author
Daniel Orner
authored
Merge pull request #3209 from rubyforgood/implement-import-maps
WIP: Enable and use import maps
2 parents d8f6b3d + 28d2de5 commit ca29b29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+382
-24347
lines changed

.nvmrc

-1
This file was deleted.

Gemfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ gem "jquery-rails"
4646
gem "jquery-ui-rails"
4747
# SASS CSS framework (nested selectors, variables, etc.)
4848
gem "sass-rails"
49-
# JavaScript bundler.
50-
gem 'webpacker', '~> 5.0'
5149
# Used to verify that the user is a human.
5250
gem "recaptcha"
5351
# Hotwire for SPA like without much JS
@@ -112,7 +110,7 @@ gem "clockwork"
112110
gem "mini_racer", "~> 0.6.3"
113111
gem "nokogiri", ">= 1.10.4"
114112
gem "image_processing"
115-
gem "sprockets", "~> 4.2.0"
113+
gem "sprockets", "~> 4.0.0"
116114

117115
group :production do
118116
# Reduce the noise of logs and include custom fields to it for easier access
@@ -218,3 +216,5 @@ end
218216

219217
# Use Redis for Action Cable
220218
gem "redis", "~> 5.0"
219+
220+
gem "importmap-rails", "~> 1.1"

Gemfile.lock

+8-13
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ GEM
240240
image_processing (1.12.2)
241241
mini_magick (>= 4.9.5, < 5)
242242
ruby-vips (>= 2.0.17, < 3)
243+
importmap-rails (1.1.5)
244+
actionpack (>= 6.0.0)
245+
railties (>= 6.0.0)
243246
jbuilder (2.11.5)
244247
actionview (>= 5.0.0)
245248
activesupport (>= 5.0.0)
@@ -404,8 +407,6 @@ GEM
404407
rack (2.2.6.2)
405408
rack-protection (2.1.0)
406409
rack
407-
rack-proxy (0.7.0)
408-
rack
409410
rack-test (2.0.2)
410411
rack (>= 1.3)
411412
rails (7.0.4.2)
@@ -528,7 +529,6 @@ GEM
528529
rexml (~> 3.2, >= 3.2.5)
529530
rubyzip (>= 1.2.2, < 3.0)
530531
websocket (~> 1.0)
531-
semantic_range (3.0.0)
532532
shellany (0.0.1)
533533
shoulda-matchers (5.3.0)
534534
activesupport (>= 5.2.0)
@@ -552,9 +552,9 @@ GEM
552552
snaky_hash (2.0.0)
553553
hashie
554554
version_gem (~> 1.1)
555-
sprockets (4.2.0)
555+
sprockets (4.0.3)
556556
concurrent-ruby (~> 1.0)
557-
rack (>= 2.2.4, < 4)
557+
rack (> 1, < 3)
558558
sprockets-rails (3.4.2)
559559
actionpack (>= 5.2)
560560
activesupport (>= 5.2)
@@ -596,11 +596,6 @@ GEM
596596
addressable (>= 2.8.0)
597597
crack (>= 0.3.2)
598598
hashdiff (>= 0.4.0, < 2.0.0)
599-
webpacker (5.4.3)
600-
activesupport (>= 5.2)
601-
rack-proxy (>= 0.6.1)
602-
railties (>= 5.2)
603-
semantic_range (>= 2.3.0)
604599
webrick (1.7.0)
605600
websocket (1.2.9)
606601
websocket-driver (0.7.5)
@@ -654,6 +649,7 @@ DEPENDENCIES
654649
httparty
655650
icalendar
656651
image_processing
652+
importmap-rails (~> 1.1)
657653
jbuilder
658654
jquery-rails
659655
jquery-ui-rails
@@ -695,7 +691,7 @@ DEPENDENCIES
695691
simple_form
696692
simplecov
697693
skylight
698-
sprockets (~> 4.2.0)
694+
sprockets (~> 4.0.0)
699695
standard (~> 1.0)
700696
stimulus-rails
701697
strong_migrations (= 1.4.2)
@@ -704,10 +700,9 @@ DEPENDENCIES
704700
web-console
705701
webdrivers (~> 5.2)
706702
webmock (~> 3.18)
707-
webpacker (~> 5.0)
708703

709704
RUBY VERSION
710705
ruby 3.1.2p20
711706

712707
BUNDLED WITH
713-
2.3.22
708+
2.3.25

Procfile.dev

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
web: bundle exec rails s -p 3000
22
worker: bundle exec rails jobs:work
3-
webpack: bin/webpack-dev-server

app/assets/config/manifest.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//= link filterrific/filterrific-spinner.gif
22
//= link_tree ../images
3-
//= link_directory ../javascripts .js
43
//= link_directory ../stylesheets .css
4+
//= link_tree ../../javascript .js
5+
//= link_tree ../../../vendor/javascript .js

app/assets/javascripts/adminlte.min.js

-7
This file was deleted.

app/assets/javascripts/adminlte.min.js.map

-1
This file was deleted.

app/assets/javascripts/application.js

-108
This file was deleted.

app/assets/javascripts/cable.js

-13
This file was deleted.

app/javascript/packs/application.js app/javascript/application.js

+35-23
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1-
/* eslint no-console:0 */
2-
// This file is automatically compiled by Webpack, along with any other files
3-
// present in this directory. You're encouraged to place your actual application logic in
4-
// a relevant structure within app/javascript and only use these pack files to reference
5-
// that code so it'll be compiled.
6-
//
7-
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8-
// layout file, like app/views/layouts/application.html.erb
1+
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
92

10-
import { Turbo } from "@hotwired/turbo-rails"
11-
12-
// Disable turbo by default to avoid issues with turbolinks
13-
Turbo.session.drive = false
3+
import jQuery from 'jquery'
4+
window.jQuery = jQuery
5+
window.$ = jQuery
146

15-
import "../controllers/index"
7+
import 'admin-lte'
8+
import "cocoon-js-vanilla";
9+
import 'filterrific'
10+
import { Turbo } from "@hotwired/turbo-rails"
1611
import "trix"
1712
import "@rails/actiontext"
18-
import "stylesheets/application.scss"
19-
import $ from 'jquery';
2013

2114
import {DateTime} from "luxon";
22-
import Litepicker from 'litepicker';
15+
import 'litepicker';
2316
import { Calendar } from '@fullcalendar/core';
2417
import luxonPlugin from '@fullcalendar/luxon'
2518
import dayGridPlugin from '@fullcalendar/daygrid';
2619
import listPlugin from '@fullcalendar/list';
2720
import toastr from 'toastr';
28-
import 'litepicker/dist/plugins/ranges';
29-
import "@fortawesome/fontawesome-free/css/fontawesome.css";
30-
import "@fortawesome/fontawesome-free/css/solid.css";
31-
import "@fortawesome/fontawesome-free/css/regular.css";
32-
import "@fortawesome/fontawesome-free/css/brands.css";
33-
import "@fortawesome/fontawesome-free/css/v4-shims.css";
34-
import "toastr/build/toastr.css"
21+
import 'litepicker/ranges';
22+
23+
import 'bootstrap'
24+
import 'controllers'
25+
26+
import 'utils/adjustments'
27+
import 'utils/barcode_items'
28+
import 'utils/barcode_scan'
29+
import 'utils/deadline_day_pickers'
30+
import 'utils/distributions_and_transfers'
31+
import 'utils/donations'
32+
import 'utils/purchases'
33+
34+
import Rails from "@rails/ujs"
35+
Rails.start()
36+
37+
// Disable turbo by default to avoid issues with turbolinks
38+
Turbo.session.drive = false
3539

3640
// Global toastr options
3741
window.toastr = toastr;
@@ -47,7 +51,13 @@ function isShortHeightScreen() {
4751
return $(window).height() < 768 && !isMobileResolution();
4852
}
4953

54+
55+
// es-module-shims calls DOMContentLoaded twice for some reason
5056
document.addEventListener("DOMContentLoaded", function() {
57+
const hash = window.location.hash;
58+
if (hash) {
59+
$('ul.nav a[href="' + hash + '"]').tab('show');
60+
}
5161
const isMobile = isMobileResolution();
5262
const isShortHeight = isShortHeightScreen();
5363

@@ -96,3 +106,5 @@ document.addEventListener("DOMContentLoaded", function() {
96106
});
97107
picker.setDateRange(startDate, endDate);
98108
}, false);
109+
110+

app/javascript/controllers/application.js

-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { Application } from "@hotwired/stimulus"
2-
import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers"
32

43
const application = Application.start()
5-
window.Stimulus = application;
6-
7-
const context = require.context("/", true, /\.js$/)
8-
Stimulus.load(definitionsFromContext(context))
94

105
// Configure Stimulus development experience
116
application.debug = false

app/javascript/controllers/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
// This file is auto-generated by ./bin/rails stimulus:manifest:update
2-
// Run that command whenever you add a new controller or create them with
3-
// ./bin/rails generate stimulus controllerName
1+
// Import and register all your controllers from the importmap under controllers/*
42

5-
import { application } from "./application"
3+
import { application } from "controllers/application"
4+
5+
// Eager load all controllers defined in the import map under controllers/**/*_controller
6+
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
7+
eagerLoadControllersFrom("controllers", application)
8+
9+
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
10+
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
11+
// lazyLoadControllersFrom("controllers", application)

app/javascript/controllers/select2_controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Controller } from "@hotwired/stimulus"
2-
import Select2 from "select2"
32
import $ from 'jquery';
3+
import "select2"
44

55
export default class extends Controller {
66
static values = {

app/assets/javascripts/adjustments.js app/javascript/utils/adjustments.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import $ from 'jquery';
2+
13
/**
24
* Likely we can remove this since distribution_and_transfers.js seen to cover this use
35
*/
@@ -25,13 +27,12 @@ $(function() {
2527
});
2628

2729
$(document).on("cocoon:after-insert", "form#new_adjustment", function(
28-
e,
29-
insertedItem
30-
) {
30+
e) {
3131
const control = $(control_id);
32+
const insertedItem = $(e.detail[2]);
3233
insertedItem
3334
.find("#_barcode-lookup-new_line_items")
34-
.attr("id", `_barcode-lookup-${$(".nested-fields").size() - 1}`);
35+
.attr("id", `_barcode-lookup-${$(".nested-fields").length - 1}`);
3536
$.ajax({
3637
url: control
3738
.data("storage-location-inventory-path")

0 commit comments

Comments
 (0)