Skip to content

Commit

Permalink
still not working on server, trying to rearrange things in the event …
Browse files Browse the repository at this point in the history
…that order of initializer is important
  • Loading branch information
blueroot committed May 16, 2011
1 parent b340a0c commit 1e3da95
Showing 1 changed file with 49 additions and 49 deletions.
98 changes: 49 additions & 49 deletions config/initializers/rails_admin.rb
@@ -1,3 +1,52 @@
module RailsAdmin
class History < ActiveRecord::Base
set_table_name :rails_admin_histories

IGNORED_ATTRS = Set[:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]

scope :most_recent, lambda {|table|
where("#{retrieve_connection.quote_column_name(:table)} = ?", table).order("updated_at")
}

def self.get_history_for_dates(mstart, mstop, ystart, ystop)
sql_in = ""
if mstart > mstop
# fix by Dan Choi
#sql_in = (mstart + 1..12).to_a.join(", ") <== possible culprit May month bug
sql_in = (mstart..12).to_a.join(", ")
sql_in_two = (1..mstop).to_a.join(", ")

results = History.find_by_sql("select count(*) as number, year, month from rails_admin_histories where month IN (#{sql_in}) and year = #{ystart} group by year, month")
results_two = History.find_by_sql("select count(*) as number, year, month from rails_admin_histories where month IN (#{sql_in_two}) and year = #{ystop} group by year, month")

results.concat(results_two)
else
#sql_in = (mstart + 1..mstop).to_a.join(", ") <=== may be defective too
sql_in = (mstart..mstop).to_a.join(", ")

results = History.find_by_sql("select count(*) as number, year, month from rails_admin_histories where month IN (#{sql_in}) and year = #{ystart} group by year, month")
end

results.each do |result|
result.number = result.number.to_i
end

add_blank_results(results, mstart, ystart)
end

def self.add_blank_results(results, mstart, ystart)
# fill in an array with BlankHistory
blanks = Array.new(5) { |i| BlankHistory.new(((mstart+i) % 12)+1, ystart + ((mstart+i)/12)) }
# replace BlankHistory array entries with the real History entries that were provided
blanks.each_index do |i|
if results[0] && results[0].year == blanks[i].year && results[0].month == blanks[i].month
blanks[i] = results.delete_at 0
end
end
end
end
end

RailsAdmin.config do |config|
config.navigation.max_visible_tabs 7

Expand Down Expand Up @@ -69,53 +118,4 @@
end
end

end

module RailsAdmin
class History < ActiveRecord::Base
set_table_name :rails_admin_histories

IGNORED_ATTRS = Set[:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]

scope :most_recent, lambda {|table|
where("#{retrieve_connection.quote_column_name(:table)} = ?", table).order("updated_at")
}

def self.get_history_for_dates(mstart, mstop, ystart, ystop)
sql_in = ""
if mstart > mstop
# fix by Dan Choi
#sql_in = (mstart + 1..12).to_a.join(", ") <== possible culprit May month bug
sql_in = (mstart..12).to_a.join(", ")
sql_in_two = (1..mstop).to_a.join(", ")

results = History.find_by_sql("select count(*) as number, year, month from rails_admin_histories where month IN (#{sql_in}) and year = #{ystart} group by year, month")
results_two = History.find_by_sql("select count(*) as number, year, month from rails_admin_histories where month IN (#{sql_in_two}) and year = #{ystop} group by year, month")

results.concat(results_two)
else
#sql_in = (mstart + 1..mstop).to_a.join(", ") <=== may be defective too
sql_in = (mstart..mstop).to_a.join(", ")

results = History.find_by_sql("select count(*) as number, year, month from rails_admin_histories where month IN (#{sql_in}) and year = #{ystart} group by year, month")
end

results.each do |result|
result.number = result.number.to_i
end

add_blank_results(results, mstart, ystart)
end

def self.add_blank_results(results, mstart, ystart)
# fill in an array with BlankHistory
blanks = Array.new(5) { |i| BlankHistory.new(((mstart+i) % 12)+1, ystart + ((mstart+i)/12)) }
# replace BlankHistory array entries with the real History entries that were provided
blanks.each_index do |i|
if results[0] && results[0].year == blanks[i].year && results[0].month == blanks[i].month
blanks[i] = results.delete_at 0
end
end
end
end
end

0 comments on commit 1e3da95

Please sign in to comment.