14 |
14 |
<%= hidden_field_tag 'criteria[]', criterion, :id => nil %>
|
15 |
15 |
<% end %>
|
16 |
16 |
<%= render :partial => 'timelog/date_range' %>
|
|
17 |
<p class="contextual"><%= link_to l(:label_statistics), '#', :onclick => "showAndScrollTo('timelog_chart')", :class => 'icon icon-stats' if @report.criteria.any? && @report.hours.any? %></p>
|
17 |
18 |
|
18 |
19 |
<p><label for='columns'><%= l(:label_details) %></label>: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'],
|
19 |
20 |
[l(:label_month), 'month'],
|
... | ... | |
68 |
69 |
<% other_formats_links do |f| %>
|
69 |
70 |
<%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
|
70 |
71 |
<% end %>
|
|
72 |
<div id="timelog_chart"></div>
|
71 |
73 |
<% end %>
|
72 |
74 |
<div id="csv-export-options" style="display: none;">
|
73 |
75 |
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
|
... | ... | |
88 |
90 |
|
89 |
91 |
|
90 |
92 |
<%= javascript_tag do %>
|
|
93 |
function renderChart(canvas_id, chart_data, title){
|
|
94 |
var backgroundColors = ['rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)'];
|
|
95 |
var borderColors = ['rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)'];
|
|
96 |
chart_data.datasets[0].backgroundColor = [];
|
|
97 |
chart_data.datasets[0].borderColor = [];
|
|
98 |
chart_data.datasets[0].borderWidth = [];
|
|
99 |
for (var i = 0; i < chart_data.datasets[0].data.length; i++) {
|
|
100 |
chart_data.datasets[0].backgroundColor[i] = backgroundColors[i % backgroundColors.length];
|
|
101 |
chart_data.datasets[0].borderColor[i] = borderColors[i % backgroundColors.length];
|
|
102 |
chart_data.datasets[0].borderWidth[i] = 1;
|
|
103 |
}
|
|
104 |
if (chart_data.type=='horizontalBar' & chart_data.labels.length > 40) {
|
|
105 |
var ctx = $(canvas_id);
|
|
106 |
ctx.attr('height', chart_data.labels.length * 5);
|
|
107 |
}
|
|
108 |
new Chart($(canvas_id), {
|
|
109 |
type: chart_data.type,
|
|
110 |
data: chart_data,
|
|
111 |
options: {
|
|
112 |
responsive: true,
|
|
113 |
legend: { display: false },
|
|
114 |
title: { display: true, text: title },
|
|
115 |
scales: {
|
|
116 |
xAxes: [ { ticks: { beginAtZero: true } } ],
|
|
117 |
yAxes: [ { ticks: { beginAtZero: true } } ]
|
|
118 |
},
|
|
119 |
},
|
|
120 |
});
|
|
121 |
}
|
91 |
122 |
$(document).ready(function(){
|
92 |
123 |
$('input#csv-export-button').click(function(){
|
93 |
124 |
$('form input#encoding').val($('select#encoding option:selected').val());
|
... | ... | |
95 |
126 |
$('form#query_form').attr('action', '<%= _report_time_entries_path(@project, nil) %>');
|
96 |
127 |
hideModal(this);
|
97 |
128 |
});
|
|
129 |
<% report_to_chart_datas(@report, params[:columns]).each do |column, chart_data| %>
|
|
130 |
$('#timelog_chart').append('<canvas id="<%= column %>_timelog_chart"></canvas>');
|
|
131 |
renderChart("#<%= column %>_timelog_chart",
|
|
132 |
<%= chart_data.to_json.html_safe %>,
|
|
133 |
"<%= l("label_total_spent_time_per", :column => l_or_humanize(column)) %>");
|
|
134 |
<% end %>
|
98 |
135 |
});
|
99 |
136 |
<% end %>
|
|
137 |
<% content_for :header_tags do %>
|
|
138 |
<%= javascript_include_tag "Chart.bundle.min" %>
|
|
139 |
<% end %>
|