diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index 6314b06..c48a997 100644 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -7,6 +7,7 @@ class JobsController < ApplicationController end def show + @journals = @job.journals end def new @@ -18,6 +19,7 @@ class JobsController < ApplicationController end def update + @job.init_journal(User.current) if @job.update(remove_empty_time_budgets(job_params)) redirect_to project_job_path(@job.project, @job) else @@ -55,6 +57,7 @@ class JobsController < ApplicationController :name, :description, :category_id, + :notes, time_budgets_attributes: [:id, :category_id, :hours, :job_id, :_destroy] ) end diff --git a/app/helpers/jobs_helper.rb b/app/helpers/jobs_helper.rb index a8b21ee..94d5eb0 100644 --- a/app/helpers/jobs_helper.rb +++ b/app/helpers/jobs_helper.rb @@ -12,4 +12,37 @@ module JobsHelper (#{l_hours_short(budget.total_time_logged)}/#{l_hours_short(budget.hours)})", class: "progress") end + + def job_history_tabs + tabs = [] + + if @journals.present? + has_notes = @journals.any? { |journal| journal.notes.present? } + tabs << + { + name: "history", + label: "History", + onclick: 'showJobHistory("history", this.href)', + partial: "jobs/tabs/history", + locals: { + job: @job, + journals: @journals + } + } + if has_notes + tabs << { + name: "notes", + label: "Notes", + onclick: 'showJobHistory("notes", this.href)', + } + end + end + tabs + end + + def job_history_default_tab + return params[:tab] if params[:tab].present? + + "history" + end end diff --git a/app/models/job.rb b/app/models/job.rb index 57763ab..1e44223 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -12,13 +12,21 @@ class Job < ActiveRecord::Base has_many :time_entries, dependent: :restrict_with_error has_many :time_budgets, dependent: :destroy + has_many :journals, as: :journalized, dependent: :destroy, inverse_of: :journalized + delegate :notes, :notes=, to: :current_journal, allow_nil: true accepts_nested_attributes_for :time_budgets, allow_destroy: true + acts_as_customizable + acts_as_watchable + acts_as_mentionable + scope :project_or_parent, ->(project) { where(project_id: [project&.id, project&.parent&.id]) } scope :active, -> { where(starts_on: ..Date.today, ends_on: Date.today..) } safe_attributes 'name', 'description' + after_save :create_journal + def with_all_time_budgets time_budgets.build(job_id: id, category_id: nil) unless time_budgets.where(category_id: nil).exists? TimeBudgetCategory.where.not(id: time_budgets.pluck(:category_id)).each do |category| @@ -54,6 +62,31 @@ class Job < ActiveRecord::Base ActionController::Base.helpers.link_to name, ActionController::Base.helpers.project_job_path(project, self) end + def init_journal(user, notes = "") + @current_journal = Journal.new(journalized: self, user: user, notes: notes) + end + + def current_journal + @current_journal + end + + def create_journal + current_journal.save if current_journal + end + + def journalized_attribute_names + Job.column_names - %w(id created_at updated_at) + end + + def notified_users + [] + end + + def notes_addable?(user = User.current) + #user_tracker_permission?(user, :add_job_notes) + true + end + def self.fields_for_order_statement "jobs.name" end diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb index 4feec0f..c485e52 100644 --- a/app/views/jobs/_form.html.erb +++ b/app/views/jobs/_form.html.erb @@ -38,5 +38,11 @@ <%= wikitoolbar_for 'job_description' %> + + <% unless @job.new_record? %> + <%= f.text_area :notes, cols: 60, rows: 15, class: "wiki-edit", + data: { auto_complete: true }, id: "job_notes" %> + <%= wikitoolbar_for 'job_notes' %> + <% end %> <%= f.submit %> <% end %> diff --git a/app/views/jobs/show.html.erb b/app/views/jobs/show.html.erb index 940e38b..5c8e7e5 100644 --- a/app/views/jobs/show.html.erb +++ b/app/views/jobs/show.html.erb @@ -43,3 +43,7 @@ + +