Orbit/app/controllers/desktop_orbit_controller.rb

52 lines
1.6 KiB
Ruby

class DesktopOrbitController< ApplicationController
def orbit
render "desktop/orbit", :layout => false
end
def gettimelinespan
@get = params['get']
case @get
when "papers"
firstpaper = current_user.papers.all.first
lastpaper = current_user.papers.all.desc(:created_at).last
endyear = Integer(lastpaper.created_at.strftime("%Y"))
startyear = Integer(firstpaper.created_at.strftime("%Y"))
end
render :json=>{"startyear"=>startyear,"endyear"=>endyear}.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