Module: ProjectsHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/projects_helper.rb
Overview
A controller include, need to split out session methods versus those that aren’t
Constant Summary collapse
- CLASSIFIER =
{ nomenclature: [TaxonName, TaxonNameRelationship, TaxonNameClassification, TypeMaterial ], digitization: [CollectionObject, CollectingEvent, Loan, LoanItem, TaxonDetermination ], descriptive: [Otu, ControlledVocabularyTerm, Content, Observation, ObservationMatrix, Descriptor, Image, BiologicalAssociation, CharacterState, ObservationMatrixRow, ObservationMatrixColumn], literature: [ProjectSource, Citation, CitationTopic, Documentation, Document ], geospatial: [Georeference, AssertedDistribution], }
- CLASSIFIER_ANNOTATION =
[Identifier, Note, Tag, AlternateValue, Attribution, Confidence, Depiction ]
Instance Method Summary collapse
- #cumulative_gb_per_year(sums) ⇒ Object
-
#cumulative_projects_created_per_year ⇒ Object
Cumulative Projects Created per Year From chatGPT 5.0 default.
- #document_cumulative_gb_per_year ⇒ Object
- #document_gb_per_year ⇒ Object
- #gb_per_year(sums) ⇒ Object
- #image_cumulative_gb_per_year ⇒ Object
- #image_gb_per_year ⇒ Object
-
#invalid_object(object) ⇒ Object
Came from application_controller.
- #project_classification(project) ⇒ Object
- #project_initials(project) ⇒ Object
- #project_link(project) ⇒ Object
- #project_login_link(project) ⇒ Object
- #project_matches(object) ⇒ Object
- #project_tag(project) ⇒ Object
- #projects_list(projects) ⇒ Object
- #projects_search_form ⇒ Object
- #sound_cumulative_gb_per_year ⇒ Object
- #sound_gb_per_year ⇒ Object
- #taxonworks_classification(project_cutoff: 1000) ⇒ Object
- #week_in_review_graphs(weeks) ⇒ Object
Instance Method Details
#cumulative_gb_per_year(sums) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/helpers/projects_helper.rb', line 145 def cumulative_gb_per_year(sums) d = gb_per_year(sums) data = {} t = 0 d.each do |k,v| t = t + v data[k] = t end data end |
#cumulative_projects_created_per_year ⇒ Object
Cumulative Projects Created per Year From chatGPT 5.0 default
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'app/helpers/projects_helper.rb', line 172 def cumulative_projects_created_per_year years = Project.reorder(nil).pluck(:created_at).compact.map { |t| t.in_time_zone(Time.zone).year } return [['Year', 'Projects']] if years.empty? per_year = years.tally # TIL! min_year = years.min max_year = Time.zone.today.year cumulative = 0 rows = (min_year..max_year).map do |y| cumulative += (per_year[y] || 0) [y, cumulative] end [['Year', 'Projects']] + rows end |
#document_cumulative_gb_per_year ⇒ Object
158 159 160 |
# File 'app/helpers/projects_helper.rb', line 158 def document_cumulative_gb_per_year cumulative_gb_per_year(Document.group_by_year(:created_at, format: '%Y').sum(:document_file_file_size)) end |
#document_gb_per_year ⇒ Object
118 119 120 |
# File 'app/helpers/projects_helper.rb', line 118 def document_gb_per_year gb_per_year( Document.group_by_year(:created_at, format: '%Y').sum(:document_file_file_size)) end |
#gb_per_year(sums) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/helpers/projects_helper.rb', line 132 def gb_per_year(sums) min = sums.keys.sort.first || 0 max = sums.keys.sort.last || 0 data = {} (min..max).each do |y| data[y] = sums[y].present? ? (sums[y].to_f / 1073741824.0).to_i : 0 end data end |
#image_cumulative_gb_per_year ⇒ Object
162 163 164 |
# File 'app/helpers/projects_helper.rb', line 162 def image_cumulative_gb_per_year cumulative_gb_per_year(Image.group_by_year(:created_at, format: '%Y').sum(:image_file_file_size)) end |
#image_gb_per_year ⇒ Object
122 123 124 |
# File 'app/helpers/projects_helper.rb', line 122 def image_gb_per_year gb_per_year( Image.group_by_year(:created_at, format: '%Y').sum(:image_file_file_size) ) end |
#invalid_object(object) ⇒ Object
Came from application_controller
58 59 60 |
# File 'app/helpers/projects_helper.rb', line 58 def invalid_object(object) !(!object.try(:project_id) || project_matches(object)) end |
#project_classification(project) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/helpers/projects_helper.rb', line 93 def project_classification(project) classification = Hash.new(0) CLASSIFIER.keys.each do |k| CLASSIFIER[k].each do |m| classification[k] += m.where(project_id: project.id).count end end # Add annotations to their respective class CLASSIFIER_ANNOTATION.each do |m| field = m.column_names.select{|n| n =~ /_type/}.first CLASSIFIER.keys.each do |k| CLASSIFIER[k].each do |s| classification[k] += m.where(project_id: project.id, field => s.name ).count end end end return { data: classification, total: classification.values.sum } end |
#project_initials(project) ⇒ Object
194 195 196 197 198 199 200 201 202 |
# File 'app/helpers/projects_helper.rb', line 194 def project_initials(project) return '' if project.nil? || project.name.blank? project.name .split(/\s+/) .map { |p| p[0].upcase } .first(3) .join end |
#project_link(project) ⇒ Object
25 26 27 28 |
# File 'app/helpers/projects_helper.rb', line 25 def project_link(project) return nil if project.nil? link_to(project.name, select_project_path(project)) end |
#project_login_link(project) ⇒ Object
51 52 53 54 |
# File 'app/helpers/projects_helper.rb', line 51 def project_login_link(project) return nil unless (!is_project_member_by_id?(sessions_current_user_id, sessions_current_project_id) && (sessions_current_project_id != project.id)) link_to('Login to ' + project.name, select_project_path(project), class: ['button-default']) end |
#project_matches(object) ⇒ Object
62 63 64 |
# File 'app/helpers/projects_helper.rb', line 62 def project_matches(object) object.try(:project_id) == sessions_current_project_id end |
#project_tag(project) ⇒ Object
16 17 18 19 |
# File 'app/helpers/projects_helper.rb', line 16 def project_tag(project) return nil if project.nil? project.name end |
#projects_list(projects) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/projects_helper.rb', line 30 def projects_list(projects) active_id = sessions_current_project_id sorted = projects.sort_by do |p| [ p.id == active_id ? 0 : 1, p.name.downcase ] end sorted.collect do |p| classes = ['project-item'] classes << 'active' if p.id == active_id content_tag(:li, project_link(p), class: classes) end.join.html_safe end |
#projects_search_form ⇒ Object
21 22 23 |
# File 'app/helpers/projects_helper.rb', line 21 def projects_search_form render('/projects/quick_search_form') end |
#sound_cumulative_gb_per_year ⇒ Object
166 167 168 |
# File 'app/helpers/projects_helper.rb', line 166 def sound_cumulative_gb_per_year cumulative_gb_per_year(Sound.group_by_year('sounds.created_at', format: '%Y').joins(sound_file_attachment: :blob).sum('active_storage_blobs.byte_size')) end |
#sound_gb_per_year ⇒ Object
126 127 128 129 130 |
# File 'app/helpers/projects_helper.rb', line 126 def sound_gb_per_year gb_per_year( Sound.joins(sound_file_attachment: :blob).group_by_year('sounds.created_at', format: '%Y').sum('active_storage_blobs.byte_size') ) end |
#taxonworks_classification(project_cutoff: 1000) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/projects_helper.rb', line 66 def taxonworks_classification(project_cutoff: 1000) result = {} data = Hash.new(0) CLASSIFIER.keys.each do |k| CLASSIFIER[k].each do |m| data[k] += m.count end end result[:taxonworks] = { data:, total: data.values.sum } result[:projects] = {} Project.all.each do |p| d = project_classification(p) next if d[:total] < project_cutoff result[:projects].merge!({ p.name => d }) end result end |
#week_in_review_graphs(weeks) ⇒ Object
189 190 191 |
# File 'app/helpers/projects_helper.rb', line 189 def week_in_review_graphs(weeks) content_tag(:div, '', 'data-weeks-ago': weeks, 'data-weeks-review': true) end |