Show jobs in time entries view
This commit is contained in:
parent
de3762bf1c
commit
afcb4c3ccc
|
@ -1,3 +1,5 @@
|
|||
include ActionView::Helpers::UrlHelper
|
||||
|
||||
class Job < ActiveRecord::Base
|
||||
validates :starts_on,
|
||||
:ends_on,
|
||||
|
@ -5,6 +7,7 @@ class Job < ActiveRecord::Base
|
|||
presence: true
|
||||
|
||||
belongs_to :project
|
||||
has_many :time_entries
|
||||
|
||||
scope :project, ->(project) { where(project_id: project.id) }
|
||||
|
||||
|
@ -17,4 +20,9 @@ class Job < ActiveRecord::Base
|
|||
TimeEntry.where(job_id: id, activity_id: activity.id)
|
||||
.sum(:hours)
|
||||
end
|
||||
|
||||
def to_s
|
||||
ActionView::Base.send(:include, Rails.application.routes.url_helpers)
|
||||
ActionController::Base.helpers.link_to name, ActionController::Base.helpers.job_path(self, project_id: project.id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
# English strings go here for Rails i18n
|
||||
en:
|
||||
# my_label: "My label"
|
||||
field_job: Job
|
||||
|
|
6
init.rb
6
init.rb
|
@ -10,4 +10,10 @@ 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'
|
||||
|
||||
Rails.application.config.before_initialize do
|
||||
Rails.logger.info "Patch Jobs"
|
||||
TimeEntryQuery.send(:include, TimeEntryQueryPatch)
|
||||
TimeEntry.send(:include, TimeEntryPatch)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_dependency 'time_entry'
|
||||
|
||||
module TimeEntryPatch
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
belongs_to :job
|
||||
end
|
||||
end
|
|
@ -0,0 +1,39 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_dependency 'time_entry_query'
|
||||
|
||||
# Here we add the jobs field so it shows in a time entry query as an available column.
|
||||
module TimeEntryQueryPatch
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
include InstanceMethods
|
||||
|
||||
# alias_method :initialize_available_filters_without_jobs, :initialize_available_filters
|
||||
# alias_method :initialize_available_filters, :initialize_available_filters_with_jobs
|
||||
|
||||
alias_method :available_columns_without_jobs, :available_columns
|
||||
alias_method :available_columns, :available_columns_with_jobs
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
# def initialize_available_filters_with_jobs
|
||||
# initialize_available_filters_without_jobs
|
||||
# initialize_issue_jobs_filter
|
||||
# end
|
||||
|
||||
def available_columns_with_jobs
|
||||
if @available_columns.nil?
|
||||
@available_columns = available_columns_without_jobs
|
||||
@available_columns << QueryColumn.new(:job)
|
||||
else
|
||||
available_columns_without_jobs
|
||||
end
|
||||
@available_columns
|
||||
end
|
||||
|
||||
def sql_for_issue_jobs_field(_field, operator, values)
|
||||
build_sql_for_jobs_field klass: Issue, operator: operator, values: values
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue