getting rudimentary query saving and loading to work

pull/6827/head
jwollert 14 years ago
parent aa8bcd64af
commit 674c91e01a
  1. 11
      app/models/cost_query.rb
  2. 15
      app/views/cost_reports/_saved_queries.rhtml
  3. 2
      app/views/cost_reports/index.rhtml

@ -129,12 +129,23 @@ class CostQuery < ActiveRecord::Base
hash[filter.class.underscore_name.to_sym] = filter.values
hash
end
params[:fields] = sel_filters.collect { |f| f.class.underscore_name }
rows = group_bys.select &:row?
columns = group_bys - rows
params[:groups] = { :rows => rows.map { |gb| gb.class.field }, :columns => columns.map { |gb| gb.class.field } }
params
end
def hash
filter_string = filters.inject("") do |str, f|
str + f.class.underscore_name + f.operator.to_s + (f.values ? f.values.to_json : "")
end
filter_string = group_bys.collect(&:class).sort_by(&:underscore_name).inject(filter_string) do |string, gb|
string.concat(gb.underscore_name)
end
Digest::MD5.hexdigest(filter_string)
end
private
def minimal_chain!

@ -0,0 +1,15 @@
<%#
This partial requires the following locals:
queries A Collection of CostQuery Objects
%>
<% queries.each do |query| %>
<%= link_to_remote "<span><em>#{query.name}</em></span>",
{ :url => ({ :set_filter => 1, :action => 'index' }.merge CostQuery.load(query.yamlized).to_params),
:condition => 'Ajax.activeRequestCount === 0',
:update => "content",
:eval_scripts => true
}, :class => 'button send_query' %>
<% end %>

@ -13,6 +13,7 @@
<h2><%= l(:label_cost_report) %></h2>
<% html_title( l(:label_cost_report) ) %>
<%= render :partial => 'saved_queries', :locals => { :queries => CostQuery.all } %>
<% form_for @query, :url => {:controller => 'cost_report', :action => 'new' }, :html => {:id => 'query_form', :method => :post} do |query_form| %>
<div id="query_form_content">
@ -42,6 +43,7 @@
{ :url => { :save_query => 1 },
:before => 'selectAllOptions("group_by_rows");selectAllOptions("group_by_columns");',
:with => "Form.serialize('query_form')",
:update => 'content',
:eval_scripts => true
}, :class => 'icon icon-save' %>
<% end %>

Loading…
Cancel
Save