From ff46b9ac95eb7a53dacaed4e854964c2c4997ca8 Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 8 Jun 2015 16:20:21 -0700 Subject: * added totals * better link * report header * configurable rate * version summary --- README.md | 17 +++++- app/controllers/version_reports_controller.rb | 1 + app/helpers/version_reports_helper.rb | 67 +++++++++++++++++++--- app/views/hooks/_view_report_link.html.erb | 8 ++- app/views/version_reports/_issue_row.html.erb | 2 +- app/views/version_reports/_main_issue_row.html.erb | 4 +- app/views/version_reports/_project_row.html.erb | 2 +- app/views/version_reports/show.html.erb | 16 ++++++ init.rb | 18 +++++- 9 files changed, 118 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0ac14b3..8d0e4a3 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,20 @@ Installation: Configuration: * You grant the permission 'view reports' to a user in order to be able to view the report. -* Create a custom field called 'Hour Budget' +* Create a 'deliverable' tracker, available only to your reporting project. + +Custom fields: + +* Issues + * "Hour Budget": an integer field for 'deliverable' issues. + * "Price": an string field for 'deliverable' issues + (used to override the money amount displayed, if present). +* Versions + * "Header URL": an string field for target versions. + If present, the image will be added to the report at the top. + * "Summary": a text field for Textile formatted summary + to appear at the top of a report ('description' is used for the heading). + * "Rate": a text field for the hourly rate, including currency ("$50"). License: @@ -25,4 +38,4 @@ The same as Redmine (GNU GENERAL PUBLIC LICENSE Version 2) Copyright: -2015 (c) LEAP Encryption Access Project \ No newline at end of file +2015 (c) LEAP Encryption Access Project diff --git a/app/controllers/version_reports_controller.rb b/app/controllers/version_reports_controller.rb index a2755ed..6979943 100644 --- a/app/controllers/version_reports_controller.rb +++ b/app/controllers/version_reports_controller.rb @@ -7,6 +7,7 @@ class VersionReportsController < ApplicationController before_filter :alias_model_object before_filter :find_project_from_association, :only => [:show] before_filter :authorize + helper :custom_fields def show @show_time = params[:time] != 'false' diff --git a/app/helpers/version_reports_helper.rb b/app/helpers/version_reports_helper.rb index ced3d07..166d98a 100644 --- a/app/helpers/version_reports_helper.rb +++ b/app/helpers/version_reports_helper.rb @@ -9,23 +9,46 @@ module VersionReportsHelper link_to text, issue_path(issue) end - def hours_to_money(hours) - "$%i" % (hours*50) + def issue_time(issue) + l_hours(issue.total_spent_hours) if @show_time end - def hour_budget(issue) - v = issue.custom_field_values.detect {|value| - value.custom_field.name == 'Hour Budget' + def issue_money(issue, *options) + if @show_money + amount = custom_price(issue) || hours_to_money(@version, issue.total_spent_hours) + if options.include?(:format) + "$#{amount}" + else + amount + end + end + end + + def hours_to_money(version, hours) + @rate ||= (custom_field_value(version, :rate)||DEFAULT_REPORT_RATE).gsub(/[^0-9\.]/, '').to_f + (hours||0) * @rate + end + + # + # name is a key for REPORT_CUSTOM_FIELDS hash + # + def custom_field(object, name) + object.custom_field_values.detect {|value| + value.custom_field.name == REPORT_CUSTOM_FIELDS[name] } + end + + def custom_field_value(object, name) + v = custom_field(object, name) if v - v.value.to_i + v.value end end def hour_budget_error(issue) return unless @show_time - budget = hour_budget(issue) - if issue.total_spent_hours != budget + budget = (custom_field_value(issue, :hours) || 0).to_i + if issue.total_spent_hours.round != budget.round if issue.total_spent_hours < budget content_tag :div, :class => 'flash error' do "%s under budget!" % l_hours(budget - issue.total_spent_hours) @@ -38,4 +61,32 @@ module VersionReportsHelper end end + def custom_price(issue) + custom_field_value(issue, :price) + end + + def report_header(version) + url = custom_field_value(version, :header) + if !url.present? + url = DEFAULT_REPORT_HEADER + end + %().html_safe + end + + # show_value requires CustomFieldsHelper + def report_summary(version) + show_value(custom_field(version, :summary)) + end + + def total_time(version, issues) + l_hours(issues.sum(&:total_spent_hours)) if @show_time + end + + def total_money(version, issues) + if @show_money + total = issues.sum {|issue| issue_money(issue)} + "$#{total}" + end + end + end diff --git a/app/views/hooks/_view_report_link.html.erb b/app/views/hooks/_view_report_link.html.erb index fdd59c9..b9758a3 100644 --- a/app/views/hooks/_view_report_link.html.erb +++ b/app/views/hooks/_view_report_link.html.erb @@ -1 +1,7 @@ -

<%= link_to 'Time Tracking Report', version_report_path %> \ No newline at end of file +
+
+
+
+
+
+
diff --git a/app/views/version_reports/_issue_row.html.erb b/app/views/version_reports/_issue_row.html.erb index 7d89e69..25c11c6 100644 --- a/app/views/version_reports/_issue_row.html.erb +++ b/app/views/version_reports/_issue_row.html.erb @@ -4,7 +4,7 @@ <%= display_issue(issue, :tracker) %> - <%= l_hours(issue.total_spent_hours) if @show_time %> + <%= issue_time(issue) %>   diff --git a/app/views/version_reports/_main_issue_row.html.erb b/app/views/version_reports/_main_issue_row.html.erb index c83eb6d..8ca4904 100644 --- a/app/views/version_reports/_main_issue_row.html.erb +++ b/app/views/version_reports/_main_issue_row.html.erb @@ -5,10 +5,10 @@ <%= hour_budget_error(issue) %> - <%= l_hours(issue.total_spent_hours) if @show_time %> + <%= issue_time(issue) %> - <%= hours_to_money(issue.total_spent_hours) if @show_money %> + <%= issue_money(issue, :format) %> diff --git a/app/views/version_reports/_project_row.html.erb b/app/views/version_reports/_project_row.html.erb index ac0acd2..dab51e2 100644 --- a/app/views/version_reports/_project_row.html.erb +++ b/app/views/version_reports/_project_row.html.erb @@ -1,5 +1,5 @@ - + <%= project.name %> diff --git a/app/views/version_reports/show.html.erb b/app/views/version_reports/show.html.erb index 09c2b20..e8c4f70 100644 --- a/app/views/version_reports/show.html.erb +++ b/app/views/version_reports/show.html.erb @@ -1,6 +1,22 @@ <% html_title @version.name %> +<%= report_header(@version) %> + +

<%= @version.description %>

+

<%= report_summary(@version) %>

+ +<% if @show_time || @show_money %> + + + + + +<% end %> <% if @issues.present? %> <%- @issues.each do |issue| -%> <%= render :partial => 'main_issue_row', :locals => {:issue => issue} %> diff --git a/init.rb b/init.rb index fe8e8a3..c85abd9 100644 --- a/init.rb +++ b/init.rb @@ -1,10 +1,24 @@ require_dependency 'version_report/hooks' +# +# The name of custom fields +# +REPORT_CUSTOM_FIELDS = { + :hours => 'Hours Budget', + :price => 'Price', + :header => 'Header URL', + :summary => 'Summary', + :rate => 'Rate' +} + +DEFAULT_REPORT_HEADER = 'https://leap.se/git/leap_assets.git/blob_plain/HEAD:/print/letterhead.png' +DEFAULT_REPORT_RATE = '$50' + Redmine::Plugin.register :version_report do name 'Version Report plugin' author 'LEAP' - description 'Show detailed reports for target versions' - version '0.0.1' + description 'Show detailed reports for target versions.' + version '0.2' url 'https://leap.se/git/version_report' permission :view_reports, :version_reports => :show -- cgit v1.2.3
Total + <%= total_time(@version, @issues) %> + + <%= total_money(@version, @issues) if @show_money %> +