Class: ProjectShowPresenter
- Inherits:
-
Object
- Object
- ProjectShowPresenter
show all
- Defined in:
- app/presenters/project_show_presenter.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
While we are transitioning to fetching the data straight from Mediaflux ‘project` can be an ActiveRecord Project model (when used from the Project show page) or a Hash with the data from Mediaflux (when used from the Dashboard). This branching can be refactored (elimitated?) once we implement ticket github.com/pulibrary/tigerdata-app/issues/2039 and the project data will always come from Mediaflux.
19
20
21
22
23
24
25
26
27
28
|
# File 'app/presenters/project_show_presenter.rb', line 19
def initialize(project, current_user)
if project.is_a?(Hash)
@project_mf = project
@project = rails_project(@project_mf)
else
@project = project
@project_mf = project.mediaflux_metadata(session_id: current_user.mediaflux_session)
end
@project_metadata = @project&.metadata_model
end
|
Instance Attribute Details
#project ⇒ Object
Returns the value of attribute project.
6
7
8
|
# File 'app/presenters/project_show_presenter.rb', line 6
def project
@project
end
|
Returns the value of attribute project_metadata.
6
7
8
|
# File 'app/presenters/project_show_presenter.rb', line 6
def project_metadata
@project_metadata
end
|
Class Method Details
.xml_presenter_class ⇒ Class
Returns The presenter class for building XML Documents from Projects.
9
10
11
|
# File 'app/presenters/project_show_presenter.rb', line 9
def self.xml_presenter_class
ProjectXmlPresenter
end
|
Instance Method Details
#created ⇒ Object
48
49
50
|
# File 'app/presenters/project_show_presenter.rb', line 48
def created
@project.created_at.strftime("%b %e, %Y %l:%M %p")
end
|
#data_manager ⇒ Object
60
61
62
|
# File 'app/presenters/project_show_presenter.rb', line 60
def data_manager
User.find_by(uid: @project_mf[:data_manager])
end
|
#data_read_only_users ⇒ Object
64
65
66
|
# File 'app/presenters/project_show_presenter.rb', line 64
def data_read_only_users
(@project_mf[:ro_users] || []).map { |uid| ReadOnlyUser.find_by(uid:) }.compact
end
|
#data_read_write_users ⇒ Object
68
69
70
|
# File 'app/presenters/project_show_presenter.rb', line 68
def data_read_write_users
(@project_mf[:rw_users] || []).map { |uid| User.find_by(uid:) }.compact
end
|
56
57
58
|
# File 'app/presenters/project_show_presenter.rb', line 56
def
User.find_by(uid: @project_mf[:data_sponsor])
end
|
#data_user_names ⇒ Object
78
79
80
81
|
# File 'app/presenters/project_show_presenter.rb', line 78
def data_user_names
user_model_names = data_users.map(&:display_name_safe)
user_model_names.join(", ")
end
|
#data_users ⇒ Object
72
73
74
75
76
|
# File 'app/presenters/project_show_presenter.rb', line 72
def data_users
unsorted_data_users = data_read_only_users + data_read_write_users
sorted_data_users = unsorted_data_users.sort_by { |u| u.family_name || u.uid }
sorted_data_users.uniq { |u| u.uid }
end
|
#department_codes ⇒ Object
114
115
116
117
118
119
120
121
122
|
# File 'app/presenters/project_show_presenter.rb', line 114
def department_codes
@dep_with_codes = {}
departments_list = departments.nil? ? [] : departments.first.split(", ")
departments_list.map do |dept|
tmp_code = Affiliation.find_fuzzy_by_name(dept)
@dep_with_codes[dept] = tmp_code.code unless tmp_code.nil?
end
@dep_with_codes
end
|
#departments ⇒ Object
110
111
112
|
# File 'app/presenters/project_show_presenter.rb', line 110
def departments
@project_mf[:departments] || []
end
|
#description ⇒ Object
34
35
36
|
# File 'app/presenters/project_show_presenter.rb', line 34
def description
@project_mf[:description]
end
|
142
143
144
145
|
# File 'app/presenters/project_show_presenter.rb', line 142
def formatted_quota_percentage(session_id:)
value = quota_percentage(session_id:)
format("%.3f", value)
end
|
137
138
139
140
|
# File 'app/presenters/project_show_presenter.rb', line 137
def formatted_storage_capacity(session_id:)
value = storage_capacity(session_id: session_id)
format("%.3f", value)
end
|
#globus ⇒ Object
98
99
100
|
# File 'app/presenters/project_show_presenter.rb', line 98
def globus
@project_mf[:globus] == true ? "Yes" : "No"
end
|
#hpc ⇒ Object
94
95
96
|
# File 'app/presenters/project_show_presenter.rb', line 94
def hpc
@project_mf[:hpc] == true ? "Yes" : "No"
end
|
#number_of_files ⇒ Object
106
107
108
|
# File 'app/presenters/project_show_presenter.rb', line 106
def number_of_files
@project_mf[:number_of_files]
end
|
#project_directory ⇒ Object
used to hide the project root that is not visible to the end user
88
89
90
91
92
|
# File 'app/presenters/project_show_presenter.rb', line 88
def project_directory
directory = @project_mf[:project_directory] || ""
directory.start_with?("/") ? directory : "/" + directory
end
|
#project_id ⇒ Object
124
125
126
|
# File 'app/presenters/project_show_presenter.rb', line 124
def project_id
@project_mf[:project_id]
end
|
#project_in_rails? ⇒ Boolean
168
169
170
|
# File 'app/presenters/project_show_presenter.rb', line 168
def project_in_rails?
project != nil
end
|
#project_purpose ⇒ Object
83
84
85
|
# File 'app/presenters/project_show_presenter.rb', line 83
def project_purpose
ProjectPurpose.label_for(@project_mf[:project_purpose])
end
|
#quota_percentage(session_id:, dashboard: false) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
|
# File 'app/presenters/project_show_presenter.rb', line 151
def quota_percentage(session_id:, dashboard: false)
storage_capacity = project.storage_capacity_raw(session_id:)
return 0 if storage_capacity.zero?
storage_usage = project.storage_usage_raw(session_id:)
return 0 if storage_usage == 0
storage_value = (storage_usage.to_f / storage_capacity.to_f) * 100
minimum_storage_used = true if storage_value > 0 && storage_value < 1
storage_value = 1 if minimum_storage_used
storage_value += 1 if minimum_storage_used && dashboard
storage_value
end
|
#quota_usage(session_id:) ⇒ Object
147
148
149
|
# File 'app/presenters/project_show_presenter.rb', line 147
def quota_usage(session_id:)
"#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
end
|
#smb ⇒ Object
102
103
104
|
# File 'app/presenters/project_show_presenter.rb', line 102
def smb
@project_mf[:smb] == true ? "Yes" : "No"
end
|
#storage_capacity(session_id: nil) ⇒ Object
128
129
130
131
132
133
134
135
|
# File 'app/presenters/project_show_presenter.rb', line 128
def storage_capacity(session_id: nil)
return project_metadata.storage_capacity if session_id.nil?
persisted = project.storage_capacity_raw(session_id: session_id)
value = persisted.to_f
value*default_capacity_divisor
end
|
#title ⇒ Object
30
31
32
|
# File 'app/presenters/project_show_presenter.rb', line 30
def title
@project_mf[:title]
end
|
#to_xml ⇒ String
Returns the XML for the project Document.
39
40
41
|
# File 'app/presenters/project_show_presenter.rb', line 39
def to_xml
xml_document.to_xml
end
|
#updated ⇒ Object
52
53
54
|
# File 'app/presenters/project_show_presenter.rb', line 52
def updated
@project.updated_at.strftime("%b %e, %Y %l:%M %p")
end
|
#user_has_access?(user:) ⇒ Boolean
163
164
165
166
|
# File 'app/presenters/project_show_presenter.rb', line 163
def user_has_access?(user:)
return true if user.eligible_sysadmin?
&.uid == user.uid || data_manager&.uid == user.uid || data_users.map(&:uid).include?(user.uid)
end
|
#xml_document ⇒ Nokogiri::XML::Document
Returns the XML Document for the Project.
44
45
46
|
# File 'app/presenters/project_show_presenter.rb', line 44
def xml_document
@xml_document ||= xml_presenter.document
end
|