Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

license type #39

Open
wants to merge 7 commits into
base: redmine-3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,19 @@ services:
- postgresql

rvm:
- 1.9.3
- 2.2.0

gemfile:
- $REDMINE_PATH/Gemfile

env:
- REDMINE_VER=2.3.3 DB=mysql
- REDMINE_VER=2.6.9 DB=mysql
- REDMINE_VER=3.2.1 DB=mysql

- REDMINE_VER=2.3.3 DB=postgresql
- REDMINE_VER=2.6.9 DB=postgresql
- REDMINE_VER=3.2.1 DB=postgresql

matrix:
exclude:
- rvm: 2.2.0
env: REDMINE_VER=2.3.3 DB=mysql
gemfile: $REDMINE_PATH/Gemfile
- rvm: 2.2.0
env: REDMINE_VER=2.6.9 DB=mysql
gemfile: $REDMINE_PATH/Gemfile
- rvm: 1.9.3
env: REDMINE_VER=3.2.1 DB=mysql
gemfile: $REDMINE_PATH/Gemfile

- rvm: 2.2.0
env: REDMINE_VER=2.3.3 DB=postgresql
gemfile: $REDMINE_PATH/Gemfile
- rvm: 2.2.0
env: REDMINE_VER=2.6.9 DB=postgresql
gemfile: $REDMINE_PATH/Gemfile
- rvm: 1.9.3
env: REDMINE_VER=3.2.1 DB=postgresql
gemfile: $REDMINE_PATH/Gemfile
- REDMINE_VER=3.1.6 DB=mysql
- REDMINE_VER=3.2.3 DB=mysql
- REDMINE_VER=3.3.0 DB=mysql

- REDMINE_VER=3.1.6 DB=postgresql
- REDMINE_VER=3.2.3 DB=postgresql
- REDMINE_VER=3.3.0 DB=postgresql

before_install:
- export PLUGIN_NAME=redmine_custom_reports
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Redmine Custom Reports Plugin (with charts)

[![Build Status](https://travis-ci.org/nodecarter/redmine_custom_reports.png?branch=master)](https://travis-ci.org/nodecarter/redmine_custom_reports)
[![Code Climate](https://codeclimate.com/github/nodecarter/redmine_custom_reports.png)](https://codeclimate.com/github/nodecarter/redmine_custom_reports)
[![Build Status](https://travis-ci.org/Restream/redmine_custom_reports.svg?branch=master)](https://travis-ci.org/Restream/redmine_custom_reports)
[![Code Climate](https://codeclimate.com/github/Restream/redmine_custom_reports/badges/gpa.svg)](https://codeclimate.com/github/Restream/redmine_custom_reports)

Redmine plugin to create project reports using [d3.js](http://d3js.org/) charts (with using [NVD3](http://nvd3.org/)). The data for the report - the number of filtered issues grouped by a column.

Expand All @@ -19,7 +19,7 @@ There are public and private custom reports. Permission "View custom reports" al
If you are downloading the plugin directly from GitHub,
you can do so by changing into your plugin directory and issuing a command like

git clone git://github.com/nodecarter/redmine_custom_reports.git
git clone git://github.com/Restream/redmine_custom_reports.git

2. Run the following command to upgrade your database (make a db backup before).

Expand All @@ -33,10 +33,10 @@ Enable plugin at project level. Now you will see "Custom report" tab at the proj

## Screenshot

![Sample](https://github.com/nodecarter/redmine_custom_reports/raw/master/screenshot.png)
![Sample](screenshot.png)

## Compatibility

This version supports only redmine 2.x.
This version supports redmine 2.x and 3.x

For all tested versions see the "tests matrix":https://travis-ci.org/nodecarter/redmine_custom_reports
For all tested versions see the "tests matrix":https://travis-ci.org/Restream/redmine_custom_reports
22 changes: 11 additions & 11 deletions app/controllers/custom_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class CustomReportsController < ApplicationController

before_filter :find_project_by_project_id
before_filter :authorize
before_filter :find_custom_reports, :only => [:index, :show, :new, :edit]
before_filter :find_custom_report, :only => [:show, :edit, :update, :destroy]
before_filter :authorize_to_manage, :only => [:edit, :update, :destroy]
before_filter :find_custom_reports, only: [:index, :show, :new, :edit]
before_filter :find_custom_report, only: [:show, :edit, :update, :destroy]
before_filter :authorize_to_manage, only: [:edit, :update, :destroy]

helper :queries
include QueriesHelper
Expand All @@ -32,11 +32,11 @@ def create

if @custom_report.save
redirect_to url_for(
:controller => "custom_reports",
:action => "show", :project_id => @project, :id => @custom_report.id),
:notice => l(:message_custom_reports_created)
controller: 'custom_reports',
action: 'show', project_id: @project, id: @custom_report.id),
notice: l(:message_custom_reports_created)
else
render :action => "new"
render action: 'new'
end
end

Expand All @@ -53,11 +53,11 @@ def update
params.required(:custom_report).permit! if params.class.method_defined? :required
if @custom_report.update_attributes(params[:custom_report])
redirect_to url_for(
:controller => "custom_reports",
:action => "show", :project_id => @project, :id => @custom_report.id),
:notice => l(:message_custom_reports_updated)
controller: 'custom_reports',
action: 'show', project_id: @project, id: @custom_report.id),
notice: l(:message_custom_reports_updated)
else
render :action => "edit"
render action: 'edit'
end
end

Expand Down
19 changes: 11 additions & 8 deletions app/helpers/custom_reports_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module CustomReportsHelper
def sanitized_object_name(object_name)
object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/, '_').sub(/_$/, '')
end

def operators_for_select(filter_type)
Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]}
Query.operators_by_filter_type[filter_type].collect { |o| [l(Query.operators[o]), o] }
end

def query_options_for_select(query)
Expand All @@ -19,15 +19,18 @@ def query_options_for_select(query)

def link_to_add_custom_report_series(name, f)
new_object = f.object.series.build
id = new_object.object_id
fields = f.fields_for(:series, new_object, :child_index => id) do |builder|
render("series", :f => builder)
id = new_object.object_id
fields = f.fields_for(:series, new_object, child_index: id) do |builder|
render('series', f: builder)
end
link_to(name, '#', :class => "add-custom-report-series",
"data-id" => id, "data-fields" => fields.gsub("\n", ""))
link_to(name, '#',
class: 'add-custom-report-series',
'data-id' => id,
'data-fields' => fields.gsub("\n", '')
)
end

def width_style_for_series(custom_report)
"width:100%;"
'width:100%;'
end
end
30 changes: 15 additions & 15 deletions app/models/custom_report.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
class CustomReport < ActiveRecord::Base
unloadable

CHART_TYPES = %w(undev_pie pie donut bar horizontal_bar stacked_bar)
CHART_TYPES = %w(undev_pie pie donut bar horizontal_bar stacked_bar)
MULTI_SERIES = %w(horizontal_bar stacked_bar)

belongs_to :project
belongs_to :user
has_many :series, :class_name => "CustomReportSeries"
has_many :series, class_name: 'CustomReportSeries'

validates_presence_of :project
validates_presence_of :user
validates_presence_of :name
validates_presence_of :group_by
validates_presence_of :null_text
validates_inclusion_of :chart_type, :in => CHART_TYPES
validates_inclusion_of :chart_type, in: CHART_TYPES

accepts_nested_attributes_for :series, :allow_destroy => true
accepts_nested_attributes_for :series, allow_destroy: true

scope :visible, lambda { |*args|
user = args.shift || User.current
user_id = user.logged? ? user.id : 0
where "(#{table_name}.is_public = ? OR #{table_name}.user_id = ?)", true, user_id
user = args.shift || User.current
user_id = user.logged? ? user.id : 0
where "(#{table_name}.is_public = ? OR #{table_name}.user_id = ?)", true, user_id
}

scope :by_name, -> { order("name") }
scope :by_name, -> { order('name') }

def groupable_columns
QueryExt.new().groupable_columns.select do |col|
if col.respond_to? :custom_field
col.custom_field.is_for_all ||
project.all_issue_custom_fields.include?(col.custom_field)
project.all_issue_custom_fields.include?(col.custom_field)
else
true
end
Expand All @@ -38,10 +38,10 @@ def groupable_columns

def info
{
:chart_type => chart_type,
:group_by_caption => group_by_column.try(:caption),
:series_count => series.count,
:multi_series => multi_series?
chart_type: chart_type,
group_by_caption: group_by_column.try(:caption),
series_count: series.count,
multi_series: multi_series?
}
end

Expand All @@ -61,8 +61,8 @@ def data

def allowed_to_manage?(user = User.current)
user.allowed_to?(
is_public? ? :manage_public_custom_reports : :manage_custom_reports,
project
is_public? ? :manage_public_custom_reports : :manage_custom_reports,
project
)
end

Expand Down
25 changes: 14 additions & 11 deletions app/models/custom_report_series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ class CustomReportSeries < ActiveRecord::Base

serialize :filters

belongs_to :custom_report, :inverse_of => :series
belongs_to :custom_report, inverse_of: :series

validates :name, presence: true

def query
@query ||= build_query
Expand All @@ -12,24 +14,25 @@ def query
def data(data_keys = [])
_keys = data_keys.dup
_data = {
:key => name,
:values => data_hash.map do |k, v|
key: name,
values: data_hash.map do |k, v|
_keys.delete(k)
{ :label => data_label_text(k), :value => v }
{ label: data_label_text(k), value: v }
end
}
_keys.each do |key|
_data[:values] << { :label => data_label_text(key), :value => 0 }
_data[:values] << { label: data_label_text(key), value: 0 }
end
_data
end

def data_hash
@data_hash ||= (query.issue_count_by_group || {})
true
@data_hash ||= (query.result_count_by_group || {})
end

def flt=(*args)
filters_hash = args.extract_options!
filters_hash = args.extract_options!
query.filters = {}
query.add_filters(filters_hash[:f], filters_hash[:op], filters_hash[:v])
self.filters = query.filters
Expand All @@ -39,10 +42,10 @@ def flt=(*args)

def build_query
QueryExt.new(
:name => name,
:filters => filters,
:group_by => custom_report.try(:group_by),
:project => custom_report.try(:project))
name: name,
filters: filters,
group_by: custom_report.try(:group_by),
project: custom_report.try(:project))
end

def data_label_text(label)
Expand Down
39 changes: 16 additions & 23 deletions app/views/custom_reports/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,64 +1,57 @@
<% content_for :header_tags do %>
<script type="text/javascript">
if(typeof(jQuery) == 'undefined') {
document.write("<%= escape_javascript(javascript_include_tag('jquery-1.8.2.min.js', :plugin => 'redmine_custom_reports')) %>");
document.write("<%= escape_javascript(javascript_include_tag('jquery-noconflict.js', :plugin => 'redmine_custom_reports')) %>");
}
</script>
<%= javascript_include_tag 'custom_report_edit.js', :plugin => 'redmine_custom_reports' %>
<%= javascript_include_tag 'custom_report_edit.js', plugin: 'redmine_custom_reports' %>
<% end %>

<%= labelled_form_for custom_report,
:url => url,
:html => { :id => 'custom-report-form' } do |f| %>
url: url,
html: { id: 'custom-report-form' } do |f| %>

<%= error_messages_for custom_report %>

<div class="box">

<div class="tablular">
<p>
<label for="custom_report_name"><%= l(:field_name) %></label>
<%= text_field 'custom_report', 'name', :size => 80 %>
<%= f.text_field :name, size: 80, required: true %>
</p>

<p>
<label for="custom_report_description"><%= l(:field_description) %></label>
<%= text_field 'custom_report', 'description', :size => 80 %>
<%= text_field 'custom_report', 'description', size: 80 %>
</p>

<p>
<label for="custom_report_chart_type"><%= l(:field_chart_type) %></label>
<%= select 'custom_report', 'chart_type',
CustomReport::CHART_TYPES.collect { |ct| [l("label_chart_type_#{ct}"), ct] },
:include_blank => false %>
CustomReport::CHART_TYPES.collect { |ct| [l("label_chart_type_#{ct}"), ct] },
include_blank: false %>
</p>

<% if User.current.admin? || User.current.allowed_to?(:manage_public_custom_reports, @project) %>
<p>
<label for="custom_report_is_public"><%=l(:field_is_public)%></label>
<label for="custom_report_is_public"><%= l(:field_is_public) %></label>
<%= check_box 'custom_report', 'is_public',
:onchange => (User.current.admin? ? nil : 'if (this.checked) {$("custom_report_is_for_all").checked = false; $("custom_report_is_for_all").disabled = true;} else {$("custom_report_is_for_all").disabled = false;}') %>
onchange: (User.current.admin? ? nil : 'if (this.checked) {$("custom_report_is_for_all").checked = false; $("custom_report_is_for_all").disabled = true;} else {$("custom_report_is_for_all").disabled = false;}') %>
</p>
<% end %>

<p>
<label for="custom_report_group_by"><%= l(:field_group_by) %></label>
<%= select 'custom_report', 'group_by',
@custom_report.groupable_columns.collect {|c| [c.caption, c.name.to_s]},
:include_blank => true %>
@custom_report.groupable_columns.collect { |c| [c.caption, c.name.to_s] },
include_blank: false %>
</p>

<p>
<label for="custom_report_null_text"><%= l(:field_null_text) %></label>
<%= text_field 'custom_report', 'null_text', :size => 80 %>
<%= text_field 'custom_report', 'null_text', size: 80 %>
</p>
</div>

<%= f.fields_for :series do |series_fields| %>
<%= render :partial => 'series', :locals => { :f => series_fields } %>
<% end %>
<%= link_to_add_custom_report_series l(:message_add_custom_report_series), f %>
<%= f.fields_for :series do |series_fields| %>
<%= render partial: 'series', locals: { f: series_fields } %>
<% end %>
<%= link_to_add_custom_report_series l(:message_add_custom_report_series), f %>

</div>

Expand Down
10 changes: 5 additions & 5 deletions app/views/custom_reports/_links.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<% if custom_reports && custom_reports.any? %>
<% custom_reports.each do |custom_report| %>
<%= link_to custom_report.name,
{ :controller => 'custom_reports',
:action => 'show',
:project_id => @project,
:id => custom_report.id } %><br />
<%= link_to custom_report.name,
{ controller: 'custom_reports',
action: 'show',
project_id: @project,
id: custom_report.id } %><br />
<% end %>
<% else %>
<%= l(:label_no_data) %>
Expand Down
Loading