Sha256: 085fe6eab7526dcede7442f5edcae03453c25ed288d68a998f9987dbe5113b2c

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

module Hyrax
  module Dashboard
    # Presenter for dashboard of a non-admin user
    class UserPresenter
      def initialize(current_user, view_context, since)
        @current_user = current_user
        @view_context = view_context
        @since = since
      end

      def activity
        @activity ||= current_user.all_user_activity(activity_seconds_ago)
      end

      def notifications
        @notifications ||= current_user.mailbox.inbox
      end

      def transfers
        @transfers ||= Hyrax::TransfersPresenter.new(current_user, view_context)
      end

      def render_recent_activity
        if activity.empty?
          t('hyrax.dashboard.no_activity')
        else
          render 'hyrax/users/activity_log', events: activity
        end
      end

      def render_recent_notifications
        if notifications.empty?
          t('hyrax.dashboard.no_notifications')
        else
          render "hyrax/notifications/notifications", messages: notifications_for_dashboard
        end
      end

      def link_to_additional_notifications
        return unless notifications.count > Hyrax.config.max_notifications_for_dashboard
        link_to t('hyrax.dashboard.additional_notifications'), hyrax.notifications_path
      end

      private

        attr_reader :current_user, :view_context, :since
        delegate :render, :t, :hyrax, :link_to, to: :view_context

        # @return [Integer] how long ago to query (in seconds)
        def activity_seconds_ago
          return since.to_i if since.present?
          DateTime.current.to_i - Hyrax.config.activity_to_show_default_seconds_since_now
        end

        def notifications_for_dashboard
          notifications.limit(Hyrax.config.max_notifications_for_dashboard)
        end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hyrax-2.0.3 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.1.0.beta2 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.2 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.1.0.beta1 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.1 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0.rc3 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0.rc2 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0.rc1 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0.beta5 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0.beta4 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0.beta3 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0.beta2 app/presenters/hyrax/dashboard/user_presenter.rb
hyrax-2.0.0.beta1 app/presenters/hyrax/dashboard/user_presenter.rb