From 6b1646e1801325a38f79d4ab0c7866b21920b21d Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Tue, 21 Nov 2023 13:59:43 +0000 Subject: [PATCH] Associate time entries with a job --- app/models/job.rb | 2 ++ app/views/jobs/index.html.erb | 2 +- app/views/timelogs/_edit_form_bottom.html.erb | 5 ++++- db/migrate/20231116202759_create_jobs.rb | 2 ++ init.rb | 2 ++ lib/jobs_hook_listener.rb | 3 ++- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/job.rb b/app/models/job.rb index 746c1d3..83c05b7 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -4,6 +4,8 @@ class Job < ActiveRecord::Base :name, presence: true + scope :project, ->(project) { where(project_id: project.id) } + def time_logged 42 end diff --git a/app/views/jobs/index.html.erb b/app/views/jobs/index.html.erb index 56879f4..a6e64e4 100644 --- a/app/views/jobs/index.html.erb +++ b/app/views/jobs/index.html.erb @@ -1,6 +1,6 @@ <% html_title "Jobs" %>
- <%= link_to 'Create new job', new_job_path(project_id: @project.id), class: "icon icon-add new-job" %> + <%= link_to 'New job', new_job_path(project_id: @project.id), class: "icon icon-add new-job" %>

Jobs

diff --git a/app/views/timelogs/_edit_form_bottom.html.erb b/app/views/timelogs/_edit_form_bottom.html.erb index eb0a70e..130c458 100644 --- a/app/views/timelogs/_edit_form_bottom.html.erb +++ b/app/views/timelogs/_edit_form_bottom.html.erb @@ -1 +1,4 @@ -

FOOBAR

+

+<%= form.label :job_id %> +<%= form.collection_select :job_id, Job.project(@project), :id, :name %> +

diff --git a/db/migrate/20231116202759_create_jobs.rb b/db/migrate/20231116202759_create_jobs.rb index f076ec5..bcef011 100644 --- a/db/migrate/20231116202759_create_jobs.rb +++ b/db/migrate/20231116202759_create_jobs.rb @@ -8,6 +8,8 @@ class CreateJobs < ActiveRecord::Migration[6.1] t.references :project, foreign_key: true t.string :description t.integer :budget + + t.timestamps end add_index :jobs, :name, unique: true end diff --git a/init.rb b/init.rb index b96a81a..c2464cd 100644 --- a/init.rb +++ b/init.rb @@ -8,4 +8,6 @@ Redmine::Plugin.register :jobs do permission :jobs, { jobs: [:index, :show, :new, :create, :edit, :update, :destroy] }, public: true menu :project_menu, :jobs, { controller: 'jobs', action: 'index' }, caption: 'Jobs', after: :issues, param: :project_id + + TimeEntry.safe_attributes 'job_id' end diff --git a/lib/jobs_hook_listener.rb b/lib/jobs_hook_listener.rb index 50dc71f..fe19ee9 100644 --- a/lib/jobs_hook_listener.rb +++ b/lib/jobs_hook_listener.rb @@ -1,3 +1,4 @@ class JobsHookListener < Redmine::Hook::ViewListener - render_on :view_timelog_edit_form_bottom, partial: "timelogs/edit_form_bottom.html.erb" + render_on :view_timelog_edit_form_bottom, partial: "timelogs/edit_form_bottom" end +