Class: DashboardPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/dashboard_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user:) ⇒ DashboardPresenter

Returns a new instance of DashboardPresenter.



4
5
6
# File 'app/presenters/dashboard_presenter.rb', line 4

def initialize(current_user:)
  @current_user = current_user
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



3
4
5
# File 'app/presenters/dashboard_presenter.rb', line 3

def current_user
  @current_user
end

Instance Method Details

#all_projectsObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/presenters/dashboard_presenter.rb', line 8

def all_projects
  # Short-cut to prevent an extra call to Mediaflux for non-admins
  # which are the large majority of our users.
  return [] unless current_user&.eligible_sysadmin?

  @all_projects ||= Project.all_projects(current_user)
                           .map { |project| ProjectDashboardPresenter.new(project) }
                           .select(&:project_in_rails?)
                           .sort_by(&:updated_at)
                           .reverse
  @all_projects
end

#dashboard_projectsObject



21
22
23
24
25
26
27
28
# File 'app/presenters/dashboard_presenter.rb', line 21

def dashboard_projects
  @dashboard_projects ||= Project.users_projects(current_user)
                                 .map { |project| ProjectDashboardPresenter.new(project) }
                                 .select(&:project_in_rails?)
                                 .sort_by(&:updated_at)
                                 .reverse
  @dashboard_projects
end

#my_draft_requestsObject



34
35
36
# File 'app/presenters/dashboard_presenter.rb', line 34

def my_draft_requests
  @my_draft_requests ||= Request.where(requested_by: current_user.uid, state: Request::DRAFT)
end

#my_inventory_requestsObject



30
31
32
# File 'app/presenters/dashboard_presenter.rb', line 30

def my_inventory_requests
  @my_inventory_requests ||= current_user.user_requests.where(type: "FileInventoryRequest")
end

#my_submitted_requestsObject



38
39
40
# File 'app/presenters/dashboard_presenter.rb', line 38

def 
  @my_submitted_requests ||= Request.where(requested_by: current_user.uid, state: Request::SUBMITTED)
end