From b9e9cdb6dfb0ad6f008f70d02c97c310ba27361c Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Sun, 11 Aug 2024 19:59:44 +0900 Subject: [PATCH 01/22] Refactor codebase and adjust packages for Turbo-rails integration. This commit revises the project's files for integration with Turbo-rails. It involves changes to Gemfile, Gemfile.lock to set specific versions of 'turbo-rails' and comment out 'turbolinks'. JavaScript files have been refactored to replace 'turbolinks' with '@hotwired/turbo-rails'. Changes in controllers and views streamline the streaming process and rasterization strategy for the admin track view. Various codebases were simplified and cleaned up as well. The 'stimulus' package was removed as it's no longer necessary with the new Turbo-rails integration. Modifications made to package.json reflect these changes. The transition to Turbo-rails provides a more efficient drive for Rails applications, benefiting overall project performance. --- Gemfile | 5 +- Gemfile.lock | 6 +- app/controllers/admin/talks_controller.rb | 57 +-- app/javascript/controllers/index.js | 9 - app/javascript/packs/application.js | 9 +- app/javascript/packs/cicd2021.js | 6 +- app/javascript/packs/cndf2023.js | 6 +- app/javascript/packs/cndo2021.js | 6 +- app/javascript/packs/cnds2024.js | 5 +- app/javascript/packs/cndt2023.js | 6 +- .../admin/talks/start_on_air.turbo_stream.erb | 15 +- .../admin/talks/stop_on_air.turbo_stream.erb | 15 +- app/views/admin/tracks/_tracks_nav.html.erb | 60 ++- app/views/admin/tracks/index.html.erb | 4 +- app/views/admin/tracks/index.js.erb | 5 - app/views/admin/tracks/index.turbo_stream.erb | 0 .../admin/tracks/partial/_messages.html.erb | 8 +- .../tracks/partial/_on_air_button.html.erb | 17 + .../admin/tracks/partial/_talks_table.erb | 73 ---- app/views/layouts/application.html.erb | 3 +- package.json | 4 +- webpack.config.js | 2 +- yarn.lock | 378 ++++++++---------- 23 files changed, 310 insertions(+), 389 deletions(-) delete mode 100644 app/javascript/controllers/index.js delete mode 100644 app/views/admin/tracks/index.js.erb delete mode 100644 app/views/admin/tracks/index.turbo_stream.erb create mode 100644 app/views/admin/tracks/partial/_on_air_button.html.erb delete mode 100644 app/views/admin/tracks/partial/_talks_table.erb diff --git a/Gemfile b/Gemfile index 4533c23eb..a71f45d1e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,9 +7,6 @@ gem 'rails', '~> 7.0.5' gem 'puma', '~> 6.0' # Use SCSS for stylesheets gem 'sass-rails', '>= 6' -# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker -# 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.11' gem 'jsbundling-rails' @@ -116,7 +113,7 @@ gem "aws-sdk-ssm" gem 'active_hash' -gem "turbo-rails" +gem "turbo-rails", "2.0.5" gem 'slack-ruby-client' diff --git a/Gemfile.lock b/Gemfile.lock index a52ad44aa..af5febca6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -657,9 +657,6 @@ GEM actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) - turbolinks (5.2.1) - turbolinks-source (~> 5.2) - turbolinks-source (5.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) @@ -746,8 +743,7 @@ DEPENDENCIES slack-ruby-client stackprof steep - turbo-rails - turbolinks (~> 5) + turbo-rails (= 2.0.5) tzinfo-data uppy-s3_multipart (~> 1.0) web-console (>= 3.3.0) diff --git a/app/controllers/admin/talks_controller.rb b/app/controllers/admin/talks_controller.rb index c5640be03..0fd92eaae 100644 --- a/app/controllers/admin/talks_controller.rb +++ b/app/controllers/admin/talks_controller.rb @@ -22,63 +22,34 @@ def update_talks end def start_on_air - date = params[:talk][:date] - track_name = params[:talk][:track_name] - talk = Talk.find(params[:talk][:id]) + @talk = Talk.find(params[:talk][:id]) respond_to do |format| - on_air_talks_of_other_days = talk.track.talks.includes([:conference_day, :video]).accepted_and_intermission.reject { |t| t.conference_day.id == talk.conference_day.id }.select { |t| t.video.on_air? } + on_air_talks_of_other_days = @talk.track.talks.includes([:conference_day, :video]).accepted_and_intermission.reject { |t| t.conference_day.id == @talk.conference_day.id }.select { |t| t.video.on_air? } if on_air_talks_of_other_days.size.positive? - format.html { - update_variables_for_tracks(talk) - redirect_to(admin_tracks_path(date:, track_name:), alert: "Talk id=#{on_air_talks_of_other_days.map(&:id).join(',')} are already on_air.") + format.turbo_stream { + flash[:alert] = "Talk id=#{on_air_talks_of_other_days.map(&:id).join(',')} are already on_air." + # render(partial: 'admin/tracks/partial/on_air_button', locals: { talk: @talk }) } - # format.turbo_stream { - # update_variables_for_tracks(talk) - # flash[:alert] = "Talk id=#{on_air_talks_of_other_days.map(&:id).join(',')} are already on_air." - # } else - talk.start_streaming - format.html { - update_variables_for_tracks(talk) - redirect_to(admin_tracks_path(date:, track_name:), notice: "OnAirに切り替えました: #{talk.start_to_end} #{talk.speaker_names.join(',')} #{talk.title}") + @talk.start_streaming + format.turbo_stream { + flash[:notice] = "OnAirに切り替えました: #{@talk.start_to_end} #{@talk.speaker_names.join(',')} #{@talk.title}" + # render(partial: 'admin/tracks/partial/on_air_button', locals: { talk: @talk }) } - # format.turbo_stream { - # update_variables_for_tracks(talk) - # flash[:notice] = "OnAirに切り替えました: #{talk.start_to_end} #{talk.speaker_names.join(',')} #{talk.title}" - # } end end end def stop_on_air - date = params[:talk][:date] - track_name = params[:talk][:track_name] - talk = Talk.find(params[:talk][:id]) - talk.stop_streaming - @conference_day = talk.conference_day - @track = talk.track - @talks = talk.track - .talks - .where(conference_day_id: talk.conference_day.id, track_id: talk.track.id) - .order('conference_day_id ASC, start_time ASC, track_id ASC').includes(:video, :speakers, :conference_day, :track) + @talk = Talk.find(params[:talk][:id]) + @talk.stop_streaming respond_to do |format| - format.html { - redirect_to(admin_tracks_path(date:, track_name:), notice: "Waiting に切り替えました: #{talk.start_to_end} #{talk.speaker_names.join(',')} #{talk.title}") + format.turbo_stream { + flash.now[:notice] = "Waitingに切り替えました: #{@talk.start_to_end} #{@talk.speaker_names.join(',')} #{@talk.title}" + # render(partial: 'admin/tracks/partial/on_air_button', locals: { talk: @talk }) } - # format.turbo_stream { - # flash[:notice] = "Waiting に切り替えました: #{talk.start_to_end} #{talk.speaker_names.join(',')} #{talk.title}" - # } end end - - private - - def update_variables_for_tracks(talk) - @conference_day = talk.conference_day - @track = talk.track - @talks = Talk.all.where(conference_day_id: @conference_day.id, track_id: @track.id) - .order('conference_day_id ASC, start_time ASC, track_id ASC').includes(:video, :speakers, :conference_day, :track) - end end diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js deleted file mode 100644 index 6f53d84bb..000000000 --- a/app/javascript/controllers/index.js +++ /dev/null @@ -1,9 +0,0 @@ -// Load all the controllers within this directory and all subdirectories. -// Controller files must be named *_controller.js. - -import { Application } from "stimulus" -import { definitionsFromContext } from "stimulus/webpack-helpers" - -const application = Application.start() -const context = require.context("controllers", true, /_controller\.js$/) -application.load(definitionsFromContext(context)) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index ce44abac1..608b01bcb 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -3,8 +3,9 @@ // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. -require("@rails/ujs").start() -require("turbolinks").start() +import "@hotwired/turbo-rails" +Turbo.session.drive = false +// import "./controllers/index.js" // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) @@ -27,7 +28,3 @@ import './cropbox.js' import './copy.js' //require.context('images/cndo201', true, /\.(png|jpg|jpeg|svg)$/) - -// import 'regenerator-runtime/runtime' -// import "@hotwired/turbo-rails" -// import "controllers" diff --git a/app/javascript/packs/cicd2021.js b/app/javascript/packs/cicd2021.js index cb53b6cbf..3f5a8411a 100644 --- a/app/javascript/packs/cicd2021.js +++ b/app/javascript/packs/cicd2021.js @@ -3,8 +3,10 @@ // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. -require("@rails/ujs").start() -require("turbolinks").start() +import Rails from "@rails/ujs" +import "@hotwired/turbo-rails" + +Rails.start() // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) diff --git a/app/javascript/packs/cndf2023.js b/app/javascript/packs/cndf2023.js index 390334b40..fb98ff01c 100644 --- a/app/javascript/packs/cndf2023.js +++ b/app/javascript/packs/cndf2023.js @@ -3,8 +3,10 @@ // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. -require("@rails/ujs").start() -require("turbolinks").start() +import Rails from "@rails/ujs" +import "@hotwired/turbo-rails" + +Rails.start() // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) diff --git a/app/javascript/packs/cndo2021.js b/app/javascript/packs/cndo2021.js index 5b6194f95..7786524d9 100644 --- a/app/javascript/packs/cndo2021.js +++ b/app/javascript/packs/cndo2021.js @@ -3,8 +3,10 @@ // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. -require("@rails/ujs").start() -require("turbolinks").start() +import Rails from "@rails/ujs" +import "@hotwired/turbo-rails" + +Rails.start() // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) diff --git a/app/javascript/packs/cnds2024.js b/app/javascript/packs/cnds2024.js index 17a617a01..511d95098 100644 --- a/app/javascript/packs/cnds2024.js +++ b/app/javascript/packs/cnds2024.js @@ -3,8 +3,9 @@ // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. -require("@rails/ujs").start() -require("turbolinks").start() +import "@hotwired/turbo-rails" +Turbo.session.drive = false +// import "./controllers/index.js" // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) diff --git a/app/javascript/packs/cndt2023.js b/app/javascript/packs/cndt2023.js index 5f4751d1e..d8dde3497 100644 --- a/app/javascript/packs/cndt2023.js +++ b/app/javascript/packs/cndt2023.js @@ -3,8 +3,10 @@ // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. -require("@rails/ujs").start() -require("turbolinks").start() +import Rails from "@rails/ujs" +import "@hotwired/turbo-rails" + +Rails.start() // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) diff --git a/app/views/admin/talks/start_on_air.turbo_stream.erb b/app/views/admin/talks/start_on_air.turbo_stream.erb index 1c2edd2e8..081f1d74f 100644 --- a/app/views/admin/talks/start_on_air.turbo_stream.erb +++ b/app/views/admin/talks/start_on_air.turbo_stream.erb @@ -1,8 +1,7 @@ -<%= turbo_stream.prepend "messages", partial: 'admin/tracks/partial/messages' %> -<%= turbo_stream.update "talks", - partial: 'admin/tracks/partial/talks_table', - locals: { - conference_day: @conference_day, - talks: @talks, - track: @track - } %> +<%= turbo_stream.prepend "messages" do %> + <%= render partial: 'admin/tracks/partial/messages' %> +<% end %> + +<%= turbo_stream.replace "talk_#{@talk.id}" do %> + <%= render partial: 'admin/tracks/partial/on_air_button', locals: { talk: @talk } %> +<% end %> diff --git a/app/views/admin/talks/stop_on_air.turbo_stream.erb b/app/views/admin/talks/stop_on_air.turbo_stream.erb index 1c2edd2e8..081f1d74f 100644 --- a/app/views/admin/talks/stop_on_air.turbo_stream.erb +++ b/app/views/admin/talks/stop_on_air.turbo_stream.erb @@ -1,8 +1,7 @@ -<%= turbo_stream.prepend "messages", partial: 'admin/tracks/partial/messages' %> -<%= turbo_stream.update "talks", - partial: 'admin/tracks/partial/talks_table', - locals: { - conference_day: @conference_day, - talks: @talks, - track: @track - } %> +<%= turbo_stream.prepend "messages" do %> + <%= render partial: 'admin/tracks/partial/messages' %> +<% end %> + +<%= turbo_stream.replace "talk_#{@talk.id}" do %> + <%= render partial: 'admin/tracks/partial/on_air_button', locals: { talk: @talk } %> +<% end %> diff --git a/app/views/admin/tracks/_tracks_nav.html.erb b/app/views/admin/tracks/_tracks_nav.html.erb index 0e3bcda3b..78d304e81 100644 --- a/app/views/admin/tracks/_tracks_nav.html.erb +++ b/app/views/admin/tracks/_tracks_nav.html.erb @@ -14,7 +14,65 @@ -<%= render partial: 'admin/tracks/partial/talks_table', locals: {conference_day: conference_day, talks: @talks, track: @track}%> +<%= turbo_frame_tag 'talks', src: @talks.nil? ? admin_talks_path : nil do %> + + + + + + + + + + + + + + <% @talks.each do |talk| %> + + + + + + + + + <% end %> + + +
IDTimeSpeakers
Title
On AirRecordingRecording Status
<%= talk.id %> + Planned
+ <%= text_field_tag(talk.id.to_s + "_planned_start", talk.start_time.strftime('%H:%M'), {disabled: true, size: 1}) %>- + <%= text_field_tag(talk.id.to_s + "_planned_end", talk.end_time.strftime('%H:%M'), {disabled: true, size: 1}) %> +
+ Offset
+ <%= text_field_tag("time[][#{talk.id.to_s}][startOffset]", talk.start_offset.to_s, {size: 1, form: 'time', class: 'start-offset'}) %>- + <%= text_field_tag("time[][#{talk.id.to_s}][endOffset]", talk.end_offset.to_s, {size: 1, form: 'time'}) %> +
+ Actual
+ <%= text_field_tag(talk.id.to_s + "_actual_start", talk.actual_start_time.strftime('%H:%M'), {disabled: true, size: 1}) %>- + <%= text_field_tag(talk.id.to_s + "_actual_end", talk.actual_end_time.strftime('%H:%M'), {disabled: true, size: 1}) %> +
+
<%= talk.title %>
+
    <% talk.speakers.each do |speaker| %>
  • <%= speaker.name %>
  • <% end %>
+
+ <% if talk.video %> + <%= render('admin/tracks/partial/on_air_button', talk: talk) %> + <% end %> + + <% if talk.abstract != 'intermission' && talk.live? && talk.recordable? %> + <%= link_to "録画する", new_admin_harvest_job_path(talk_id: talk.id) %> + <% end %> + + <% if talk.video && talk.abstract != 'intermission' %> + <% if already_recorded?(talk) %> +
録画済み
+ <% else %> + 未録画 + <% end %> + <% end %> +
+<% end %> ※ Track video ID は On Air 状態のセッションがUIで表示された時に使われる (ライブ)
※ 各セッションの Video URL は Off Air 状態のセッションがUIで表示された時に使われる (アーカイブ) diff --git a/app/views/admin/tracks/index.html.erb b/app/views/admin/tracks/index.html.erb index e573b7b17..06ec6ecd9 100644 --- a/app/views/admin/tracks/index.html.erb +++ b/app/views/admin/tracks/index.html.erb @@ -22,7 +22,9 @@ diff --git a/app/views/admin/tracks/index.js.erb b/app/views/admin/tracks/index.js.erb deleted file mode 100644 index de40d64fa..000000000 --- a/app/views/admin/tracks/index.js.erb +++ /dev/null @@ -1,5 +0,0 @@ -$("#messages").html('<%= j(render partial: 'admin/tracks/partial/messages', locals: {flash: flash}) %>'); - -recording_group_target = document.getElementById('talks_table_tbody'); -html = "<%= j(render partial: 'admin/tracks/partial/talks_table', locals: {conference_day: @conference_day, talks: @talks, track: @track}) %>" -recording_group_target.innerHTML = html diff --git a/app/views/admin/tracks/index.turbo_stream.erb b/app/views/admin/tracks/index.turbo_stream.erb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/views/admin/tracks/partial/_messages.html.erb b/app/views/admin/tracks/partial/_messages.html.erb index 749e9e4ae..7f1404edb 100644 --- a/app/views/admin/tracks/partial/_messages.html.erb +++ b/app/views/admin/tracks/partial/_messages.html.erb @@ -1,8 +1,6 @@ <% flash.each do |message_type, message| %> - diff --git a/app/views/admin/show.html.erb b/app/views/admin/show.html.erb index 4d353d593..7d78d971e 100644 --- a/app/views/admin/show.html.erb +++ b/app/views/admin/show.html.erb @@ -6,17 +6,59 @@ <% end %>

<%= @conference.name %>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldValue
カンファレンスステータス<%= @conference.conference_status %>
リハーサルモード<%= @conference.rehearsal_mode ? 'オン' : 'オフ' %>
CFPの結果公開<%= @conference.cfp_result_visible ? '公開' : '非公開' %>
登壇者のエントリー<%= @conference.speaker_entry %>
参加者の申し込み<%= @conference.attendee_entry %>
タイムテーブルを表示<%= @conference.show_timetable %>
現地参加定員<%= @conference.capacity %>
Contact Url<%= @conference.contact_url %>
Sponsor Guideline Url<%= link_to @conference.sponsor_guideline_url, @conference.sponsor_guideline_url, target: '_blank' %>
スポンサーを表示<%= @conference.show_sponsors ? '表示' : '非表示' %>
+ <%= link_to 'Edit', edit_admin_conference_path(id: @conference.id), class: 'btn btn-primary' %> From 2f80185b380adf35d88f3b9613a5593f8e1a4ba6 Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Mon, 12 Aug 2024 00:57:45 +0900 Subject: [PATCH 04/22] chore: use turbo streams for check in --- .../admin/check_in_events_controller.rb | 22 +++--- .../check_in_events/create.turbo_stream.erb | 11 +++ .../destroy_all.turbo_stream.erb | 11 +++ app/views/admin/profiles/index.html.erb | 69 +++++++++---------- .../partial/_check_in_button.html.erb | 14 ++++ .../partial/_check_in_status.html.erb | 3 + .../admin/profiles/partial/_messages.html.erb | 6 ++ config/routes.rb | 2 +- 8 files changed, 91 insertions(+), 47 deletions(-) create mode 100644 app/views/admin/check_in_events/create.turbo_stream.erb create mode 100644 app/views/admin/check_in_events/destroy_all.turbo_stream.erb create mode 100644 app/views/admin/profiles/partial/_check_in_button.html.erb create mode 100644 app/views/admin/profiles/partial/_check_in_status.html.erb create mode 100644 app/views/admin/profiles/partial/_messages.html.erb diff --git a/app/controllers/admin/check_in_events_controller.rb b/app/controllers/admin/check_in_events_controller.rb index df57a28e2..3480a095e 100644 --- a/app/controllers/admin/check_in_events_controller.rb +++ b/app/controllers/admin/check_in_events_controller.rb @@ -5,10 +5,13 @@ def create @check_in = CheckInConference.new(check_in_events_params.merge(conference_id: conference.id, check_in_timestamp: DateTime.now)) @profile = Profile.find(@check_in.profile_id) - if @check_in.save - redirect_back(fallback_location: "#{conference.abbr}/admin", allow_other_host: false) - else - redirect_back(fallback_location: "#{conference.abbr}/admin", allow_other_host: false, notice: "#{@profile.last_name} #{@profile.first_name} のチェックインに失敗しました") + respond_to do |format| + if @check_in.save + flash.now[:notice] = "#{@profile.last_name} #{@profile.first_name} をチェックインしました" + else + flash.now[:alert] = "#{@profile.last_name} #{@profile.first_name} のチェックインに失敗しました" + end + format.turbo_stream end end @@ -16,10 +19,13 @@ def destroy_all @check_ins = CheckInConference.where(profile_id: check_in_events_params[:profile_id], conference_id: conference.id) @profile = Profile.find(check_in_events_params[:profile_id]) - if @check_ins.map(&:destroy!) - redirect_back(fallback_location: "#{conference.abbr}/admin") - else - redirect_back(fallback_location: "#{conference.abbr}/admin", notice: "#{@profile.last_name} #{@profile.first_name} のチェックインキャンセルに失敗しました") + respond_to do |format| + if @check_ins.map(&:destroy!) + flash.now[:notice] = "#{@profile.last_name} #{@profile.first_name} のチェックインをキャンセルしました" + else + flash.now[:alert] = "#{@profile.last_name} #{@profile.first_name} のチェックインキャンセルに失敗しました" + end + format.turbo_stream end end diff --git a/app/views/admin/check_in_events/create.turbo_stream.erb b/app/views/admin/check_in_events/create.turbo_stream.erb new file mode 100644 index 000000000..1e822a274 --- /dev/null +++ b/app/views/admin/check_in_events/create.turbo_stream.erb @@ -0,0 +1,11 @@ +<%= turbo_stream.prepend "messages" do %> + <%= render partial: 'admin/tracks/partial/messages' %> +<% end %> + +<%= turbo_stream.replace "check_in_status_#{@profile.id}" do %> + <%= render partial: 'admin/profiles/partial/check_in_status', locals: { profile: @profile } %> +<% end %> + +<%= turbo_stream.replace "profile_#{@profile.id}" do %> + <%= render partial: 'admin/profiles/partial/check_in_button', locals: { profile: @profile } %> +<% end %> diff --git a/app/views/admin/check_in_events/destroy_all.turbo_stream.erb b/app/views/admin/check_in_events/destroy_all.turbo_stream.erb new file mode 100644 index 000000000..1e822a274 --- /dev/null +++ b/app/views/admin/check_in_events/destroy_all.turbo_stream.erb @@ -0,0 +1,11 @@ +<%= turbo_stream.prepend "messages" do %> + <%= render partial: 'admin/tracks/partial/messages' %> +<% end %> + +<%= turbo_stream.replace "check_in_status_#{@profile.id}" do %> + <%= render partial: 'admin/profiles/partial/check_in_status', locals: { profile: @profile } %> +<% end %> + +<%= turbo_stream.replace "profile_#{@profile.id}" do %> + <%= render partial: 'admin/profiles/partial/check_in_button', locals: { profile: @profile } %> +<% end %> diff --git a/app/views/admin/profiles/index.html.erb b/app/views/admin/profiles/index.html.erb index 362f68ac2..84af2fef6 100644 --- a/app/views/admin/profiles/index.html.erb +++ b/app/views/admin/profiles/index.html.erb @@ -1,4 +1,8 @@ <%= render 'admin/layout' do %> +
+ <%= render 'admin/profiles/partial/messages' %> +
+

Registered users

@@ -11,44 +15,33 @@
- - - - - - - - - - - - - - <% @profiles.each do |profile| %> + <%= turbo_frame_tag 'profiles' do %> +
NameName(Kana)登録に用いたEmail参加方法二次元バーコードチェックイン状況
+ - - - - - - - + + + + + + + - <% end %> - -
<%= profile.last_name %> <%= profile.first_name %><%= profile.last_name_kana %> <%= profile.first_name_kana %><%= profile.email %><%= Profile.participations[profile.participation] %><%= link_to 'QRコードを表示する', admin_entry_sheet_path(id: profile.id) %><%= profile.check_in_conferences.present? ? profile.check_in_conferences.first.created_at : "未チェックイン" %> - <% if profile.check_in_conferences.nil? || profile.check_in_conferences.empty? %> - <%= form_with(url: admin_check_in_events_path, method: "post", remote: true) do |f| %> - <%= f.hidden_field "check_in_event[profile_id]", value: profile.id %> - <%= f.submit 'チェックイン', data: { confirm: "#{profile.last_name} #{profile.first_name} をチェックインする"} %> - <% end %> - <% else %> - チェックイン済み - <%= form_with(url: admin_check_in_events_path, method: "delete", remote: true) do |f| %> - <%= f.hidden_field "check_in_event[profile_id]", value: profile.id %> - <%= f.submit '(チェックインをキャンセル)', data: { confirm: "#{profile.last_name} #{profile.first_name} のイベントへのチェックインをキャンセルしますか?"} %> - <% end %> - <% end %> - NameName(Kana)登録に用いたEmail参加方法二次元バーコードチェックイン状況
-
+ + + <% @profiles.each do |profile| %> + + <%= profile.last_name %> <%= profile.first_name %> + <%= profile.last_name_kana %> <%= profile.first_name_kana %> + <%= profile.email %> + <%= Profile.participations[profile.participation] %> + <%= link_to 'QRコードを表示する', admin_entry_sheet_path(id: profile.id) %> + <%= render('admin/profiles/partial/check_in_status', profile: profile) %> + <%= render('admin/profiles/partial/check_in_button', profile: profile) %> + + <% end %> + + + + <% end %> <% end %> diff --git a/app/views/admin/profiles/partial/_check_in_button.html.erb b/app/views/admin/profiles/partial/_check_in_button.html.erb new file mode 100644 index 000000000..e1f0ef8e6 --- /dev/null +++ b/app/views/admin/profiles/partial/_check_in_button.html.erb @@ -0,0 +1,14 @@ +
+ <% if profile.check_in_conferences.nil? || profile.check_in_conferences.empty? %> + <%= form_with(url: admin_check_in_events_path, method: "post") do |f| %> + <%= f.hidden_field "check_in_event[profile_id]", value: profile.id %> + <%= f.submit 'チェックイン', data: { turbo_confirm: "#{profile.last_name} #{profile.first_name} をチェックインする"} %> + <% end %> + <% else %> + チェックイン済み + <%= form_with(url: admin_check_in_events_path, method: "delete", remote: true) do |f| %> + <%= f.hidden_field "check_in_event[profile_id]", value: profile.id %> + <%= f.submit '(チェックインをキャンセル)', data: { turbo_confirm: "#{profile.last_name} #{profile.first_name} のイベントへのチェックインをキャンセルしますか?"} %> + <% end %> + <% end %> +
diff --git a/app/views/admin/profiles/partial/_check_in_status.html.erb b/app/views/admin/profiles/partial/_check_in_status.html.erb new file mode 100644 index 000000000..0be98c250 --- /dev/null +++ b/app/views/admin/profiles/partial/_check_in_status.html.erb @@ -0,0 +1,3 @@ +
+ <%= profile.check_in_conferences.present? ? profile.check_in_conferences.first.created_at : "未チェックイン" %> +
diff --git a/app/views/admin/profiles/partial/_messages.html.erb b/app/views/admin/profiles/partial/_messages.html.erb new file mode 100644 index 000000000..7f1404edb --- /dev/null +++ b/app/views/admin/profiles/partial/_messages.html.erb @@ -0,0 +1,6 @@ +<% flash.each do |message_type, message| %> + +<% end %> diff --git a/config/routes.rb b/config/routes.rb index a890ad2d2..e4ed14934 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,7 +56,7 @@ get 'export_speakers' => 'speakers#export_speakers' get 'export_profiles' => 'profiles#export_profiles' get 'speaker_check_in_statuses' => 'speakers#check_in_statuses' - resources :check_in_events, only: [:create] + resources :check_in_events, only: [:create, :destroy] delete 'check_in_events' => 'check_in_events#destroy_all' resources :talks, only: [:index] resources :rooms, only: [:index, :update] From 0aa07fe6d4623f9056da8daacdcf4d8960c75bef Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Sat, 17 Aug 2024 09:55:32 +0900 Subject: [PATCH 05/22] chore: remove jQuery package --- package.json | 1 - yarn.lock | 5 ----- 2 files changed, 6 deletions(-) diff --git a/package.json b/package.json index 5cc439540..59e1257d6 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "cropperjs": "1.6.2", "css-loader": "^7.1.2", "file-loader": "^6.2.0", - "jquery": "3.7.1", "mini-css-extract-plugin": "^2.9.0", "nodemon": "^3.1.4", "particles.js": "^2.0.0", diff --git a/yarn.lock b/yarn.lock index d68f381bd..765c8ea0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1146,11 +1146,6 @@ jest-worker@^27.4.5: merge-stream "^2.0.0" supports-color "^8.0.0" -jquery@3.7.1: - version "3.7.1" - resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.7.1.tgz#083ef98927c9a6a74d05a6af02806566d16274de" - integrity sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg== - json-parse-even-better-errors@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d" From 22672d3ee1364ab28a17b26738528648397b2746 Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Sat, 17 Aug 2024 10:34:09 +0900 Subject: [PATCH 06/22] remove jquery import --- app/javascript/packs/application.js | 4 ---- app/javascript/packs/cicd2021.js | 12 +++++------- app/javascript/packs/cndf2023.js | 11 +++++++---- app/javascript/packs/cndo2021.js | 2 -- app/javascript/packs/cnds2024.js | 2 -- app/javascript/packs/cndt2023.js | 10 ++++++---- webpack.config.js | 4 ---- 7 files changed, 18 insertions(+), 27 deletions(-) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index bde69e84f..3c5a38f2d 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -14,14 +14,10 @@ Turbo.session.drive = false // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) // import '../stylesheets/application' -import $ from 'jquery' import './bootstrap_custom.js' -window.jQuery = $ -import './scripts.js' import './timetable.js' import './talks.js' import './conference_form.js' - import './contents.js' import './speaker_form.js' import './cropbox.js' diff --git a/app/javascript/packs/cicd2021.js b/app/javascript/packs/cicd2021.js index 89d4068bf..c9a92f182 100644 --- a/app/javascript/packs/cicd2021.js +++ b/app/javascript/packs/cicd2021.js @@ -14,16 +14,14 @@ Rails.start() // // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) -import $ from 'jquery' +import '../stylesheets/cicd2021' import './bootstrap_custom.js' -window.jQuery = $ +import './utils' import './scripts.js' import './talks.js' +import './sponsor_form.js' import './conference_form.js' import './contents.js' -import './cropbox.js' -import './timetable.js' -import './attendee_dashboard.js' -import "particles.js"; -import './copy.js' import './speaker_form.js' + +require.context('images', true, /\.(png|jpg|jpeg|svg)$/) diff --git a/app/javascript/packs/cndf2023.js b/app/javascript/packs/cndf2023.js index 88636c3e9..c5b6bf04d 100644 --- a/app/javascript/packs/cndf2023.js +++ b/app/javascript/packs/cndf2023.js @@ -14,19 +14,22 @@ Rails.start() // // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) -import $ from 'jquery' +import '../stylesheets/cndf2023' import './bootstrap_custom.js' -window.jQuery = $ +import './utils' import './scripts.js' import './talks.js' +import './sponsor_form.js' import './conference_form.js' import './contents.js' +import './speaker_form.js' import './cropbox.js' import './timetable.js' import './attendee_dashboard.js' -import "particles.js"; import './copy.js' -import './speaker_form.js' + +require.context('images', true, /\.(png|jpg|jpeg|svg)$/) + // import 'regenerator-runtime/runtime' // import "@hotwired/turbo-rails" // import "controllers" diff --git a/app/javascript/packs/cndo2021.js b/app/javascript/packs/cndo2021.js index dc2315b0f..da4831bcb 100644 --- a/app/javascript/packs/cndo2021.js +++ b/app/javascript/packs/cndo2021.js @@ -15,9 +15,7 @@ Rails.start() // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) // import '../stylesheets/cndo2021' -import $ from 'jquery' import './bootstrap_custom.js' -window.jQuery = $ import './scripts.js' import './talks.js' import './conference_form.js' diff --git a/app/javascript/packs/cnds2024.js b/app/javascript/packs/cnds2024.js index e102999a0..349d6219e 100644 --- a/app/javascript/packs/cnds2024.js +++ b/app/javascript/packs/cnds2024.js @@ -14,9 +14,7 @@ Turbo.session.drive = false // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) // import '../stylesheets/cnds2024' -import $ from 'jquery' import './bootstrap_custom.js' -window.jQuery = $ import './scripts.js' import './talks.js' import './conference_form.js' diff --git a/app/javascript/packs/cndt2023.js b/app/javascript/packs/cndt2023.js index af5b0c188..366f6f8aa 100644 --- a/app/javascript/packs/cndt2023.js +++ b/app/javascript/packs/cndt2023.js @@ -14,19 +14,21 @@ Rails.start() // // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) -import $ from 'jquery' +import '../stylesheets/cndt2023' import './bootstrap_custom.js' -window.jQuery = $ +import './utils' import './scripts.js' import './talks.js' +import './sponsor_form.js' import './conference_form.js' import './contents.js' import './cropbox.js' import './timetable.js' import './attendee_dashboard.js' -import "particles.js"; +import './particles.min.js' import './copy.js' -import './speaker_form.js' + +require.context('images', true, /\.(png|jpg|jpeg|svg)$/) // import 'regenerator-runtime/runtime' // import "@hotwired/turbo-rails" diff --git a/webpack.config.js b/webpack.config.js index 24403e5ac..28a11f656 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -94,9 +94,5 @@ module.exports = { }), new RemoveEmptyScriptsPlugin(), new MiniCssExtractPlugin(), - new webpack.ProvidePlugin({ - $: 'jquery', - jQuery: 'jquery' - }) ] } From 8d926696d1feb91815309829031337b4867cdce3 Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Sat, 17 Aug 2024 10:35:39 +0900 Subject: [PATCH 07/22] migrate attendee_dashboard.js to stimulus --- app/javascript/packs/attendee_dashboard.js | 4 ---- app/javascript/packs/cndf2023.js | 2 +- app/javascript/packs/cndo2021.js | 1 - app/javascript/packs/cnds2024.js | 3 +-- app/javascript/packs/cndt2023.js | 1 - app/javascript/packs/controllers/application.js | 12 ++++++++++++ app/javascript/packs/controllers/index.js | 14 ++++++++++++++ .../controllers/share_registration_controller.js | 10 ++++++++++ app/views/attendee_dashboards/show.html.erb | 6 +++--- package.json | 2 ++ yarn.lock | 10 ++++++++++ 11 files changed, 53 insertions(+), 12 deletions(-) delete mode 100644 app/javascript/packs/attendee_dashboard.js create mode 100644 app/javascript/packs/controllers/application.js create mode 100644 app/javascript/packs/controllers/index.js create mode 100644 app/javascript/packs/controllers/share_registration_controller.js diff --git a/app/javascript/packs/attendee_dashboard.js b/app/javascript/packs/attendee_dashboard.js deleted file mode 100644 index 819a1adcd..000000000 --- a/app/javascript/packs/attendee_dashboard.js +++ /dev/null @@ -1,4 +0,0 @@ -$(document).on('click', '#twitter_share', function(event) { - const content = document.getElementById("tweet_content") - window.open(`https://twitter.com/intent/tweet?text=${encodeURIComponent(content.value)}`); -}); diff --git a/app/javascript/packs/cndf2023.js b/app/javascript/packs/cndf2023.js index c5b6bf04d..b51dc6d3d 100644 --- a/app/javascript/packs/cndf2023.js +++ b/app/javascript/packs/cndf2023.js @@ -25,7 +25,7 @@ import './contents.js' import './speaker_form.js' import './cropbox.js' import './timetable.js' -import './attendee_dashboard.js' + import './copy.js' require.context('images', true, /\.(png|jpg|jpeg|svg)$/) diff --git a/app/javascript/packs/cndo2021.js b/app/javascript/packs/cndo2021.js index da4831bcb..b99dd3680 100644 --- a/app/javascript/packs/cndo2021.js +++ b/app/javascript/packs/cndo2021.js @@ -22,7 +22,6 @@ import './conference_form.js' import './contents.js' import './cropbox.js' import './timetable.js' -import './attendee_dashboard.js' import "particles.js"; import './copy.js' import './speaker_form.js' \ No newline at end of file diff --git a/app/javascript/packs/cnds2024.js b/app/javascript/packs/cnds2024.js index 349d6219e..93152cbf2 100644 --- a/app/javascript/packs/cnds2024.js +++ b/app/javascript/packs/cnds2024.js @@ -5,7 +5,7 @@ import "@hotwired/turbo-rails" Turbo.session.drive = false -// import "./controllers/index.js" +import "./controllers/index.js" // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) @@ -21,7 +21,6 @@ import './conference_form.js' import './contents.js' import './cropbox.js' import './timetable.js' -import './attendee_dashboard.js' import "particles.js"; import './copy.js' import './speaker_form.js' diff --git a/app/javascript/packs/cndt2023.js b/app/javascript/packs/cndt2023.js index 366f6f8aa..b5f441050 100644 --- a/app/javascript/packs/cndt2023.js +++ b/app/javascript/packs/cndt2023.js @@ -24,7 +24,6 @@ import './conference_form.js' import './contents.js' import './cropbox.js' import './timetable.js' -import './attendee_dashboard.js' import './particles.min.js' import './copy.js' diff --git a/app/javascript/packs/controllers/application.js b/app/javascript/packs/controllers/application.js new file mode 100644 index 000000000..3e85a580f --- /dev/null +++ b/app/javascript/packs/controllers/application.js @@ -0,0 +1,12 @@ +import { Application } from "@hotwired/stimulus" +import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers" + +const application = Application.start() +const context = require.context("./", true, /\.js$/) +application.load(definitionsFromContext(context)) + +// Configure Stimulus development experience +application.debug = true +window.Stimulus = application + +export { application } diff --git a/app/javascript/packs/controllers/index.js b/app/javascript/packs/controllers/index.js new file mode 100644 index 000000000..49b4e9e14 --- /dev/null +++ b/app/javascript/packs/controllers/index.js @@ -0,0 +1,14 @@ +// Import and register all your controllers from the importmap under controllers/* + +import { application } from "./application.js" + +// Eager load all controllers defined in the import map under controllers/**/*_controller +// import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +// eagerLoadControllersFrom("controllers", application) + +// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) +// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" +// lazyLoadControllersFrom("controllers", application) + +import ShareRegistrationController from "./share_registration_controller.js" +application.register("share-registration", ShareRegistrationController) diff --git a/app/javascript/packs/controllers/share_registration_controller.js b/app/javascript/packs/controllers/share_registration_controller.js new file mode 100644 index 000000000..86bf5ad2f --- /dev/null +++ b/app/javascript/packs/controllers/share_registration_controller.js @@ -0,0 +1,10 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + static targets = [ "tweet_content" ] + + windowOpen() { + const value = this.tweet_contentTarget.value + window.open(`https://twitter.com/intent/tweet?text=${encodeURIComponent(value)}`); + } +} diff --git a/app/views/attendee_dashboards/show.html.erb b/app/views/attendee_dashboards/show.html.erb index 983314b09..81dc2a292 100644 --- a/app/views/attendee_dashboards/show.html.erb +++ b/app/views/attendee_dashboards/show.html.erb @@ -79,17 +79,17 @@ <% end %>
-
+
X(Twitter)でシェアしよう!
- " /> + " />
- +
diff --git a/package.json b/package.json index 59e1257d6..38acda999 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,8 @@ "name": "cndtattend", "private": true, "dependencies": { + "@hotwired/stimulus": "^3.2.2", + "@hotwired/stimulus-webpack-helpers": "^1.0.1", "@hotwired/turbo-rails": "8.0.4", "@popperjs/core": "^2.11.8", "@rails/actioncable": "7.2.0", diff --git a/yarn.lock b/yarn.lock index 765c8ea0c..07d4aea25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14,6 +14,16 @@ resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70" integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw== +"@hotwired/stimulus-webpack-helpers@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@hotwired/stimulus-webpack-helpers/-/stimulus-webpack-helpers-1.0.1.tgz#4cd74487adeca576c9865ac2b9fe5cb20cef16dd" + integrity sha512-wa/zupVG0eWxRYJjC1IiPBdt3Lruv0RqGN+/DTMmUWUyMAEB27KXmVY6a8YpUVTM7QwVuaLNGW4EqDgrS2upXQ== + +"@hotwired/stimulus@^3.2.2": + version "3.2.2" + resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.2.2.tgz#071aab59c600fed95b97939e605ff261a4251608" + integrity sha512-eGeIqNOQpXoPAIP7tC1+1Yc1yl1xnwYqg+3mzqxyrbE5pg5YFBZcA6YoTiByJB6DKAEsiWtl6tjTJS4IYtbB7A== + "@hotwired/turbo-rails@8.0.4": version "8.0.4" resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-8.0.4.tgz#d224f524a9e33fe687cec5d706054eb6fe13fa5b" From 6abbd686217d262e2558c4c2697dd1d739187a70 Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Sat, 17 Aug 2024 10:36:02 +0900 Subject: [PATCH 08/22] Add turbo stream to append link fields in admin conferences This commit introduces a new Turbo Stream view for appending link fields in the admin conference section. It renders a partial to dynamically add link fields when needed. --- app/views/admin/conferences/add_link_field.turbo_stream.erb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/views/admin/conferences/add_link_field.turbo_stream.erb diff --git a/app/views/admin/conferences/add_link_field.turbo_stream.erb b/app/views/admin/conferences/add_link_field.turbo_stream.erb new file mode 100644 index 000000000..3969e6924 --- /dev/null +++ b/app/views/admin/conferences/add_link_field.turbo_stream.erb @@ -0,0 +1,3 @@ +<%= turbo_stream.append "link_fields" do %> + <%= render partial: 'admin/conferences/partial/link_fields' %> +<% end %> From 8b82b3606ca29a6f0cd51a0ac914b90e4ab0a38f Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Sat, 17 Aug 2024 10:56:57 +0900 Subject: [PATCH 09/22] chore: remove unused codes related to sponsors --- app/javascript/packs/cicd2021.js | 1 - app/javascript/packs/cndf2023.js | 1 - app/javascript/packs/cndt2023.js | 1 - 3 files changed, 3 deletions(-) diff --git a/app/javascript/packs/cicd2021.js b/app/javascript/packs/cicd2021.js index c9a92f182..00653f1f5 100644 --- a/app/javascript/packs/cicd2021.js +++ b/app/javascript/packs/cicd2021.js @@ -19,7 +19,6 @@ import './bootstrap_custom.js' import './utils' import './scripts.js' import './talks.js' -import './sponsor_form.js' import './conference_form.js' import './contents.js' import './speaker_form.js' diff --git a/app/javascript/packs/cndf2023.js b/app/javascript/packs/cndf2023.js index b51dc6d3d..54c3f394b 100644 --- a/app/javascript/packs/cndf2023.js +++ b/app/javascript/packs/cndf2023.js @@ -19,7 +19,6 @@ import './bootstrap_custom.js' import './utils' import './scripts.js' import './talks.js' -import './sponsor_form.js' import './conference_form.js' import './contents.js' import './speaker_form.js' diff --git a/app/javascript/packs/cndt2023.js b/app/javascript/packs/cndt2023.js index b5f441050..cb493718e 100644 --- a/app/javascript/packs/cndt2023.js +++ b/app/javascript/packs/cndt2023.js @@ -19,7 +19,6 @@ import './bootstrap_custom.js' import './utils' import './scripts.js' import './talks.js' -import './sponsor_form.js' import './conference_form.js' import './contents.js' import './cropbox.js' From 66b43a30955d69c6850d0c4f6802177d0adc6062 Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Sat, 17 Aug 2024 11:18:55 +0900 Subject: [PATCH 10/22] remove unused code --- app/helpers/application_helper.rb | 18 ------------------ app/javascript/packs/conference_form.js | 24 +----------------------- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b596e009f..2887a1470 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,24 +33,6 @@ def event_image_url end end - def link_to_add_link_fields(name, f, association, **args) - new_object = f.object.to_model.class.reflect_on_association(association).klass.new - id = new_object.object_id - fields = f.fields_for(association, new_object, child_index: id) do |builder| - render(association.to_s.singularize + '_fields', f: builder) - end - link_to(name, '#', class: 'add_link_fields ' + args[:class], data: { id:, fields: fields.gsub("\n", '') }, style: args[:style]) - end - - def link_to_add_conference_day_fields(name, f, association, **args) - new_object = f.object.to_model.class.reflect_on_association(association).klass.new - id = new_object.object_id - fields = f.fields_for(association, new_object, child_index: id) do |builder| - render(association.to_s.singularize + '_fields', f: builder) - end - link_to(name, '#', class: 'add_conference_day_fields ' + args[:class], data: { id:, fields: fields.gsub("\n", '') }, style: args[:style]) - end - def markdown(text) html_render = Redcarpet::Render::HTML options = { diff --git a/app/javascript/packs/conference_form.js b/app/javascript/packs/conference_form.js index b51546501..d02251ca1 100644 --- a/app/javascript/packs/conference_form.js +++ b/app/javascript/packs/conference_form.js @@ -1,27 +1,5 @@ -$(document).on('click', '.add_link_fields', function(event) { - var regexp, time; - time = new Date().getTime(); - regexp = new RegExp($(this).data('id'), 'g'); - $('.link-fields').append($(this).data('fields').replace(regexp, time)); - return event.preventDefault(); -}) - -$(document).on('click', '.remove_link_field', function(event) { +(document).on('click', '.remove_link_field', function(event) { $(this).prev('input[type=hidden]').val('1'); $(this).closest('.link-field').hide(); return event.preventDefault(); }) - -$(document).on('click', '.add_conference_day_fields', function(event) { - var regexp, time; - time = new Date().getTime(); - regexp = new RegExp($(this).data('id'), 'g'); - $('.conference-day-fields').append($(this).data('fields').replace(regexp, time)); - return event.preventDefault(); -}) - -$(document).on('click', '.remove_conference_day_field', function(event) { - $(this).prev('input[type=hidden]').val('1'); - $(this).closest('.conference-day-field').hide(); - return event.preventDefault(); -}) \ No newline at end of file From 3c64791f8aacd7f70f99d9f1750949990a2b28b7 Mon Sep 17 00:00:00 2001 From: Ryo Takaishi Date: Sat, 17 Aug 2024 11:19:09 +0900 Subject: [PATCH 11/22] switch to stimulus --- app/javascript/packs/controllers/index.js | 3 +++ .../packs/controllers/remove_link_field_controller.js | 10 ++++++++++ app/views/admin/conferences/_link_fields.html.erb | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/javascript/packs/controllers/remove_link_field_controller.js diff --git a/app/javascript/packs/controllers/index.js b/app/javascript/packs/controllers/index.js index 49b4e9e14..e99c02cdb 100644 --- a/app/javascript/packs/controllers/index.js +++ b/app/javascript/packs/controllers/index.js @@ -12,3 +12,6 @@ import { application } from "./application.js" import ShareRegistrationController from "./share_registration_controller.js" application.register("share-registration", ShareRegistrationController) + +import RemoveLinkFieldController from "./remove_link_field_controller.js" +application.register("remove-link-field", RemoveLinkFieldController) diff --git a/app/javascript/packs/controllers/remove_link_field_controller.js b/app/javascript/packs/controllers/remove_link_field_controller.js new file mode 100644 index 000000000..5d8201e8f --- /dev/null +++ b/app/javascript/packs/controllers/remove_link_field_controller.js @@ -0,0 +1,10 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + static targets = [ "tweet_content" ] + + remove() { + const value = this.tweet_contentTarget.value + window.open(`https://twitter.com/intent/tweet?text=${encodeURIComponent(value)}`); + } +} diff --git a/app/views/admin/conferences/_link_fields.html.erb b/app/views/admin/conferences/_link_fields.html.erb index bf024a4d2..14c615c61 100644 --- a/app/views/admin/conferences/_link_fields.html.erb +++ b/app/views/admin/conferences/_link_fields.html.erb @@ -1,4 +1,4 @@ -