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
- #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_link(project) ⇒ Object
- #project_matches(object) ⇒ Object
- #project_tag(project) ⇒ Object
- #projects_list(projects) ⇒ Object
- #projects_search_form ⇒ Object
- #taxonworks_classification(project_cutoff: 1000) ⇒ Object
- #week_in_review_graphs(weeks) ⇒ Object
Instance Method Details
#cumulative_gb_per_year(sums) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/helpers/projects_helper.rb', line 120 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 |
#document_cumulative_gb_per_year ⇒ Object
133 134 135 |
# File 'app/helpers/projects_helper.rb', line 133 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
99 100 101 |
# File 'app/helpers/projects_helper.rb', line 99 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
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/helpers/projects_helper.rb', line 107 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
137 138 139 |
# File 'app/helpers/projects_helper.rb', line 137 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
103 104 105 |
# File 'app/helpers/projects_helper.rb', line 103 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
39 40 41 |
# File 'app/helpers/projects_helper.rb', line 39 def invalid_object(object) !(!object.try(:project_id) || project_matches(object)) end |
#project_classification(project) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/projects_helper.rb', line 74 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_link(project) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/helpers/projects_helper.rb', line 25 def project_link(project) return nil if project.nil? l = link_to(project.name, select_project_path(project)) project.id == sessions_current_project_id ? content_tag(:mark, l) : l end |
#project_matches(object) ⇒ Object
43 44 45 |
# File 'app/helpers/projects_helper.rb', line 43 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
33 34 35 |
# File 'app/helpers/projects_helper.rb', line 33 def projects_list(projects) projects.collect { |p| content_tag(:li, project_link(p)) }.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 |
#taxonworks_classification(project_cutoff: 1000) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/projects_helper.rb', line 47 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
141 142 143 |
# File 'app/helpers/projects_helper.rb', line 141 def week_in_review_graphs(weeks) content_tag(:div, '', 'data-weeks-ago': weeks, 'data-weeks-review': true) end |