Generated operator controller and cleaned job controller
This commit is contained in:
@@ -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
|
||||
|
||||
95
app/controllers/operator/jobs_controller.rb
Normal file
95
app/controllers/operator/jobs_controller.rb
Normal file
@@ -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
|
||||
|
||||
2
app/helpers/operator/jobs_helper.rb
Normal file
2
app/helpers/operator/jobs_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Operator::JobsHelper
|
||||
end
|
||||
@@ -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" %>
|
||||
</div>
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :intern %> -->
|
||||
<!-- <%= form.check_box :intern, class: "block mt-2 h-5 w-5" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :cost_center %> -->
|
||||
<!-- <%= form.text_field :cost_center, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :number_of_plans_a0 %> -->
|
||||
<!-- <%= form.number_field :number_of_plans_a0, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :number_of_plans_a1 %> -->
|
||||
<!-- <%= form.number_field :number_of_plans_a1, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :number_of_plans_a2 %> -->
|
||||
<!-- <%= form.number_field :number_of_plans_a2, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :number_of_plans_a3 %> -->
|
||||
<!-- <%= form.number_field :number_of_plans_a3, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<div>
|
||||
<%= form.label :pdf, "Plan auswählen (PDF-Format)" %>
|
||||
<%= form.file_field :pdf, accept: "application/pdf", class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
|
||||
|
||||
55
app/views/operator/jobs/_form.html.erb
Normal file
55
app/views/operator/jobs/_form.html.erb
Normal file
@@ -0,0 +1,55 @@
|
||||
<%= form_with(model: job, class: "contents") do |form| %>
|
||||
<% if job.errors.any? %>
|
||||
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg shadow-lg border-l border-red mt-3" >
|
||||
<h2><%= pluralize(job.errors.count, "error") %>
|
||||
prohibited this job from being saved:</h2>
|
||||
<ul>
|
||||
<% job.errors.each do |error| %>
|
||||
<li><%= error.full_message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="my-5">
|
||||
<%= form.label :costumer_firstname, 'Vorname' %>
|
||||
<%= form.text_field :costumer_firstname, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
<div class="my-5">
|
||||
<%= 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" %>
|
||||
</div>
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :intern %> -->
|
||||
<!-- <%= form.check_box :intern, class: "block mt-2 h-5 w-5" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :cost_center %> -->
|
||||
<!-- <%= form.text_field :cost_center, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :number_of_plans_a0 %> -->
|
||||
<!-- <%= form.number_field :number_of_plans_a0, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :number_of_plans_a1 %> -->
|
||||
<!-- <%= form.number_field :number_of_plans_a1, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :number_of_plans_a2 %> -->
|
||||
<!-- <%= form.number_field :number_of_plans_a2, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<!-- <div class="my-5"> -->
|
||||
<!-- <%= form.label :number_of_plans_a3 %> -->
|
||||
<!-- <%= form.number_field :number_of_plans_a3, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
|
||||
<!-- </div> -->
|
||||
<div>
|
||||
<%= form.label :pdf, "Plan auswählen (PDF-Format)" %>
|
||||
<%= form.file_field :pdf, accept: "application/pdf", class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
<div>
|
||||
<%= form.check_box :privacy_policy_accepted, class: "mt-2 h-5 w-5" %> <%= form.label :privacy_policy_accepted, "Datenschutzerklärung akzeptiert", class: "p-2" %>
|
||||
</div>
|
||||
<div class="inline">
|
||||
<%= form.submit "Plottauftrag abschicken", class: "py-2 px-3 bg-hsrm-red hover:bg-hsrm-red-light shadow-lg text-white inline-block font-medium cursor-pointer" %>
|
||||
</div>
|
||||
<% end %>
|
||||
66
app/views/operator/jobs/_job_tr.html.erb
Normal file
66
app/views/operator/jobs/_job_tr.html.erb
Normal file
@@ -0,0 +1,66 @@
|
||||
<tr id="<%= dom_id job %>" class="bg-status-<%= job.status %>-light odd:bg-opacity-20 even:bg-opacity-10">
|
||||
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 text-xs font-medium uppercase tracking-wider bg-opacity-50 text-status-<%= job.status %> bg-status-<%= job.status %>-light rounded-lg">
|
||||
<%= job.id %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap">
|
||||
<%= job.costumer_fullname %>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap w-6">
|
||||
<% if job.pdf.attached? %>
|
||||
<%= image_tag url_for(job.pdf.preview(resize_to_limit: [100, 100])) %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap">
|
||||
<% if job.pdf.attached? %>
|
||||
<%#= link_to job.pdf.filename, rails_blob_path(job.pdf, disposition: "attachment") %>
|
||||
<%= link_to job.pdf.filename, job.pdf, download:true %>
|
||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 text-hsrm-gray font-medium rounded-lg ml-2">
|
||||
<%=number_to_human_size job.pdf.blob.byte_size%>
|
||||
</span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
||||
<%= job.number_of_plans_a0 %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
||||
<%= job.number_of_plans_a1 %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
||||
<%= job.number_of_plans_a2 %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
||||
<%= job.number_of_plans_a3 %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-right text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
||||
<%= job.costum_qm_plan.round(2) %> m²
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-right text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
||||
<%= job.cost.round(2) %> €
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 block text-xs font-medium uppercase tracking-wider bg-opacity-50 w-20 text-center text-status-<%= job.status.to_sym %> bg-status-<%= job.status %>-light rounded-lg">
|
||||
<%= job.status %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-right text-hsrm-gray whitespace-nowrap">
|
||||
<% if job.able_to_cancel? %>
|
||||
<%= button_to icon("x-circle", class: "text-hsrm-red size-8 inline", title: "Abbrechen"), cancel_job_path(job), method: :patch, form: {data: {turbo_confirm: 'Den Plottauftrag wirklich abbrechen?'}}, form_class: "inline" %>
|
||||
<% else %>
|
||||
<%= icon("x-circle", class: "text-hsrm-gray text-opacity-50 size-8 inline", title: "Kann nicht mehr abgebrochen werden") %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
1
app/views/operator/jobs/cancel.turbo_stream.erb
Normal file
1
app/views/operator/jobs/cancel.turbo_stream.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= turbo_stream.update "flash", partial: "layouts/flash" %>
|
||||
32
app/views/operator/jobs/index.html.erb
Normal file
32
app/views/operator/jobs/index.html.erb
Normal file
@@ -0,0 +1,32 @@
|
||||
<%= turbo_stream_from 'jobs' %>
|
||||
<div class="w-full">
|
||||
<%#= render partial: 'layouts/flash' %>
|
||||
<% content_for :title, "Current Print Jobs" %>
|
||||
<div class="flex justify-between items-center py-4">
|
||||
<h1 class="font-bold text-hsrm-gray text-4xl">Aktuelle Plottaufträge <span class="font-semibold text-sm"><%= Date.today.strftime("%d.%m.%Y") %></span></h1>
|
||||
<%= link_to "Plottauftrag aufgeben", new_job_path, class: "px-3 py-2 bg-hsrm-red drop-shadow-lg transition-colors hover:bg-hsrm-red-light text-white block font-medium" %>
|
||||
</div>
|
||||
<div class="overflow-auto min-w-full drop-shadow-lg">
|
||||
<table class="w-full py-8 table-auto">
|
||||
<thead class="bg-gray-200 text-hsrm-gray border-b-2 border-gray-300">
|
||||
<tr>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> ID </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-left"> Auftraggeber </th>
|
||||
<th colspan="2" class="p-3 text-sm font-semibold tracking-wide text-left"> PDF </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A0 </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A1 </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A2 </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A3 </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-center w-1"> noDIN </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-center w-1"> Kosten </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-center w-1"> Status </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-center w-1"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id='jobs' class="divide-y divivde-gray-300">
|
||||
<%= render partial: "job_tr", collection: @jobs, as: :job %>
|
||||
<%#= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -4,6 +4,9 @@ Rails.application.routes.draw do
|
||||
patch "cancel"
|
||||
end
|
||||
end
|
||||
namespace :operator do
|
||||
resources :jobs
|
||||
end
|
||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
||||
|
||||
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
|
||||
|
||||
7
test/controllers/operator/jobs_controller_test.rb
Normal file
7
test/controllers/operator/jobs_controller_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Operator::JobsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user