Compare commits
3 Commits
690ac30b7a
...
70b935e76d
| Author | SHA1 | Date | |
|---|---|---|---|
| 70b935e76d | |||
| 54e0cd5e45 | |||
| ed0c4408ca |
38
Gemfile
38
Gemfile
@@ -1,36 +1,36 @@
|
||||
source "https://rubygems.org"
|
||||
source 'https://rubygems.org'
|
||||
|
||||
ruby "3.3.4"
|
||||
ruby '3.3.4'
|
||||
|
||||
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
||||
gem "rails", "~> 7.1.3", ">= 7.1.3.4"
|
||||
gem 'rails', '~> 7.1.3', '>= 7.1.3.4'
|
||||
|
||||
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
|
||||
gem "sprockets-rails"
|
||||
gem 'sprockets-rails'
|
||||
|
||||
# Use sqlite3 as the database for Active Record
|
||||
gem "sqlite3", "~> 1.4"
|
||||
gem 'sqlite3', '~> 1.4'
|
||||
|
||||
# Use the Puma web server [https://github.com/puma/puma]
|
||||
gem "puma", ">= 5.0"
|
||||
gem 'puma', '>= 5.0'
|
||||
|
||||
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
|
||||
gem "importmap-rails"
|
||||
gem 'importmap-rails'
|
||||
|
||||
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
|
||||
gem "turbo-rails"
|
||||
gem 'turbo-rails'
|
||||
|
||||
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
|
||||
gem "stimulus-rails"
|
||||
gem 'stimulus-rails'
|
||||
|
||||
# Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]
|
||||
gem "tailwindcss-rails"
|
||||
gem 'tailwindcss-rails'
|
||||
|
||||
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
|
||||
gem "jbuilder"
|
||||
gem 'jbuilder'
|
||||
|
||||
# Use Redis adapter to run Action Cable in production
|
||||
# gem "redis", ">= 4.0.1"
|
||||
gem 'redis', '>= 4.0.1'
|
||||
|
||||
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
|
||||
# gem "kredis"
|
||||
@@ -39,22 +39,22 @@ gem "jbuilder"
|
||||
# gem "bcrypt", "~> 3.1.7"
|
||||
|
||||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||||
gem "tzinfo-data", platforms: %i[ windows jruby ]
|
||||
gem 'tzinfo-data', platforms: %i[windows jruby]
|
||||
|
||||
# Reduces boot times through caching; required in config/boot.rb
|
||||
gem "bootsnap", require: false
|
||||
gem 'bootsnap', require: false
|
||||
|
||||
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
|
||||
# gem "image_processing", "~> 1.2"
|
||||
|
||||
group :development, :test do
|
||||
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
||||
gem "debug", platforms: %i[ mri windows ]
|
||||
gem 'debug', platforms: %i[mri windows]
|
||||
end
|
||||
|
||||
group :development do
|
||||
# Use console on exceptions pages [https://github.com/rails/web-console]
|
||||
gem "web-console"
|
||||
gem 'web-console'
|
||||
|
||||
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
|
||||
# gem "rack-mini-profiler"
|
||||
@@ -65,8 +65,8 @@ end
|
||||
|
||||
group :test do
|
||||
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
|
||||
gem "capybara"
|
||||
gem "selenium-webdriver"
|
||||
gem 'capybara'
|
||||
gem 'selenium-webdriver'
|
||||
end
|
||||
|
||||
gem "faker", "~> 3.4"
|
||||
gem 'faker', '~> 3.4'
|
||||
|
||||
@@ -201,6 +201,10 @@ GEM
|
||||
rake (13.2.1)
|
||||
rdoc (6.7.0)
|
||||
psych (>= 4.0.0)
|
||||
redis (5.2.0)
|
||||
redis-client (>= 0.22.0)
|
||||
redis-client (0.22.2)
|
||||
connection_pool
|
||||
regexp_parser (2.9.2)
|
||||
reline (0.5.9)
|
||||
io-console (~> 0.5)
|
||||
@@ -281,6 +285,7 @@ DEPENDENCIES
|
||||
jbuilder
|
||||
puma (>= 5.0)
|
||||
rails (~> 7.1.3, >= 7.1.3.4)
|
||||
redis (>= 4.0.1)
|
||||
selenium-webdriver
|
||||
sprockets-rails
|
||||
sqlite3 (~> 1.4)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -11,6 +11,9 @@ class Job < ApplicationRecord
|
||||
before_save :update_paid_at, if: :will_save_change_to_status?
|
||||
before_save :update_status_changed_at, if: :will_save_change_to_status?
|
||||
|
||||
after_create_commit -> { broadcast_prepend_later_to 'jobs', partial: 'jobs/job_tr' }
|
||||
after_update_commit -> { broadcast_replace_later_to 'jobs', partial: 'jobs/job_tr' }
|
||||
|
||||
# NOTE: Multiple status if paing before brinting?
|
||||
enum status: {
|
||||
open: 0,
|
||||
@@ -40,7 +43,7 @@ class Job < ApplicationRecord
|
||||
.or(Job.where(status: %i[paid canceled])
|
||||
.where('status_changed_at >= ?', Time.now.beginning_of_day))
|
||||
# .in_status_order
|
||||
# .order(created_at: :asc)
|
||||
.order(created_at: :desc)
|
||||
.order(:costumer_firstname, :costumer_lastname)
|
||||
end
|
||||
|
||||
@@ -59,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>
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
<%= turbo_stream_from 'jobs' %>
|
||||
<div class="w-full">
|
||||
<% if notice.present? %>
|
||||
<p class="px-3 py-2 bg-green-100 mb-5 text-green-700 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
|
||||
<% end %>
|
||||
<div id="notice">
|
||||
<% if notice.present? %>
|
||||
<p class="p-4 bg-green-100 text-green-700 font-medium rounded-lg border-l-4"><%= notice %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% 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 id="jobs" class="overflow-auto min-w-full drop-shadow-lg">
|
||||
<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-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>
|
||||
@@ -19,9 +22,10 @@
|
||||
<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 class="divide-y divivde-gray-300">
|
||||
<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>
|
||||
|
||||
@@ -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