Verified Commit 42402364 authored by Khang Le's avatar Khang Le
Browse files

Merge branch 'feature/report-with-filter'

# Conflicts:
#	app/controllers/sp_report_controller.rb
#	app/views/sp_report/_report_table.html.erb
Showing with 98 additions and 11 deletions
+98 -11
class SpReportController < ApplicationController
before_action :find_project_by_project_id, only: :proj_available
include ServicePacksReportHelper
NUMBER_OF_FILLED_COLUMN = 8
def report
# json & html endpoint
# params[:service_pack, :start_date, :end_date]
# binding.pry
begin
if params[:proj_id].present?
@project = Project.find_by!(id: params[:proj_id])
else
@project = Project.find(params[:project_id]) # find by slug
end
spid = params[:service_pack_id]
if spid.present?
sp = ServicePack.find(spid)
end
rescue ActiveRecord::RecordNotFound
render(status: 404) and return
end
unless User.current.admin? || User.current.allowed_to?(:see_assigned_service_packs, @project)
render status: 404 and return
end
respond_to do |format|
format.html {
# change this to debug
# render plain: sp_available
query(service_pack: sp, project: @project,
lite: true)
get_projects_available
get_available_service_packs
render -'show'
}
format.json {
query(service_pack: sp, project: @project,
lite: true)
render json: @entries
}
format.csv {
query(service_pack: sp, project: @project)
render csv: csv_extractor(@entries), filename: "sp-report-#{Date.today}.csv"
}
end
end
def proj_available
render json: { projects: get_projects_available.pluck(:id, :name), preselect: @project.id }
end
def sp_available
render json: { service_packs: get_available_service_packs, preselect: nil } # just use the first one
end
end
\ No newline at end of file
......@@ -31,12 +31,6 @@
</ul>
</div>
</div>
<div class="sp assigned">
<div class="sp-content">
<%= render partial: -'active_assignments' %>
</div>
</div>
</section>
<div class='button-container clearfix'>
......
<div class="generic-table--container">
<div class="generic-table--results-container">
<table interactive-table="true" class="generic-table" id="sortable-table">
<colgroup>
<%# angular boilerplate %>
<%= (-'<col highlight-col>' * SpReportController::NUMBER_OF_FILLED_COLUMN).html_safe %>
</colgroup>
<thead>
<tr>
<th style="width: 4em;"><div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span class="sort desc">Time</span></div></div></th>
<th><div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>User</span></div></div></th>
<th><div class="generic-table--sort-header-outer" style="width: 6em;"><div class="generic-table--sort-header"><span>Service Pack</span></div></div></th>
<th><div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>Activity</span></div></div></th>
<th><div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>Project</span></div></div></th>
<th><div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>Work Package</span></div></div></th>
<th style="width: 4em;"><div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>Units</span></div></div></th>
<th style="width: 4em;"><div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>Hours</span></div></div></th>
</tr>
</thead>
<tbody>
<% user_time_zone = User.current.time_zone %>
<%# offset = (user_time_zone || Time.now).utc_offset.to_i / 60 %>
<% @entries.each do |entry| %>
<tr>
<%= content_tag :td, (user_time_zone.nil? ? entry[-'spent_on'] : entry[-'spent_on'].to_time.in_time_zone(user_time_zone)).strftime(-'%F %H:%M') %>
<%= content_tag :td, entry[-'user_name'] %>
<%= content_tag :td, entry[-'sp_name'] %>
<%= content_tag :td, entry[-'activity_name'] %>
<%= content_tag :td, entry[-'project_name'], title: entry[-'project_name']%>
<%= content_tag :td, "#{entry[-'type_name']} \##{entry[-'work_package_id']}: #{entry[-'subject']}", title: entry[-'subject']%>
<%= content_tag :td, entry[-'units'].round(0) %>
<%= content_tag :td, -"%.2f" % entry[-'hours'].round(2) %>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
\ No newline at end of file
......@@ -10,10 +10,7 @@ module OpenProject::ServicePacks
# Create an SP_entry with the log entry cost.
# Subtract the remaining counter of SP to the cost.
unless project.enabled_modules.find_by(name: -'service_packs')
service_pack_id = nil
return
end
return unless project.enabled_modules.find_by(name: -'service_packs')
assignments = project.assigns.active.pluck(:service_pack_id)
if assignments.empty?
......@@ -107,7 +104,7 @@ module OpenProject::ServicePacks
after_create :log_consumed_units
before_update :update_consumed_units # to stop persisting changed SP
before_destroy :get_consumed_units_back
validates :service_pack_id, numericality: {only_integer: true, greater_than: 0}, allow_nil: true
# validates :service_pack_id, numericality: {only_integer: true, greater_than: 0}, allow_nil: true
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment