Merge branch 'feature/dependent' of https://dev.finn.de/git/reporting-engine into feature/dependent

pull/6827/head
Philipp Tessenow 14 years ago
commit a00ac3de9d
  1. 36
      assets/javascripts/reporting/filters.js
  2. 10
      lib/report/controller.rb

@ -131,7 +131,7 @@ Reporting.Filters = {
},
visible_filters: function () {
return $("filter_table").childElements().first().select('tr').select(function (tr) {
return $("filter_table").select("tr").select(function (tr) {
return tr.visible() === true;
}).collect(function (filter) {
return filter.getAttribute("data-filter-name");
@ -148,26 +148,31 @@ Reporting.Filters = {
// Afterwards, collect the visible filters from the dependents list and start
// narrowing down their values.
activate_dependents: function () {
var dependents = this.getAttribute("data-dependents").replace(/'/g, '"'); // [String]
var active_filters = Reporting.Filters.visible_filters(); // [String]
var dependents = this.getAttribute("data-dependents").replace(/'/g, '"').evalJSON();
var active_filters = Reporting.Filters.visible_filters();
if (!active_filters.include(dependents.first())) {
$("add_filter_select").select("option[value='" + dependents.first() + "']").first().selected = true;
Reporting.Filters.add_filter($("add_filter_select"));
Reporting.Filters.show_filter(dependents.first(), { slowly: true });
active_filters.unshift(dependents.first());
}
var source = this.getAttribute("data-filter-name");
setTimeout(function () { // Make sure the newly shown filters are in the DOM
var active_dependents = dependents.select(function (d) {
return active_filters.include(d);
});
var source = this.getAttribute("data-filter-name");
Reporting.Filters.narrow_values([source], active_dependents);
}, 1);
},
// Narrow down the available values for the [dependents] of [sources].
// This will narrow down for each dependent separately, adding each finished
// dependent to the sources array and removing it from the dependents array.
narrow_values: function (sources, dependents) {
if (sources.size() === 0 || dependents.size === 0) {
return;
}
var params = "?narrow_values=1&dependent=" + dependents.first();
sources.inject(params, function (string, filter) {
return string + "&sources[]=" + filter;
sources.each(function (filter) {
params = params + "&sources[]=" + filter;
});
var targetUrl = document.location.href + params;
var updater = new Ajax.Request(targetUrl,
@ -176,15 +181,15 @@ Reporting.Filters = {
evalScripts: true,
postBody: Form.serialize('query_form'),
onSuccess: function (response) {
if (response.isJSON()) {
if (response.responseJSON !== undefined) {
var selectBox = $(dependents.first() + "_arg_1_val");
var selected = selectBox.select("option").collect(function (sel) {
if (sel.selected) {
return sel.value;
}
}).compact();
var newOptions = response.evalJSON().inject("", function (str, o) {
return str + '<option value="' + o.value + '">' + o.label + '</option>';
var newOptions = response.responseJSON.inject("", function (str, o) {
return str + '<option value="' + o + '">' + o.escapeHTML() + '</option>';
});
selectBox.innerHTML = newOptions;
selected.each(function (val) {
@ -193,12 +198,9 @@ Reporting.Filters = {
opt.first().selected = true;
}
});
var newDependents = dependents.reverse();
newDependents.pop();
newDependents = newDependents.reverse();
var newSources = sources;
newSources.push(dependents.first());
Reporting.Filters.narrow_values(newSources, newDependents);
sources.push(dependents.first()); // Add as last element
dependents.splice(0, 1); // Delete first element
Reporting.Filters.narrow_values(sources, dependents);
}
}
}

@ -105,19 +105,19 @@ module Report::Controller
# Determine the available values for the specified filter and return them as
# json, if that was requested. This will be executed INSTEAD of the actual action
def possibly_only_narrow_values
if params[:narrow_values] == 1
if params[:narrow_values] == "1"
sources = params[:sources]
dependent = params[:dependent]
query = CostQuery.new
query = report_engine.new
sources.each do |dependency|
query.filter(dependency,
query.filter(dependency.to_sym,
:operator => params[:operators][dependency],
:values => params[:values][dependency])
end
query.column(dependent)
values = query.result.collect {|r| debugger; r.fields[dependent] }
render :text => values.to_json
values = query.result.collect {|r| r.fields[dependent] }
render :json => values.to_json
end
end

Loading…
Cancel
Save