Skip to content

Commit

Permalink
Switch from turbolinks and rails-ujs to turbo-rails
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 29, 2024
1 parent 18ae322 commit 20950fe
Show file tree
Hide file tree
Showing 27 changed files with 87 additions and 73 deletions.
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ gem 'pg'
# Use Puma as the app server
gem 'puma', '>= 5.0'

# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'

Expand Down Expand Up @@ -116,3 +113,5 @@ gem "local_time", "~> 2.1"
gem "cssbundling-rails", "~> 1.1"

gem "importmap-rails", "~> 1.1"

gem "turbo-rails", "~> 2.0"
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ GEM
thor (1.3.2)
timecop (0.9.10)
timeout (0.4.1)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
turbo-rails (2.0.11)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.2.0)
Expand Down Expand Up @@ -545,7 +545,7 @@ DEPENDENCIES
sprockets-rails
sqlite3 (~> 1.4)
timecop
turbolinks (~> 5)
turbo-rails (~> 2.0)
tzinfo-data
web-console
webdrivers
Expand Down
41 changes: 24 additions & 17 deletions app/assets/stylesheets/application.sass.scss
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// Entrypoint for stylesheet
@import 'bootstrap-overrides';
@import 'bootstrap/scss/bootstrap';
@import 'variables';
@import 'logo';
@import 'pod-icons';
@import 'rails_bootstrap_forms';
@import 'organizations';
@import 'streams';
@import 'files';
@import "bootstrap-overrides";
@import "bootstrap/scss/bootstrap";
@import "variables";
@import "logo";
@import "pod-icons";
@import "rails_bootstrap_forms";
@import "organizations";
@import "streams";
@import "files";

// background image for homepage banner
#hero .bg-image {
width: 100%;
height: 100%;
position: absolute;
background-image: url('hero.jpg');
background-image: url("hero.jpg");
background-size: contain;
top: 0; bottom: 0; left: 0; right: 0;
filter:blur(3.5px) brightness(50%) sepia(50%) hue-rotate(160deg);
top: 0;
bottom: 0;
left: 0;
right: 0;
filter: blur(3.5px) brightness(50%) sepia(50%) hue-rotate(160deg);
}

.direct-upload {
Expand All @@ -39,7 +42,9 @@
a {
padding-left: 0.5rem;
opacity: 0;
transition: color .15s ease-in-out,opacity .15s ease-in-out;
transition:
color 0.15s ease-in-out,
opacity 0.15s ease-in-out;
}
&:hover {
a {
Expand All @@ -57,7 +62,9 @@
min-width: 50px;
background: $info;
text-align: center;
transition: width 120ms ease-out, opacity 60ms 60ms ease-in;
transition:
width 120ms ease-out,
opacity 60ms 60ms ease-in;
transform: translate3d(0, 0, 0);
}

Expand All @@ -73,7 +80,7 @@
border-color: $danger;
}

input[type=file][data-direct-upload-url][disabled] {
input[type="file"][data-direct-upload-url][disabled] {
display: none;
}

Expand Down Expand Up @@ -148,10 +155,10 @@ input[type=file][data-direct-upload-url][disabled] {
font-weight: 500;
}

// turbolinks progress bar: render in a more constrasting color, and prevent
// turbo progress bar: render in a more constrasting color, and prevent
// layout shift when it appears by absolute-positioning it. see:
// https://github.com/pod4lib/aggregator/issues/658
.turbolinks-progress-bar {
.turbo-progress-bar {
position: absolute;
z-index: 1;
top: 0;
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/allowlisted_jwts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def new; end
def create
respond_to do |format|
if @allowlisted_jwt.save
format.html { redirect_to organization_allowlisted_jwts_path(@organization), notice: 'Token was successfully created.' }
format.html do
redirect_to organization_allowlisted_jwts_path(@organization), notice: 'Token was successfully created.',
status: :see_other
end
format.json { render :show, status: :created, location: [@organization, @allowlisted_jwt] }
else
format.html { render :new }
Expand All @@ -35,7 +38,10 @@ def destroy
@allowlisted_jwt.destroy

respond_to do |format|
format.html { redirect_to organization_allowlisted_jwts_path(@organization), notice: 'Token was successfully destroyed.' }
format.html do
redirect_to organization_allowlisted_jwts_path(@organization), notice: 'Token was successfully destroyed.',
status: :see_other
end
format.json { head :no_content }
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ApplicationController < ActionController::Base
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.json { head :forbidden, content_type: 'text/html' }
format.html { redirect_to main_app.root_url, notice: exception.message }
format.html { redirect_to main_app.root_url, notice: exception.message, status: :see_other }
format.js { head :forbidden, content_type: 'text/html' }
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/contact_emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def render_or_redirect_with_flash(**messages)
end

if can? :read, @contact_email.organization
redirect_to @contact_email.organization
redirect_to @contact_email.organization, status: :see_other
else
render 'confirm'
end
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/organization_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def update
@user.add_role(params[:add_role], @organization) if params[:add_role].present?

respond_to do |format|
format.html { redirect_to organization_users_url(@organization), notice: 'User role was successfully updated.' }
format.html do
redirect_to organization_users_url(@organization), notice: 'User role was successfully updated.', status: :see_other
end
format.json { head :no_content }
end
end
Expand All @@ -26,7 +28,9 @@ def destroy
@user.destroy

respond_to do |format|
format.html { redirect_to organization_users_url(@organization), notice: 'User was successfully removed.' }
format.html do
redirect_to organization_users_url(@organization), notice: 'User was successfully removed.', status: :see_other
end
format.json { head :no_content }
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
def show
# make the org homepage for consumer orgs point to their org details default tab
# see https://github.com/pod4lib/aggregator/issues/535#issuecomment-1103234114
redirect_to organization_users_path(@organization) unless @organization.provider?
redirect_to organization_users_path(@organization), status: :see_other unless @organization.provider?

@stream = @organization.default_stream if @organization.provider?
@uploads = @organization.default_stream.uploads.active.order(created_at: :desc).page(params[:page])
Expand All @@ -30,7 +30,7 @@ def new
# GET /organizations/1/provider_details
def provider_details
# consumer orgs don't have provider details; redirect to org details instead
redirect_to organization_details_organization_path(@organization) unless @organization.provider?
redirect_to organization_details_organization_path(@organization), status: :see_other unless @organization.provider?
end

# GET /organizations/1/organization_details
Expand All @@ -43,7 +43,7 @@ def create

respond_to do |format|
if @organization.save
format.html { redirect_to @organization, notice: 'Organization was successfully created.' }
format.html { redirect_to @organization, notice: 'Organization was successfully created.', status: :see_other }
format.json { render :show, status: :created, location: @organization }
else
format.html { render :new }
Expand Down Expand Up @@ -71,7 +71,7 @@ def update
def destroy
@organization.destroy
respond_to do |format|
format.html { redirect_to organizations_url, notice: 'Organization was successfully destroyed.' }
format.html { redirect_to organizations_url, notice: 'Organization was successfully destroyed.', status: :see_other }
format.json { head :no_content }
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/site_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def update
@user.add_role params[:add_role] if params[:add_role].present?

respond_to do |format|
format.html { redirect_to site_users_url, notice: 'User role was successfully updated.' }
format.html { redirect_to site_users_url, notice: 'User role was successfully updated.', status: :see_other }
format.json { head :no_content }
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/streams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create

respond_to do |format|
if @stream.save
format.html { redirect_to [@organization, @stream], notice: 'Stream was successfully created.' }
format.html { redirect_to [@organization, @stream], notice: 'Stream was successfully created.', status: :see_other }
format.json { render :show, status: :created, location: [@organization, @stream] }
else
format.html { render :new }
Expand All @@ -45,7 +45,7 @@ def destroy
@stream.destroy

respond_to do |format|
format.html { redirect_to organization_streams_path, notice: 'Stream was successfully destroyed.' }
format.html { redirect_to organization_streams_path, notice: 'Stream was successfully destroyed.', status: :see_other }
format.json { head :no_content }
end
end
Expand All @@ -63,7 +63,7 @@ def make_default
@stream.make_default

respond_to do |format|
format.html { redirect_to @organization, notice: 'Stream was successfully updated.' }
format.html { redirect_to @organization, notice: 'Stream was successfully updated.', status: :see_other }
format.json { render :show, status: :ok, location: @organization }
end
end
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def new; end
def create
respond_to do |format|
if @upload.save
format.html { redirect_to [@organization, @upload], notice: 'Upload was successfully created.' }
format.html { redirect_to [@organization, @upload], notice: 'Upload was successfully created.', status: :see_other }
format.json { render :show, status: :created, location: [@organization, @upload] }
else
format.html { render :new }
Expand All @@ -43,7 +43,7 @@ def create
def update
respond_to do |format|
if @upload.update(upload_params)
format.html { redirect_to [@organization, @upload], notice: 'Upload was successfully updated.' }
format.html { redirect_to [@organization, @upload], notice: 'Upload was successfully updated.', status: :see_other }
format.json { render :show, status: :ok, location: [@organization, @upload] }
else
format.html { render :edit }
Expand All @@ -57,7 +57,9 @@ def update
def destroy
@upload.destroy
respond_to do |format|
format.html { redirect_to organization_uploads_url(@organization), notice: 'Upload was successfully destroyed.' }
format.html do
redirect_to organization_uploads_url(@organization), notice: 'Upload was successfully destroyed.', status: :see_other
end
format.json { head :no_content }
end
end
Expand Down
7 changes: 2 additions & 5 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import Rails from '@rails/ujs';
import Turbolinks from 'turbolinks';
import * as ActiveStorage from "@rails/activestorage";
import LocalTime from "local-time"
Rails.start();
Turbolinks.start();
ActiveStorage.start();
LocalTime.start()

Expand All @@ -13,4 +9,5 @@ import 'direct_uploads';
import 'pod_console';
import 'copy_to_clipboard';
import 'organizations';
import 'tooltips'
import 'tooltips'
import "@hotwired/turbo-rails"
6 changes: 3 additions & 3 deletions app/javascript/tooltips.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as bootstrap from 'bootstrap';

// Enable bootstrap tooltips, with localized time content if applicable
document.addEventListener('turbolinks:load', function() {
document.addEventListener('turbo:load', function() {
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
// Find any hidden time DOM elements within this tooltip
var times = [].slice.call(tooltipTriggerEl.querySelectorAll('.hidden-tooltip-time[data-localized]'))
var text = ""
// Construct the tooltip text
// See application_helper.js
times.forEach(function (timeEl) {
times.forEach(function (timeEl) {
if (timeEl.classList.contains('default')) {
text = text + ("Default since " + timeEl.innerHTML + "<br/>")
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/allowlisted_jwts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</td>
<td class="text-end">
<button class='btn btn-primary copy-token-button' id="copy-token-button-<%= index %>"><%= bootstrap_icon('files', class: 'pod-icon') %> Copy</button>
<%= link_to 'Revoke', [@organization, token], method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' if can? :destroy, token %>
<%= link_to 'Revoke', [@organization, token], data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }, class: 'btn btn-danger' if can? :destroy, token %>
</td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@

<div class='user-profile-section'>
<h2>Cancel account</h2>
<%= button_to "Cancel my account", registration_path(resource_name), id: 'cancel_form', class: 'btn btn-danger', data: { confirm: "Are you sure you want to delete your account?" }, method: :delete %>
<%= button_to "Cancel my account", registration_path(resource_name), id: 'cancel_form', class: 'btn btn-danger', data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete your account?" } %>
</div>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbo-track': 'reload' %>
<%= favicon_link_tag 'favicon.svg' %>
<%= content_for(:head) %>
<%= javascript_importmap_tags %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/organization_users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
<td class="text-center align-middle">
<div class="form-check form-switch align-middle d-inline-block">
<% if user.roles.map{|r| r['name']}.include? "owner" %>
<%= link_to '', organization_user_path(@organization, user, remove_role: 'owner'), method: :patch, data: { confirm: t('organization_users.index.confirm_action') }, class: 'form-check-input checked', title: t('organization_users.index.remove_owner') %>
<%= link_to '', organization_user_path(@organization, user, remove_role: 'owner'), data: { turbo_method: :patch, turbo_confirm: t('organization_users.index.confirm_action') }, class: 'form-check-input checked', title: t('organization_users.index.remove_owner') %>
<input class="form-check-input pe-none" type="checkbox" aria-hidden="true" checked>
<% else %>
<%= link_to '', organization_user_path(@organization, user, add_role: 'owner'), method: :patch, data: { confirm: t('organization_users.index.confirm_action') }, class: 'form-check-input', title: t('organization_users.index.add_owner') %>
<%= link_to '', organization_user_path(@organization, user, add_role: 'owner'), data: { turbo_method: :patch, turbo_confirm: t('organization_users.index.confirm_action') }, class: 'form-check-input', title: t('organization_users.index.add_owner') %>
<% end %>
</div>
</td>
<td class="align-middle text-center">
<%= link_to t('organization_users.index.remove_user'), organization_user_path(@organization, user), method: :delete, data: { confirm: t('organization_users.index.confirm_action') }, class: 'btn btn-danger btn-sm' %>
<%= link_to t('organization_users.index.remove_user'), organization_user_path(@organization, user), data: { turbo_method: :delete, turbo_confirm: t('organization_users.index.confirm_action') }, class: 'btn btn-danger btn-sm' %>
</td>
<% else %>
<td class="align-middle">
Expand Down
4 changes: 2 additions & 2 deletions app/views/organizations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</td>
<% if can? :manage, Organization %>
<td class="align-middle"><%= link_to 'Edit', organization_details_organization_path(organization), class: 'btn btn-secondary btn-sm' if can? :edit, organization %></td>
<td class="align-middle"><%= link_to 'Delete', organization, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' if can? :destroy, organization %></td>
<td class="align-middle"><%= link_to 'Delete', organization, data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' if can? :destroy, organization %></td>
<% end %>

</tr>
Expand Down Expand Up @@ -81,7 +81,7 @@

<% if can? :manage, Organization %>
<td class="align-middle"><%= link_to 'Edit', organization_details_organization_path(organization), class: 'btn btn-secondary btn-sm' if can? :edit, organization %></td>
<td class="align-middle"><%= link_to 'Delete', organization, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' if can? :destroy, organization %></td>
<td class="align-middle"><%= link_to 'Delete', organization, data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' if can? :destroy, organization %></td>
<% end %>

</tr>
Expand Down
Loading

0 comments on commit 20950fe

Please sign in to comment.