Class: WorkPresenter
- Inherits:
-
Object
- Object
- WorkPresenter
- Defined in:
- app/presenters/work_presenter.rb
Instance Attribute Summary collapse
-
#can_curate ⇒ Object
readonly
Returns the value of attribute can_curate.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#work ⇒ Object
readonly
Returns the value of attribute work.
Instance Method Summary collapse
- #changes ⇒ Object
- #current_user_is_admin? ⇒ Boolean
- #description ⇒ Object
- #download_path ⇒ Object
- #edit_path ⇒ Object
- #file_list_path ⇒ Object
-
#initialize(work:, current_user:) ⇒ WorkPresenter
constructor
A new instance of WorkPresenter.
- #messages ⇒ Object
- #related_objects_link_list ⇒ Object
- #show_approve_button? ⇒ Boolean
- #show_complete_button? ⇒ Boolean
- #show_migrate_button? ⇒ Boolean
- #show_revert_button? ⇒ Boolean
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_curate ⇒ Object (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_user ⇒ Object (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 |
#work ⇒ Object (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
#changes ⇒ Object
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
35 36 37 |
# File 'app/presenters/work_presenter.rb', line 35 def current_user_is_admin? current_user.has_role?(:group_admin, group) end |
#description ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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 |
#messages ⇒ Object
20 21 22 |
# File 'app/presenters/work_presenter.rb', line 20 def WorkActivity.(work.id).order(created_at: :desc) end |
#related_objects_link_list ⇒ Object
30 31 32 33 |
# File 'app/presenters/work_presenter.rb', line 30 def ro = resource. ro.map { |a| (a) } end |
#show_approve_button? ⇒ Boolean
39 40 41 |
# File 'app/presenters/work_presenter.rb', line 39 def work.awaiting_approval? && current_user_is_admin? end |
#show_complete_button? ⇒ Boolean
47 48 49 |
# File 'app/presenters/work_presenter.rb', line 47 def draft? && (work.created_by_user_id == current_user.id || current_user_is_admin?) end |
#show_migrate_button? ⇒ Boolean
51 52 53 |
# File 'app/presenters/work_presenter.rb', line 51 def draft? && migrated && current_user_is_admin? end |
#show_revert_button? ⇒ Boolean
43 44 45 |
# File 'app/presenters/work_presenter.rb', line 43 def work.awaiting_approval? && (work.created_by_user_id == current_user.id || current_user_is_admin?) end |