added heavy filters. issue is now a heavy filter

git-svn-id: https://dev.finn.de/svn/cockpit/branches/deployment_merge@2153 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
p.tessenow 14 years ago
parent 47299d3c2e
commit 79e2d81333
  1. 9
      app/helpers/reporting_helper.rb
  2. 7
      app/models/cost_query/filter/base.rb
  3. 19
      app/models/cost_query/filter/issue_id.rb
  4. 2
      app/views/cost_reports/_filters.rhtml
  5. 21
      app/views/cost_reports/filters/_heavy_values.rhtml
  6. 27
      assets/javascripts/reporting.js

@ -14,6 +14,7 @@ module ReportingHelper
def html_elements(filter)
return text_elements filter if CostQuery::Operator.string_operators.all? { |o| filter.available_operators.include? o }
return date_elements filter if CostQuery::Operator.time_operators.all? { |o| filter.available_operators.include? o }
return heavy_object_elements filter if filter.heavy?
object_elements filter
end
@ -32,6 +33,14 @@ module ReportingHelper
{:name => :remove_filter, :filter_name => filter.underscore_name}]
end
def heavy_object_elements(filter)
[
{:name => :activate_filter, :filter_name => filter.underscore_name, :label => l(filter.label)},
{:name => :text, :text => l(:label_equals)},
{:name => :heavy_values, :filter_name => filter.underscore_name, :disable_controls => true},
{:name => :remove_filter, :filter_name => filter.underscore_name}]
end
def date_elements(filter)
[
{:name => :activate_filter, :filter_name => filter.underscore_name, :label => l(filter.label)},

@ -14,6 +14,13 @@ module CostQuery::Filter
attr_accessor :values
##
# A Filter is 'heavy' if it possibly returns a _hughe_ number of available_values.
# In that case the UI-guys should think twice about displaying all the values.
def self.heavy?
false
end
def value=(val)
self.values = [val]
end

@ -3,6 +3,23 @@ class CostQuery::Filter::IssueId < CostQuery::Filter::Base
def self.available_values(*)
issues = Project.visible.collect { |p| p.issues }.flatten.uniq.sort_by { |i| i.id }
issues.map { |i| ["##{i.id} #{i.subject.length>30 ? i.subject.first(26)+'...': i.subject}", i.id] }
issues.map { |i| [text_for_issue i, i.id] }
end
def self.heavy?
true
end
not_selectable! if heavy?
def self.text_for_issue(i)
i = i.first if i.is_a? Array
str = "##{i.id} "
str << (i.subject.length > 30 ? i.subject.first(26)+'...': i.subject)
end
def self.text_for_id(i)
text_for_issue Issue.find(i)
rescue ActiveRecord::RecordNotFound
""
end
end

@ -17,7 +17,7 @@
<tr id="tr_<%= filter.underscore_name %>" class="filter" style="display:none" data-label="tr_<%= label.to_s %>">
<% html_elements(filter).each do |element| %>
<%= render :partial => File.join(partial_prefix, element[:name].to_s),
:locals => {:element => element, :f => f, :filter => filter} %>
:locals => {:element => element, :f => f, :filter => filter, :query => query} %>
<% end %>
</tr>
<% end %>

@ -0,0 +1,21 @@
<%#
This partial requires the following locals:
element a Hash containing the following keys:
- :name => :heavy_values
- :filter_name => String: The name of a filter (e.g. activity_id)
- :hide => Boolean: If you want this to be hidden
query => the current CostQuery
%>
<% filter = query.filters.detect {|f| f.class.underscore_name == element[:filter_name] }
values_available = !!filter && !!filter.values %>
<td <%= 'style="display:none"' if element[:hide] %> >
<div style="" id="<%= element[:filter_name] %>_arg_1" class="filter_values">
<%= filter.values.map{ |v| filter.class.text_for_id v }.join '<br />' if values_available %>
<input type="hidden"
name="values[<%= element[:filter_name] %>][]"
id="<%= element[:filter_name] %>_arg_1_val"
<%= 'disabled="disabled"' unless values_available %>
value="<%= filter.values.to_json if values_available %>"/>
</div>
</td>

@ -38,6 +38,9 @@ function change_argument_visibility(field, arg_nr) {
function operator_changed(field, select) {
var option_tag, arity;
if (select === null) {
return;
}
option_tag = select.options[select.selectedIndex];
arity = parseInt(option_tag.getAttribute("data-arity"), 10);
change_argument_visibility(field, arity);
@ -71,7 +74,7 @@ function set_remove_button_visibility(field, value) {
function load_available_values_for_filter(filter_name, callback_func) {
var select;
select = $('' + filter_name + '_arg_1_val');
if (select.readAttribute('data-loading') === "ajax" && select.childElements().length === 0) {
if (select !== null && select.readAttribute('data-loading') === "ajax" && select.childElements().length === 0) {
new Ajax.Updater({ success: select }, window.global_prefix + '/cost_reports/available_values', {
parameters: { filter_name: filter_name },
insertion: 'bottom',
@ -126,7 +129,8 @@ function occupied_category(tr_field) {
}
function hide_filter(field, slowly) {
var field_el = $('tr_' + field);
var field_el, operator_select;
field_el = $('tr_' + field);
if (field_el !== null) {
$('rm_' + field).value = "";
if (slowly) {
@ -134,7 +138,11 @@ function hide_filter(field, slowly) {
} else {
field_el.hide();
}
operator_changed(field, $("operators_" + field));
operator_select = $("operators_" + field);
if (operator_select !== null) {
// in case the filter doesn't have an operator select field'
operator_changed(field, $("operators_" + field));
}
if (!occupied_category(field_el)) {
hide_category(field_el);
}
@ -195,6 +203,9 @@ function show_group_by(group_by, target) {
function select_operator(field, operator) {
var select, i;
select = $("operators_" + field);
if (select === null) {
return; // there is no such operator select field
}
for (i = 0; i < select.options.length; i += 1) {
if (select.options[i].value === operator) {
select.selectedIndex = i;
@ -239,8 +250,16 @@ function find_arguments(field) {
function restore_values(field, values) {
var op_select, op_arity, args, i;
op_select = $("operators_" + field);
op_arity = op_select.options[op_select.selectedIndex].getAttribute("data-arity");
if (op_select !== null) {
op_arity = op_select.options[op_select.selectedIndex].getAttribute("data-arity");
}
else {
op_arity = 0;
}
args = find_arguments(field);
if (args.size() === 0) {
return; // there are no values to set
}
if (!Object.isArray(values)) {
values = [values];
}

Loading…
Cancel
Save