Last active
May 30, 2016 11:33
-
-
Save ijunaid8989/ec180dd96f46604ba07c46fcc175758c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
params[:id].downcase! | |
camera = get_cam(params[:id]) | |
if params[:from].present? and params[:to].present? and params[:from].to_i > params[:to].to_i | |
raise(BadRequestError, "From can't be higher than to") | |
end | |
from = Time.at(params[:from].to_i).to_s || 0 | |
to = Time.at(params[:to].to_i).to_s | |
to = Time.now.to_s if params[:to].blank? | |
limit = params[:limit] || DEFAULT_LIMIT | |
page = params[:page] || 0 | |
page = 0 if page < 0 | |
limit = DEFAULT_LIMIT if limit < 1 | |
types = params[:types].split(',').map(&:strip) | |
results = CameraActivity.where(camera_id: camera.id).filter(:done_at => (from..to)).reverse_order(:done_at) | |
results = results.where(:action => types) unless types.blank? | |
total_pages = results.count / limit | |
results = results.limit(limit, page * limit).all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment