This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/desktop_orbit_controller.rb

51 lines
1.6 KiB
Ruby

class DesktopOrbitController< ApplicationController
def orbit
render "desktop/orbit", :layout => false
end
def getevents
@event = params["event"]
@data = Array.new
@fromdate = params["from"]
case @event
when "papers"
@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
@limit = 15
@fromdate = params["from"]
@fromdate[0] = Integer(@fromdate[0])
@fromdate[1] = Integer(@fromdate[1])
@totalpapers = 0
@lastpaper = current_user.papers.all.desc(:created_at).last
@date = Date.new(Integer(@lastpaper.created_at.strftime("%Y")),Integer(@lastpaper.created_at.strftime("%m")))
@data = Array.new
while @totalpapers < @limit
if Date.new(@date.year,@date.month-1) > 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
end
end
render :json=>@data.to_json
end
end