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:, display_modal: "") ⇒ DashboardPresenter

Returns a new instance of DashboardPresenter.



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

def initialize(current_user:, display_modal: "")
  @current_user = current_user
  @display_modal = display_modal
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

#display_modalObject (readonly)

Returns the value of attribute display_modal.



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

def display_modal
  @display_modal
end

Instance Method Details

#all_projectsObject



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

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, current_user) }
                           .select(&:project_in_rails?)
                           .sort_by(&:updated_at)
                           .reverse
  @all_projects
end

#dashboard_projectsObject



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

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

#display_confirm_delete_draft_modal?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/presenters/dashboard_presenter.rb', line 44

def display_confirm_delete_draft_modal?
  display_modal == "confirm_delete_draft"
end

#my_draft_requestsObject



36
37
38
# File 'app/presenters/dashboard_presenter.rb', line 36

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

#my_inventory_requestsObject



32
33
34
# File 'app/presenters/dashboard_presenter.rb', line 32

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

#my_submitted_requestsObject



40
41
42
# File 'app/presenters/dashboard_presenter.rb', line 40

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