From a01ac2203ec37f5df1f6f1dbb67ec20dc324668e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=B6hm?= Date: Wed, 23 Jul 2025 15:52:55 +0200 Subject: [PATCH] Fixed job number to work with broadcast in jobs#index --- app/controllers/jobs_controller.rb | 10 ++++++++-- app/views/jobs/_badge.html.erb | 3 +++ app/views/jobs/_job_tr.html.erb | 13 +++++++++++-- app/views/jobs/index.html.erb | 2 +- config/routes.rb | 1 + 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 app/views/jobs/_badge.html.erb diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index 78eaeb3..ddeb0c9 100644 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -1,7 +1,7 @@ class JobsController < ApplicationController - skip_before_action :authenticate_user!, only: [ :index, :cancel_button ] + skip_before_action :authenticate_user!, only: [ :index, :cancel_button, :badge ] skip_before_action :verified_user!, only: [ :index ] - skip_verify_authorized only: [ :index, :new, :create, :cancel_button ] + skip_verify_authorized only: [ :index, :new, :create, :cancel_button, :badge] # GET /jobs or /jobs.json def index @@ -53,6 +53,12 @@ class JobsController < ApplicationController render partial: "jobs/cancel_button", locals: { job: @job } end + def badge + @job = Job.find(params[:id]) + + render partial: "jobs/badge", locals: { job: @job } + end + private def broadcast_update_status_cards_and_start_next_job_button diff --git a/app/views/jobs/_badge.html.erb b/app/views/jobs/_badge.html.erb new file mode 100644 index 0000000..0c120bc --- /dev/null +++ b/app/views/jobs/_badge.html.erb @@ -0,0 +1,3 @@ +<%= turbo_frame_tag dom_id(job, :badge) do %> + <%= link_to_if user_signed_in? && allowed_to?(:show, job, namespace: :Operator), job.id, operator_job_path(job) %> +<% end %> diff --git a/app/views/jobs/_job_tr.html.erb b/app/views/jobs/_job_tr.html.erb index 75a5f73..d98f43e 100644 --- a/app/views/jobs/_job_tr.html.erb +++ b/app/views/jobs/_job_tr.html.erb @@ -1,13 +1,22 @@ - <%= link_to_if user_signed_in? && allowed_to?(:show, job, namespace: :Operator), job.id, operator_job_path(job) %> + <% # TODO: Refactor to helper function %> + <% if defined?(no_turbo_stream) && no_turbo_stream %> + <%= turbo_frame_tag dom_id(job, :badge) do %> + <%= render partial: "jobs/badge", locals: { job: job } %> + <% end %> + <% else %> + <%= turbo_frame_tag dom_id(job, :badge), src: badge_job_path(job), loading: 'lazy' do %> + <%= icon("ellipsis-horizontal-circle", class: "icon icon-disabled size-10", title: "Loading...") %> + <% end %> + <% end %> <% if job.pdf.attached? && job.pdf.previewable? %> <%= image_tag(url_for(job.pdf.blob.preview(resize_to_limit: [100, 100])), class: "shadow") %> - <%#= image_tag job.pdf.preview(resize_to_limit: [50, 50]), class: "mx-auto" %> + <%# = image_tag job.pdf.preview(resize_to_limit: [50, 50]), class: "mx-auto" %> <% end %> diff --git a/app/views/jobs/index.html.erb b/app/views/jobs/index.html.erb index d872b35..f2eeede 100644 --- a/app/views/jobs/index.html.erb +++ b/app/views/jobs/index.html.erb @@ -23,7 +23,7 @@ Action - + <%= render partial: "job_tr", collection: @jobs, as: :job, locals: { no_turbo_stream: @no_turbo_stream } %> diff --git a/config/routes.rb b/config/routes.rb index b8ed49f..02c46c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,7 @@ Rails.application.routes.draw do member do patch "cancel" get "cancel_button" + get "badge" end end resource :profile, only: [ :show, :edit, :destroy ]