Add categories to jobs

This commit is contained in:
Trevor Vallender 2023-11-30 19:08:55 +00:00
parent 983e6a3b6a
commit 08b49a4263
9 changed files with 28 additions and 1 deletions

View File

@ -52,6 +52,7 @@ class JobsController < ApplicationController
:budget,
:name,
:description,
:category_id,
time_budgets_attributes: [:id, :category_id, :hours, :job_id, :_destroy]
)
end

View File

@ -7,6 +7,8 @@ class Job < ActiveRecord::Base
presence: true
belongs_to :project
belongs_to :category, class_name: "JobCategory"
has_many :time_entries, dependent: :restrict_with_error
has_many :time_budgets, dependent: :destroy
accepts_nested_attributes_for :time_budgets, allow_destroy: true

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
class JobCategory < Enumeration
has_many :jobs, foreign_key: :category_id
OptionName = :enumeration_job_category
def option_name
OptionName
end
end

View File

@ -9,6 +9,10 @@
<%= f.label :description %>
<%= f.text_area :description %>
<p>
<%= f.label :category %>
<%= f.collection_select :category_id, JobCategory.all, :id, :name %>
<p>
<%= f.label :starts_on %>
<%= f.date_field :starts_on %>

View File

@ -1,5 +1,6 @@
<tr>
<td><%= link_to job.name, project_job_path(job.project, job) %></td>
<td><%= job.category&.name || "Unassigned" %></td>
<td><%= format_date(job.starts_on) %></td>
<td><%= format_date(job.ends_on) %></td>
<td><%= job.project_id %></td>

View File

@ -12,11 +12,11 @@
<thead>
<tr>
<th>Name</th>
<th>Category</th>
<th>Starts on</th>
<th>Ends on</th>
<th>Project</th>
<th>External project</th>
<th>Total budget</th>
<th>Progress</th>
</tr>
</thead>

View File

@ -14,6 +14,8 @@
<div class="splitcontent">
<div class="splitcontentleft">
<div class="status attribute">
<div class="label">Category:</div>
<div class="value"><%= @job.category&.name || "Unassigned" %></div>
<div class="label">Starts on:</div>
<div class="value"><%= format_date(@job.starts_on) %></div>
<div class="label">Ends on:</div>

View File

@ -3,3 +3,4 @@ en:
field_job: Job
enumeration_time_budget_category: Time budget categories
enumeration_job_category: Job categories

View File

@ -0,0 +1,5 @@
class AddCategoryIdToJobs < ActiveRecord::Migration[6.1]
def change
add_column :jobs, :category_id, :integer
end
end