diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index fcbfe46..490a641 100644 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -1,30 +1,22 @@ class JobsController < ApplicationController - before_action :set_job, only: %i[show edit update destroy cancel] - # GET /jobs or /jobs.json def index @jobs = Job.currently_working_on end - # GET /jobs/1 or /jobs/1.json - def show; end - - # GET /jobs/new + # GET /jobs/new def new @job = Job.new end - # GET /jobs/1/edit - def edit; end - # POST /jobs or /jobs.json def create @job = Job.new(job_params) respond_to do |format| if @job.save - flash[:notice] = 'Job was successfully created.' - Turbo::StreamsChannel.broadcast_prepend_later_to 'jobs', target: :jobs, partial: 'jobs/job_tr', + flash[:notice] = "Job was successfully created." + Turbo::StreamsChannel.broadcast_prepend_later_to "jobs", target: :jobs, partial: "jobs/job_tr", locals: { job: @job } format.html { redirect_to jobs_url } format.json { render :show, status: :created, location: @job } @@ -35,38 +27,14 @@ class JobsController < ApplicationController end end - # PATCH/PUT /jobs/1 or /jobs/1.json - def update - respond_to do |format| - if @job.update(job_params) - broadcast_update_job - format.html { redirect_to jobs_url, notice: 'Job was successfully updated.' } - format.json { render :show, status: :ok, location: @job } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @job.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /jobs/1 or /jobs/1.json - def destroy - @job.destroy! - - respond_to do |format| - Turbo::StreamsChannel.broadcast_remove_to 'jobs', target: @job - format.html { redirect_to jobs_url, notice: 'Job was successfully destroyed.' } - format.json { head :no_content } - end - end - def cancel + @job = Job.find(params[:id]) if @job.canceled! - flash[:notice] = 'Job successfully canceled' + flash[:notice] = "Job successfully canceled" else - flash[:alert] = 'Job could not be canceled' + flash[:alert] = "Job could not be canceled" end - + respond_to do |format| broadcast_update_job format.turbo_stream @@ -77,20 +45,12 @@ class JobsController < ApplicationController private - # Use callbacks to share common setup or constraints between actions. - def set_job - @job = Job.find(params[:id]) - end - def broadcast_update_job - Turbo::StreamsChannel.broadcast_replace_later_to 'jobs', target: @job, partial: 'jobs/job_tr', locals: { job: @job } + Turbo::StreamsChannel.broadcast_replace_later_to "jobs", target: @job, partial: "jobs/job_tr", locals: { job: @job } end # Only allow a list of trusted parameters through. def job_params - params.require(:job).permit(:operator_id, :costumer_id, :operator_firstname, :operator_lastname, - :costumer_firstname, :costumer_lastname, :paid, :printed_at, :intern, - :cost_center, :number_of_plans_a0, :number_of_plans_a1, - :number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan, :privacy_policy_accepted, :pdf) + params.require(:job).permit(:costumer_id, :costumer_firstname, :costumer_lastname, :privacy_policy_accepted, :pdf) end end diff --git a/app/controllers/operator/jobs_controller.rb b/app/controllers/operator/jobs_controller.rb new file mode 100644 index 0000000..daae288 --- /dev/null +++ b/app/controllers/operator/jobs_controller.rb @@ -0,0 +1,95 @@ +class Operator::JobsController < ApplicationController + before_action :set_job, only: %i[show edit update destroy cancel] + + # GET /jobs or /jobs.json + def index + @jobs = Job.currently_working_on + end + + + # GET /jobs/1 or /jobs/1.json + def show; end + + # GET /jobs/new + def new + @job = Job.new + end + + # GET /jobs/1/edit + def edit; end + + # POST /jobs or /jobs.json + def create + @job = Job.new(job_params) + + respond_to do |format| + if @job.save + flash[:notice] = "Job was successfully created." + Turbo::StreamsChannel.broadcast_prepend_later_to "jobs", target: :jobs, partial: "jobs/job_tr", + locals: { job: @job } + format.html { redirect_to jobs_url } + format.json { render :show, status: :created, location: @job } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @job.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /jobs/1 or /jobs/1.json + def update + respond_to do |format| + if @job.update(job_params) + broadcast_update_job + format.html { redirect_to jobs_url, notice: "Job was successfully updated." } + format.json { render :show, status: :ok, location: @job } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @job.errors, status: :unprocessable_entity } + end + end + end + + def cancel + if @job.canceled! + flash[:notice] = "Job successfully canceled" + else + flash[:alert] = "Job could not be canceled" + end + + respond_to do |format| + broadcast_update_job + format.turbo_stream + format.html { redirect_to jobs_url } + format.json { head :no_content } + end + end + + # DELETE /jobs/1 or /jobs/1.json + def destroy + @job.destroy! + + respond_to do |format| + Turbo::StreamsChannel.broadcast_remove_to "jobs", target: @job + format.html { redirect_to jobs_url, notice: "Job was successfully destroyed." } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_job + @job = Job.find(params[:id]) + end + + def broadcast_update_job + Turbo::StreamsChannel.broadcast_replace_later_to "jobs", target: @job, partial: "jobs/job_tr", locals: { job: @job } + end + + # Only allow a list of trusted parameters through. + def job_params + params.require(:job).permit(:operator_id, :costumer_id, :opertator_firstname, :operator_lastname, :costumer_firstname, :costumer_lastname) + end +end + diff --git a/app/helpers/operator/jobs_helper.rb b/app/helpers/operator/jobs_helper.rb new file mode 100644 index 0000000..4c274c1 --- /dev/null +++ b/app/helpers/operator/jobs_helper.rb @@ -0,0 +1,2 @@ +module Operator::JobsHelper +end diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb index 1f1b26a..39fdbd8 100644 --- a/app/views/jobs/_form.html.erb +++ b/app/views/jobs/_form.html.erb @@ -18,30 +18,6 @@ <%= form.label :costumer_lastname, 'Nachname' %> <%= form.text_field :costumer_lastname, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> - - - - - - - - - - - - - - - - - - - - - - - -
| ID | +Auftraggeber | +A0 | +A1 | +A2 | +A3 | +noDIN | +Kosten | +Status | ++ | ||
|---|---|---|---|---|---|---|---|---|---|---|---|