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

Add importmaps rails and turbo rails #15201

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ gem 'matrix', '~> 0.4'
# until we have a fix for https://github.com/rubygems/rubygems/pull/5529
gem 'strscan', '3.0.1'

gem 'turbo-rails'

group :development, :production do
# to have the delayed job daemon
gem 'daemons'
Expand Down Expand Up @@ -234,3 +236,5 @@ group :assets do
# assets for font-awesome vector icons
gem 'font-awesome-sass'
end

gem "importmap-rails", "~> 1.2"
10 changes: 10 additions & 0 deletions src/api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
importmap-rails (1.2.3)
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
influxdb (0.8.1)
influxdb-rails (1.0.3)
influxdb (~> 0.6, >= 0.6.4)
Expand Down Expand Up @@ -486,6 +490,10 @@ GEM
thor (1.3.0)
tilt (2.3.0)
timeout (0.4.1)
turbo-rails (1.5.0)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
Expand Down Expand Up @@ -562,6 +570,7 @@ DEPENDENCIES
haml
haml-rails
haml_lint
importmap-rails (~> 1.2)
influxdb-rails
jquery-datatables
jquery-rails
Expand Down Expand Up @@ -613,6 +622,7 @@ DEPENDENCIES
terser
test-unit
thinking-sphinx
turbo-rails
vcr
view_component
voight_kampff
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
//= link_tree ../images


//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
22 changes: 7 additions & 15 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def new

def edit
authorize @project, :update?
respond_to do |format|
format.js
end
end

def create
Expand Down Expand Up @@ -107,20 +104,15 @@ def create

def update
authorize @project, :update?
respond_to do |format|
if @project.update(project_params)
format.html do
flash[:success] = 'Project was successfully updated.'
redirect_to project_show_path(@project)
end
format.js { flash.now[:success] = 'Project was successfully updated.' }
else
format.html do
flash[:error] = 'Failed to update project'
redirect_to project_show_path(@project)

if @project.update(project_params)
respond_to do |format|
format.turbo_stream do
flash.now[:success] = 'Project was successfully updated.'
end
format.js
end
else
render :edit, status: :unprocessable_entity
end
end

Expand Down
4 changes: 4 additions & 0 deletions src/api/app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"

Turbo.session.drive = false
1 change: 1 addition & 0 deletions src/api/app/views/layouts/webui/webui.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
%meta{ property: 'errbit:key', content: CONFIG['errbit_javascript_api_key'] }
%meta{ property: 'errbit:host', content: CONFIG['errbit_javascript_host'] }

= javascript_importmap_tags
= stylesheet_link_tag 'webui/application'
= javascript_include_tag 'webui/application'

Expand Down
33 changes: 17 additions & 16 deletions src/api/app/views/webui/project/_basic_info.html.haml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
.basic-info.in-place-editing
- if project.categories.any?
- project.categories.each do |category|
= category_badge(category)
- if project.url.present?
= link_to(project.url, project.url, class: 'mb-3 d-block')
#description-text
- if project.description.blank?
%i No description set
- else
= render partial: 'webui/shared/collapsible_text', locals: { text: project.description }
= turbo_frame_tag("basic-info-project_#{project.id}") do
.basic-info.in-place-editing
- if project.categories.any?
- project.categories.each do |category|
= category_badge(category)
- if project.url.present?
= link_to(project.url, project.url, class: 'mb-3 d-block')
#description-text
- if project.description.blank?
%i No description set
- else
= render partial: 'webui/shared/collapsible_text', locals: { text: project.description }

- if policy(project).update?
.pt-4
= link_to(edit_project_path(project), class: 'ps-0', remote: true, title: 'Edit') do
%i.fas.fa-edit.text-secondary
%span.nav-item-name Edit
- if policy(project).update?
.pt-4
= link_to(edit_project_path(project), class: 'ps-0', title: 'Edit') do
%i.fas.fa-edit.text-secondary
%span.nav-item-name Edit
15 changes: 0 additions & 15 deletions src/api/app/views/webui/project/_edit.html.haml

This file was deleted.

26 changes: 26 additions & 0 deletions src/api/app/views/webui/project/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
= turbo_frame_tag("basic-info-project_#{@project.id}") do
= form_for(@project, url: project_update_url, method: :patch) do |form|
%h5 Edit Project #{@project}

= hidden_field_tag(:id, @project.id)
.mb-3
= form.label(:title, 'Title:')
= form.text_field(:title, class: "form-control #{'is-invalid' if @project.errors.include?(:title)}", autofocus: true)
- @project.errors.full_messages_for(:title).each do |error_message|
.invalid-feedback.d-block
= error_message
.mb-3
= form.label(:url, 'URL:')
= form.text_field(:url, class: "form-control #{'is-invalid' if @project.errors.include?(:url)}")
.invalid-feedback.d-block
- @project.errors.full_messages_for(:url).each do |error_message|
= error_message
.mb-3
= form.label(:description, 'Description:')
= form.text_area(:description, rows: 8, class: "form-control #{'is-invalid' if @project.errors.include?(:description)}")
.invalid-feedback.d-block
- @project.errors.full_messages_for(:description).each do |error_message|
= error_message
.mb-3.text-end
= link_to 'Cancel', project_show_path(@project), class: 'cancel btn btn-outline-danger px-4'
= submit_tag('Update', class: 'btn btn-primary px-4')
10 changes: 0 additions & 10 deletions src/api/app/views/webui/project/edit.js.erb

This file was deleted.

18 changes: 0 additions & 18 deletions src/api/app/views/webui/project/update.js.haml

This file was deleted.

4 changes: 4 additions & 0 deletions src/api/app/views/webui/project/update.turbo_stream.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
= turbo_stream.replace "basic-info-project_#{@project.id}", partial: 'basic_info', locals: { project: @project }
= turbo_stream.replace "flash", partial: "layouts/webui/flash"
= turbo_stream.update "project-title" do
= @project.title.presence || @project
4 changes: 4 additions & 0 deletions src/api/bin/importmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby

require_relative "../config/application"
require "importmap/commands"
4 changes: 4 additions & 0 deletions src/api/config/importmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Pin npm packages by running ./bin/importmap

pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
Binary file added src/api/vendor/cache/importmap-rails-1.2.3.gem
Binary file not shown.
Binary file added src/api/vendor/cache/turbo-rails-1.5.0.gem
Binary file not shown.
Empty file added src/api/vendor/javascript/.keep
Empty file.
Loading