From a697bbf7beddd62b4c4faf1351e2b95e0855dd35 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Thu, 30 Nov 2023 19:38:02 +0000 Subject: [PATCH] Assign users default time log categories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These will be used to show the amount logged against specific time budgets on each project. It’s potentially a little naïve but we can start with the simpler approach and see. Refs #2165 --- app/views/timelogs/_edit_form_bottom.html.erb | 1 - app/views/users/_edit_form.html.erb | 3 +++ config/locales/en.yml | 5 +++++ .../20231130190644_add_time_budget_category_id_to_users.rb | 5 +++++ init.rb | 1 + lib/jobs_hook_listener.rb | 1 + 6 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 app/views/users/_edit_form.html.erb create mode 100644 db/migrate/20231130190644_add_time_budget_category_id_to_users.rb diff --git a/app/views/timelogs/_edit_form_bottom.html.erb b/app/views/timelogs/_edit_form_bottom.html.erb index 8194e58..26d93f5 100644 --- a/app/views/timelogs/_edit_form_bottom.html.erb +++ b/app/views/timelogs/_edit_form_bottom.html.erb @@ -1,4 +1,3 @@

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

diff --git a/app/views/users/_edit_form.html.erb b/app/views/users/_edit_form.html.erb new file mode 100644 index 0000000..e13bece --- /dev/null +++ b/app/views/users/_edit_form.html.erb @@ -0,0 +1,3 @@ +

+<%= form.label :time_budget_category_id %> +<%= form.collection_select :time_budget_category_id, TimeBudgetCategory.all, :id, :name, include_blank: true %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 8d7dd82..c5aeb04 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,6 +1,11 @@ en: + activerecord: + attributes: + user: + time_budget_category_id: Log time as field_jobs: Jobs field_job: Job enumeration_time_budget_category: Time budget categories enumeration_job_category: Job categories + diff --git a/db/migrate/20231130190644_add_time_budget_category_id_to_users.rb b/db/migrate/20231130190644_add_time_budget_category_id_to_users.rb new file mode 100644 index 0000000..019c7db --- /dev/null +++ b/db/migrate/20231130190644_add_time_budget_category_id_to_users.rb @@ -0,0 +1,5 @@ +class AddTimeBudgetCategoryIdToUsers < ActiveRecord::Migration[6.1] + def change + add_column :users, :time_budget_category_id, :integer + end +end diff --git a/init.rb b/init.rb index 418db34..eb06414 100644 --- a/init.rb +++ b/init.rb @@ -10,6 +10,7 @@ Redmine::Plugin.register :jobs do menu :project_menu, :jobs, { controller: 'jobs', action: 'index' }, caption: 'Jobs', after: :issues, param: :project_id TimeEntry.safe_attributes 'job_id' + User.safe_attributes 'time_budget_category_id' Rails.application.config.before_initialize do Rails.logger.info "Patch Jobs" diff --git a/lib/jobs_hook_listener.rb b/lib/jobs_hook_listener.rb index fe19ee9..8c2c16e 100644 --- a/lib/jobs_hook_listener.rb +++ b/lib/jobs_hook_listener.rb @@ -1,4 +1,5 @@ class JobsHookListener < Redmine::Hook::ViewListener render_on :view_timelog_edit_form_bottom, partial: "timelogs/edit_form_bottom" + render_on :view_users_form, partial: "users/edit_form" end