[wip] Add journals to jobs

This commit is contained in:
Trevor Vallender 2024-02-04 14:32:27 +00:00
parent c2e16d729d
commit c2f0290b55
7 changed files with 112 additions and 0 deletions

View File

@ -7,6 +7,7 @@ class JobsController < ApplicationController
end end
def show def show
@journals = @job.journals
end end
def new def new
@ -18,6 +19,7 @@ class JobsController < ApplicationController
end end
def update def update
@job.init_journal(User.current)
if @job.update(remove_empty_time_budgets(job_params)) if @job.update(remove_empty_time_budgets(job_params))
redirect_to project_job_path(@job.project, @job) redirect_to project_job_path(@job.project, @job)
else else
@ -55,6 +57,7 @@ class JobsController < ApplicationController
:name, :name,
:description, :description,
:category_id, :category_id,
:notes,
time_budgets_attributes: [:id, :category_id, :hours, :job_id, :_destroy] time_budgets_attributes: [:id, :category_id, :hours, :job_id, :_destroy]
) )
end end

View File

@ -12,4 +12,37 @@ module JobsHelper
(#{l_hours_short(budget.total_time_logged)}/#{l_hours_short(budget.hours)})", (#{l_hours_short(budget.total_time_logged)}/#{l_hours_short(budget.hours)})",
class: "progress") class: "progress")
end 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 end

View File

@ -12,13 +12,21 @@ class Job < ActiveRecord::Base
has_many :time_entries, dependent: :restrict_with_error has_many :time_entries, dependent: :restrict_with_error
has_many :time_budgets, dependent: :destroy 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 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 :project_or_parent, ->(project) { where(project_id: [project&.id, project&.parent&.id]) }
scope :active, -> { where(starts_on: ..Date.today, ends_on: Date.today..) } scope :active, -> { where(starts_on: ..Date.today, ends_on: Date.today..) }
safe_attributes 'name', 'description' safe_attributes 'name', 'description'
after_save :create_journal
def with_all_time_budgets def with_all_time_budgets
time_budgets.build(job_id: id, category_id: nil) unless time_budgets.where(category_id: nil).exists? 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| 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) ActionController::Base.helpers.link_to name, ActionController::Base.helpers.project_job_path(project, self)
end 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 def self.fields_for_order_statement
"jobs.name" "jobs.name"
end end

View File

@ -38,5 +38,11 @@
<%= wikitoolbar_for 'job_description' %> <%= wikitoolbar_for 'job_description' %>
</div> </div>
<% 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 %> <%= f.submit %>
<% end %> <% end %>

View File

@ -43,3 +43,7 @@
</div> </div>
</div> </div>
</div> </div>
<div id="history">
<%= render_tabs job_history_tabs, job_history_default_tab %>
</div>

View File

@ -0,0 +1,31 @@
<%
job = tab[:locals][:job]
journals = tab[:locals][:journals]
%>
<% reply_links = job.notes_addable? %>
<% journals.each_with_index do |journal, indice| %>
<div id="change-<%= journal.id %>" class="journal has-notes">
<div id="note-<%= indice %>" class="note">
<div class="contextual">
<span class="journal-actions">
<!-- TODO -->
</span>
<a href="#note-<%= journal.indice %>" class="journal-link"><%= indice %></a>
</div>
<h4 class="note-header">
<%= avatar(journal.user) %>
<%= authoring journal.created_on, journal.user, label: :label_updated_time_by %>
</h4>
<%= journal.notes%>
<% if journal.details.any? %>
<ul class="details">
<% details_to_strings(journal.visible_details).each do |string| %>
<li><%= string %></li>
<% end %>
</ul>
<% end %>
</div>
</div>
<% end %>

View File

@ -9,3 +9,5 @@ en:
enumeration_time_budget_category: Time budget categories enumeration_time_budget_category: Time budget categories
enumeration_job_category: Job categories enumeration_job_category: Job categories
History: History
Notes: Notes