Class: WorkPresenter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work:, current_user:) ⇒ WorkPresenter

Returns a new instance of WorkPresenter.



10
11
12
13
14
# File 'app/presenters/work_presenter.rb', line 10

def initialize(work:, current_user:)
  @work = work
  @current_user = current_user
  @can_curate = current_user&.can_admin?(group)
end

Instance Attribute Details

#can_curateObject (readonly)

Returns the value of attribute can_curate.



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

def can_curate
  @can_curate
end

#current_userObject (readonly)

Returns the value of attribute current_user.



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

def current_user
  @current_user
end

#workObject (readonly)

Returns the value of attribute work.



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

def work
  @work
end

Instance Method Details

#changesObject



16
17
18
# File 'app/presenters/work_presenter.rb', line 16

def changes
  WorkActivity.changes_for_work(work.id).order(created_at: :asc)
end

#current_user_is_admin?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/presenters/work_presenter.rb', line 35

def current_user_is_admin?
  current_user.has_role?(:group_admin, group)
end

#descriptionObject



24
25
26
27
28
# File 'app/presenters/work_presenter.rb', line 24

def description
  value = resource.description
  return if value.nil?
  Rinku.auto_link(value, :all, 'target="_blank"')
end

#download_pathObject



69
70
71
72
73
# File 'app/presenters/work_presenter.rb', line 69

def download_path
  return if @work.nil? || !@work.persisted?

  work_download_path(@work.id)
end

#edit_pathObject



55
56
57
58
59
60
61
# File 'app/presenters/work_presenter.rb', line 55

def edit_path
  if draft? && !migrated # wizard mode
    edit_work_wizard_path(work)
  else
    edit_work_path(work)
  end
end

#file_list_pathObject



63
64
65
66
67
# File 'app/presenters/work_presenter.rb', line 63

def file_list_path
  return work_file_list_path("NONE") if @work.nil? || !@work.persisted?

  work_file_list_path(@work.id)
end

#messagesObject



20
21
22
# File 'app/presenters/work_presenter.rb', line 20

def messages
  WorkActivity.messages_for_work(work.id).order(created_at: :desc)
end


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

def related_objects_link_list
  ro = resource.related_objects
  ro.map { |a| format_related_object_links(a) }
end

#show_approve_button?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/presenters/work_presenter.rb', line 39

def show_approve_button?
  work.awaiting_approval? && current_user_is_admin?
end

#show_complete_button?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/presenters/work_presenter.rb', line 47

def show_complete_button?
  draft? && (work.created_by_user_id == current_user.id || current_user_is_admin?)
end

#show_migrate_button?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/presenters/work_presenter.rb', line 51

def show_migrate_button?
  draft? && migrated && current_user_is_admin?
end

#show_revert_button?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/presenters/work_presenter.rb', line 43

def show_revert_button?
  work.awaiting_approval? && (work.created_by_user_id == current_user.id || current_user_is_admin?)
end