Orbit/app/controllers/desktop_orbit_controller.rb

49 lines
1.4 KiB
Ruby
Raw Normal View History

2012-06-26 07:59:28 +00:00
class DesktopOrbitController< ApplicationController
def orbit
render "desktop/orbit", :layout => false
end
2012-06-26 13:09:33 +00:00
def getevents
@event = params["event"]
@data = Array.new
2012-07-02 13:06:20 +00:00
@fromdate = params["from"]
2012-06-26 13:09:33 +00:00
case @event
when "papers"
2012-07-02 13:06:20 +00:00
@data = current_user.papers.where(:created_at.gt => Date.new(Integer(@fromdate[0]),Integer(@fromdate[1])-1),:created_at.lt => Date.new(Integer(@fromdate[0]),Integer(@fromdate[1])+1)).desc(:created_at)
end
render :json=>@data.to_json
end
def eventajaxload
@fromdate = params["from"]
@fromdate[0] = Integer(@fromdate[0])
@fromdate[1] = Integer(@fromdate[1])
@totalpapers = 0
@lastpaper = current_user.papers.all.desc(:created_at).last
@data = Array.new
while @totalpapers < 15
if @lastpaper.created_at > Date.new(@fromdate[0],@fromdate[1])
break
end
if(@fromdate[1] == 12)
@papers = current_user.papers.where(:created_at.gt => Date.new(@fromdate[0],@fromdate[1]),:created_at.lt => Date.new(@fromdate[0]+1,1)).desc(:created_at)
else
@papers = current_user.papers.where(:created_at.gt => Date.new(@fromdate[0],@fromdate[1]),:created_at.lt => Date.new(@fromdate[0],@fromdate[1]+1)).desc(:created_at)
end
if(@papers.length > 0)
@data << {"papers" => @papers}
end
@totalpapers = @totalpapers + @papers.length
@fromdate[1] = @fromdate[1]-1
if(@fromdate[1] == 0)
@fromdate[1] = 12
@fromdate[0] = @fromdate[0] - 1
2012-06-26 13:09:33 +00:00
end
2012-07-02 13:06:20 +00:00
2012-06-26 13:09:33 +00:00
end
render :json=>@data.to_json
end
2012-06-26 07:59:28 +00:00
end