Sha256: 614288f0c0886250379334d8e70f8f20f52bc9ae62283064f3b660919efea549

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module Sufia
  module DashboardControllerBehavior
    extend ActiveSupport::Concern
    
    included do
      include ActionView::Helpers::DateHelper

      before_filter :authenticate_user!

      layout "sufia-dashboard"
    end

    # Render our dashboard page
    def index
      gather_dashboard_information
      respond_to do |format|
        format.html { }
        format.rss  { render layout: false }
        format.atom { render layout: false }
      end
    end

    # Returns a formated list of recent events in JSON for use with AJAX.
    def activity
      render json: human_readable_user_activity
    end

    protected

    # Gathers all the information that we'll display in the user's dashboard.
    # Override this method if you want to exclude or gather additional data elements
    # in your dashboard view.  You'll need to alter dashboard/index.html.erb accordingly.
    def gather_dashboard_information
      @user = current_user
      @activity = current_user.get_all_user_activity(params[:since].blank? ? DateTime.now.to_i - 8640 : params[:since].to_i)
      @notifications = current_user.mailbox.inbox
    end

    # Formats the user's activities into human-readable strings used for rendering JSON
    def human_readable_user_activity
      current_user.get_all_user_activity.map do |event|
        [event[:action], "#{time_ago_in_words(Time.at(event[:timestamp].to_i))} ago", event[:timestamp].to_i]
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sufia-4.0.0 app/controllers/concerns/sufia/dashboard_controller_behavior.rb
sufia-4.0.0.rc2 app/controllers/concerns/sufia/dashboard_controller_behavior.rb