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

pull/6827/head
jwollert 14 years ago
commit 0f7e6c82d4
  1. 11
      lib/widget.rb
  2. 6
      lib/widget/base.rb
  3. 2
      lib/widget/filters.rb
  4. 6
      lib/widget/filters/multi_values.rb
  5. 12
      lib/widget/filters/operators.rb
  6. 33
      lib/widget/settings.rb
  7. 15
      lib/widget/settings/fieldset.rb
  8. 20
      lib/widget/table.rb
  9. 2
      lib/widget/table/detailed_table.rb
  10. 5
      lib/widget/table/report_table.rb

@ -1,10 +1,11 @@
class ActionView::Base class ActionView::Base
def render_widget(widget, subject, options = nil) def render_widget(widget, subject, options = {}, &block)
i = widget.new(subject) i = widget.new(subject)
i.config = config i.config = config
i.controller = controller i.controller = controller
i._content_for = @_content_for i._content_for = @_content_for
(options ? i.render_with_options(options) : i.render).html_safe i._routes = _routes
i.render_with_options(options, &block).html_safe
end end
end end
@ -14,7 +15,7 @@ class Widget < ActionView::Base
include ActionView::Helpers::FormTagHelper include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::JavaScriptHelper include ActionView::Helpers::JavaScriptHelper
attr_accessor :output_buffer, :controller, :config, :_content_for attr_accessor :output_buffer, :controller, :config, :_content_for, :_routes
extend ProactiveAutoloader extend ProactiveAutoloader
@ -25,4 +26,8 @@ class Widget < ActionView::Base
def current_language def current_language
::I18n.locale ::I18n.locale
end end
def protect_against_forgery?
false
end
end end

@ -10,11 +10,11 @@ class Widget::Base < Widget
raise NotImplementedError, "#render is missing in my subclass" raise NotImplementedError, "#render is missing in my subclass"
end end
def render_with_options(options = {}) def render_with_options(options = {}, &block)
if canvas = options[:to] if canvas = options[:to]
canvas << "\n" << render canvas << "\n" << render(&block)
else else
raise ArgumentError, "invalid options" render(&block)
end end
end end
end end

@ -35,7 +35,7 @@ class Widget::Filters < Widget::Base
def render_filters def render_filters
active_filters = @query.filters.select {|f| f.class.display? } active_filters = @query.filters.select {|f| f.class.display? }
engine::Filter.all.collect do |filter| engine::Filter.all.collect do |filter|
opts = :id => "tr_#{filter.underscore_name}", :class => "#{filter.underscore_name}" opts = {:id => "tr_#{filter.underscore_name}", :class => "#{filter.underscore_name}"}
active_instance = active_filters.detect {|f| f.class == filter } active_instance = active_filters.detect {|f| f.class == filter }
if active_instance if active_instance
opts[:"data-selected"] = true opts[:"data-selected"] = true

@ -16,9 +16,9 @@ class Widget::Filters::MultiValues < Widget::Filters::Base
name = l(name) if name.is_a? Symbol name = l(name) if name.is_a? Symbol
name_prefix = ((level && level > 0) ? (' ' * 2 * level + '> ') : '') name_prefix = ((level && level > 0) ? (' ' * 2 * level + '> ') : '')
unless options[:optgroup] unless options[:optgroup]
content_tag :option, :value => id do opts = { :value => id }
name_prefix + h(name) opts[:selected] = "selected" if filter.values.include? id
end content_tag(:option, opts) { name_prefix + h(name) }
else else
tag :optgroup, :label => l(:label_sector) tag :optgroup, :label => l(:label_sector)
end end

@ -7,15 +7,9 @@ class Widget::Filters::Operators < Widget::Filters::Base
:onchange => "operator_changed('#{filter_class.underscore_name}', this);", :onchange => "operator_changed('#{filter_class.underscore_name}', this);",
:name => "operators[#{filter_class.underscore_name}]" do :name => "operators[#{filter_class.underscore_name}]" do
filter_class.available_operators.collect do |o| filter_class.available_operators.collect do |o|
if filter.operator.to_s == o.to_s opts = {:value => h(o.to_s), :"data-arity" => o.arity}
content_tag :option, :value => h(o.to_s), :"data-arity" => o.arity, :selected => "selected" do opts[:selected] = "selected" if filter.operator.to_s == o.to_s
h(l(o.label)) content_tag(:option, opts) { h(l(o.label)) }
end
else
content_tag :option, :value => h(o.to_s), :"data-arity" => o.arity do
h(l(o.label))
end
end
end.join.html_safe end.join.html_safe
end end
end end

@ -1,2 +1,35 @@
class Widget::Settings < Widget::Base class Widget::Settings < Widget::Base
def render
form_for @query, :url => "#", :html => {:id => 'query_form', :method => :post} do |query_form|
content_tag :div, :id => "query_form_content" do
fieldsets = render_widget Widget::Settings::Fieldset, :type => "filter" do
render_widget Widget::Filters, @query
end
fieldsets += render_widget Widget::Settings::Fieldset, :type => "group_by" do
render_widget Widget::GroupBys, @query
end
buttons = content_tag :p, :class => "buttons form_controls" do
p = link_to({}, {:href => "#",
:onclick => "
selectAllOptions('group_by_rows');
selectAllOptions('group_by_columns');
new Ajax.Updater('result-table',
'#{url_for(:action => 'index', :set_filter => '1')}',
{ asynchronous:true,
evalScripts:true,
postBody: Form.serialize('query_form') + '\\n' + $('filters').innerHTML });
return false;".html_safe,
:class => 'button apply'}) do
content_tag(:span, content_tag(:em, l(:button_apply)))
end
p += link_to_function l(:button_reset), "restore_query_inputs();", :class => 'icon icon-reload'
end
fieldsets + buttons
end
end
end
end end

@ -0,0 +1,15 @@
class Widget::Settings::Fieldset < Widget::Base
def render_with_options(options, &block)
@type = options.delete(:type) || "filter"
@id = "#{@type}-settings"
@label = :"label_#{@type}"
super(options, &block)
end
def render
content_tag :fieldset, :id => @id, :class => "collapsible collapsed" do
html = content_tag :legend, l(@label), :onclick => "toggleFieldset(this);" #FIXME: onclick
html + yield
end
end
end

@ -1,2 +1,22 @@
class Widget::Table < Widget::Base class Widget::Table < Widget::Base
def render
if @query.group_bys.empty?
widget = Widget::Table::DetailedTable
else
if @query.depth_of(:column) == 0
@query.column(:singleton_value)
elsif @query.depth_of(:row) == 0
@query.row(:singleton_value)
end
widget = Widget::Table::ReportTable
end
content_tag :div, :id => "result-table" do
if @query.result.count > 0
render_widget widget, @query
else
content_tag :p, l(:label_no_data), :class => "nodata"
end
end
end
end end

@ -0,0 +1,2 @@
class Widget::Table::DetailedTable < Widget::Base
end

@ -0,0 +1,5 @@
class Widget::Table::ReportTable < Widget::Base
def render
"blah"
end
end
Loading…
Cancel
Save