From 932f8654120d330d758438a6d68cdc6b00804840 Mon Sep 17 00:00:00 2001 From: Yves Siegrist Date: Sun, 6 Aug 2023 22:09:07 +0200 Subject: [PATCH] Fix broadcasting Only update the progressbar and bytes transferred --- app/helpers/syncs_helper.rb | 14 +-- app/models/sync.rb | 5 +- app/views/receiver/payloads/index.html.erb | 1 + app/views/sender/payloads/index.html.erb | 1 + .../syncs/_detail_files_and_bytes.html.erb | 4 + app/views/syncs/_detail_progress.html.erb | 5 + .../syncs/_list_files_and_bytes.html.erb | 5 + app/views/syncs/_list_progress.html.erb | 20 ++++ app/views/syncs/_sync.html.erb | 29 +---- app/views/syncs/_sync_detail.html.erb | 106 +++++++++--------- app/views/syncs/index.html.erb | 1 + app/views/syncs/show.html.erb | 1 + 12 files changed, 101 insertions(+), 91 deletions(-) create mode 100644 app/views/syncs/_detail_files_and_bytes.html.erb create mode 100644 app/views/syncs/_detail_progress.html.erb create mode 100644 app/views/syncs/_list_files_and_bytes.html.erb create mode 100644 app/views/syncs/_list_progress.html.erb diff --git a/app/helpers/syncs_helper.rb b/app/helpers/syncs_helper.rb index e17f3a0..6370bf8 100644 --- a/app/helpers/syncs_helper.rb +++ b/app/helpers/syncs_helper.rb @@ -1,18 +1,8 @@ module SyncsHelper - def sync_progress_bar(sync) + def sync_progress_classes(sync) css_class = "progress-bar" css_class << " bg-danger" if sync.errored? css_class << " bg-success" if sync.succeeded? - - content_tag :div, class: "progress" do - content_tag( - :div, - "#{sync.progress.round}%", - style: "width: #{sync.progress}%", - class: css_class, - aria: { valuenow: sync.progress, valuemin: 0, valuemax: 100 }, - role: "progressbar" - ) - end + css_class end end diff --git a/app/models/sync.rb b/app/models/sync.rb index 7f19bcf..4c2ecef 100644 --- a/app/models/sync.rb +++ b/app/models/sync.rb @@ -1,5 +1,8 @@ class Sync < ApplicationRecord - after_update_commit -> { broadcast_replace_later_to "sync_detail_#{id}", partial: "syncs/sync_detail" } + after_update_commit -> { broadcast_replace_later_to "list_progress_#{id}", partial: "syncs/list_progress", target: "list_progress_#{id}" } + after_update_commit -> { broadcast_replace_later_to "list_files_and_bytes_#{id}", partial: "syncs/list_files_and_bytes", target: "list_files_and_bytes_#{id}" } + after_update_commit -> { broadcast_replace_later_to "detail_progress_#{id}", partial: "syncs/detail_progress", target: "detail_progress_#{id}" } + after_update_commit -> { broadcast_replace_later_to "detail_files_and_bytes_#{id}", partial: "syncs/detail_files_and_bytes", target: "detail_files_and_bytes_#{id}" } broadcasts inserts_by: :prepend has_many :sent_files diff --git a/app/views/receiver/payloads/index.html.erb b/app/views/receiver/payloads/index.html.erb index 5ae99ee..da051e5 100644 --- a/app/views/receiver/payloads/index.html.erb +++ b/app/views/receiver/payloads/index.html.erb @@ -1,4 +1,5 @@ <% content_for :title, "Payloads" %> +<%= turbo_stream_from :receiver_payloads %>