Added edit and cancel button
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class JobsController < ApplicationController
|
||||
before_action :set_job, only: %i[show edit update destroy]
|
||||
before_action :set_job, only: %i[show edit update destroy cancel]
|
||||
|
||||
# GET /jobs or /jobs.json
|
||||
def index
|
||||
@@ -36,7 +36,7 @@ class JobsController < ApplicationController
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @job.update(job_params)
|
||||
format.html { redirect_to job_url(@job), notice: 'Job was successfully updated.' }
|
||||
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 }
|
||||
@@ -55,6 +55,16 @@ class JobsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def cancel
|
||||
@job.canceled! if @job.able_to_cancel?
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream {} # view is updated from model broadcast
|
||||
format.html { redirect_to jobs_url, notice: 'Job was successfully canceled.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
|
||||
@@ -62,6 +62,16 @@ class Job < ApplicationRecord
|
||||
errors.add(:pdf, 'must be a PDF')
|
||||
end
|
||||
|
||||
def able_to_cancel?
|
||||
open?
|
||||
end
|
||||
|
||||
# cancel job only if it is still open
|
||||
def canceled!
|
||||
self.status = :canceled if open?
|
||||
save
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_printed_at
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<tr id="<%= dom_id job %>" class="<%= cycle('bg-gray-50','bg-gray-100') %> ">
|
||||
<!-- <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> -->
|
||||
<tr id="<%= dom_id job %>" class="odd:bg-gray-50 even:bg-gray-100">
|
||||
<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.fullname %> </td>
|
||||
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap">
|
||||
<% if job.pdf.attached? %>
|
||||
@@ -15,4 +15,10 @@
|
||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||
<span class="p-1.5 text-xs font-medium uppercase tracking-wider bg-opacity-50 text-status-<%= job.status.to_sym %> bg-status-<%= job.status %>-light rounded-lg"><%= job.status %></span>
|
||||
</td>
|
||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||
<%= link_to "edit", edit_job_url(job), class: "p-1.5 ml-2 rounded-lg bg-gray-100 font-medium" %>
|
||||
<% if job.able_to_cancel? %>
|
||||
<%= button_to "cancel", cancel_job_url(job), method: :patch, class: "p-1.5 ml-2 rounded-lg bg-gray-100 font-medium" %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<table class="w-full py-8 table-auto">
|
||||
<thead class="bg-gray-200 text-hsrm-gray border-b-2 border-hsrm-gray">
|
||||
<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 w-1"> ID </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-left"> Auftraggeber </th>
|
||||
<th 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>
|
||||
@@ -20,6 +20,7 @@
|
||||
<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-left w-1"> Status </th>
|
||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> Actions </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id='jobs' class="divide-y divivde-gray-300">
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
Rails.application.routes.draw do
|
||||
resources :jobs
|
||||
resources :jobs do
|
||||
member do
|
||||
patch 'cancel'
|
||||
end
|
||||
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.
|
||||
# Can be used by load balancers and uptime monitors to verify that the app is live.
|
||||
get "up" => "rails/health#show", as: :rails_health_check
|
||||
get 'up' => 'rails/health#show', as: :rails_health_check
|
||||
|
||||
# Defines the root path route ("/")
|
||||
root "jobs#index"
|
||||
root 'jobs#index'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user