Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

rails_admin patch for may bug

View rails_admin.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.