Implemented turbo_stream for operator jobs
This commit is contained in:
@@ -41,10 +41,18 @@ class Operator::JobsController < ApplicationController
|
||||
|
||||
# PATCH/PUT /jobs/1 or /jobs/1.json
|
||||
def update
|
||||
# FIXME: Move to the model (orderstuff)
|
||||
@openjobs = Job.open.order(:created_at)
|
||||
@printingjobs = Job.printing.order(:status_changed_at)
|
||||
@pickupjobs = Job.pickup.order(:status_changed_at)
|
||||
@paidjobs = Job.paid.status_changed_today.order(:status_changed_at)
|
||||
@canceledjobs = Job.canceled.status_changed_today.order(:status_changed_at)
|
||||
@job.assign_attributes(job_params)
|
||||
@status_changed = @job.status_changed?
|
||||
respond_to do |format|
|
||||
if @job.update(job_params)
|
||||
if @job.save
|
||||
broadcast_update_job
|
||||
# format.turbo_stream
|
||||
format.turbo_stream
|
||||
format.html { redirect_to operator_jobs_url, notice: "Job was successfully updated." }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
@@ -67,11 +75,13 @@ class Operator::JobsController < ApplicationController
|
||||
flash[:notice] = "Job was successfully updated"
|
||||
else
|
||||
flash[:alert] = "Job could not be updated"
|
||||
# NOTE: Discard changes that could not be saved so turbo_stream renders the correct values
|
||||
@job.reload
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
broadcast_update_job
|
||||
# format.turbo_stream
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.replace(@job, partial: "operator/jobs/job_tr", locals: { job: @job }) }
|
||||
format.html { redirect_to operator_jobs_url }
|
||||
end
|
||||
end
|
||||
@@ -81,11 +91,13 @@ class Operator::JobsController < ApplicationController
|
||||
flash[:notice] = "Job was successfully updated"
|
||||
else
|
||||
flash[:alert] = "Job could not be updated"
|
||||
# NOTE: Discard changes that could not be saved so turbo_stream renders the correct values
|
||||
@job.reload
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
broadcast_update_job
|
||||
# format.turbo_stream
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.replace(@job, partial: "operator/jobs/job_tr", locals: { job: @job }) }
|
||||
format.html { redirect_to operator_jobs_url }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user