Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 45f38056cf
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 47 lines (42 sloc) 1.366 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
class LogsController < ApplicationController
  def index
    @logs = Log.scoped.includes(:user)
    
    if params[:at_time]
      # Format: "2012-10-20-10-00"
      at = DateTime.strptime(params[:at],"%Y-%m-%d-%H-%M").to_time
      @logs = @logs.where("at >= ?", at).where("at <= ?", at + 1.minute)
    end
    
    if params[:from] && params[:to]
      # Format: 0-n
      # In Seconds
      # 1st minute == timestamp = 60
      @logs = @logs.where("timestamp >= ? AND timestamp <= ?", params[:from], params[:to])
    end
    
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @logs.to_json(:methods => [:uid, :name]) }
    end
  end
  
  def new
    @log = Log.new
  end
  
  def create
    if logged_in?
      @log = Log.new(params[:log])
      @log.user_id = current_user.id
      if params[:time].present?
        @log.at = params[:time]
      else
        @log.at = Time.now
      end
      if @log.save
        logger.info "awesome, #{current_user.email} tagged a video at #{@log.at}"
        Pusher['comments'].trigger('comment', { :body => @log.body, :user_id => @log.user_id, :short_time => @log.at.strftime("%H:%M"), :name => @log.user.name })
      end
      render json: @log, status: :created, location: @log
    else
      flash[:notice] = 'not logged in!'
      redirect_to new_log_path
    end
  end
end
Something went wrong with that request. Please try again.