orbit-basic/app/controllers/desktop_orbit_controller.rb

52 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2012-06-26 07:59:28 +00:00
class DesktopOrbitController< ApplicationController
def orbit
render "desktop/orbit", :layout => false
end
2012-07-06 08:11:03 +00:00
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"))
2012-07-02 13:06:20 +00:00
end
2012-07-06 08:11:03 +00:00
render :json=>{"startyear"=>startyear,"endyear"=>endyear}.to_json
2012-07-02 13:06:20 +00:00
end
def eventajaxload
@limit = 15
2012-07-02 13:06:20 +00:00
@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")))
2012-07-02 13:06:20 +00:00
@data = Array.new
while @totalpapers < @limit
if Date.new(@date.year,@date.month-1) > Date.new(@fromdate[0],@fromdate[1])
2012-07-02 13:06:20 +00:00
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-08-21 11:36:49 +00:00
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