summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-06-08 16:20:21 -0700
committerelijah <elijah@riseup.net>2015-06-08 16:20:21 -0700
commitff46b9ac95eb7a53dacaed4e854964c2c4997ca8 (patch)
treefae6a6fdb36e1eb0a5ada0528afd482b556028ed
parent4d976166d360462b411545256a6b00eba3080a5a (diff)
* added totals
* better link * report header * configurable rate * version summary
-rw-r--r--README.md17
-rw-r--r--app/controllers/version_reports_controller.rb1
-rw-r--r--app/helpers/version_reports_helper.rb67
-rw-r--r--app/views/hooks/_view_report_link.html.erb8
-rw-r--r--app/views/version_reports/_issue_row.html.erb2
-rw-r--r--app/views/version_reports/_main_issue_row.html.erb4
-rw-r--r--app/views/version_reports/_project_row.html.erb2
-rw-r--r--app/views/version_reports/show.html.erb16
-rw-r--r--init.rb18
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
+ %(<img src="#{url}" style="max-width:100%"/>).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 @@
-<br><br><%= link_to 'Time Tracking Report', version_report_path %> \ No newline at end of file
+<br>
+<br>
+<form method='get' action='<%= version_report_path %>'>
+ <button type="submit">Detailed Report</button><br>
+ <label><input type="checkbox" name="time" value="false">Hide Time</label><br>
+ <label><input type="checkbox" name="money" value="false">Hide Money</label><br>
+</form>
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) %>
</td>
<td>
- <%= l_hours(issue.total_spent_hours) if @show_time %>
+ <%= issue_time(issue) %>
</td>
<td>
&nbsp;
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) %>
</td>
<td>
- <%= l_hours(issue.total_spent_hours) if @show_time %>
+ <%= issue_time(issue) %>
</td>
<td>
- <%= hours_to_money(issue.total_spent_hours) if @show_money %>
+ <%= issue_money(issue, :format) %>
</td>
</tr>
<tr>
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 @@
<tr>
- <td colspan="2">
+ <td colspan="3">
<b><%= project.name %></b>
</td>
</tr>
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) %>
+
+<h1><%= @version.description %></h1>
+<p><%= report_summary(@version) %></p>
+
<table>
+<% if @show_time || @show_money %>
+ <tr>
+ <td><b>Total</b></td>
+ <td>
+ <%= total_time(@version, @issues) %>
+ </td>
+ <td>
+ <%= total_money(@version, @issues) if @show_money %>
+ </td>
+ </tr>
+<% 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