Module: RepositoriesHelper

Defined in:
app/helpers/repositories_helper.rb

Instance Method Summary collapse

Instance Method Details

#label_for_repository(repository) ⇒ Object



10
11
12
13
# File 'app/helpers/repositories_helper.rb', line 10

def label_for_repository(repository)
  return nil if repository.nil?
  repository_tag(repository) # identical for now
end

#repositories_search_formObject



50
51
52
# File 'app/helpers/repositories_helper.rb', line 50

def repositories_search_form
  render('/repositories/quick_search_form')
end

#repository_autocomplete_tag(repository) ⇒ Object



20
21
22
23
24
25
26
27
# File 'app/helpers/repositories_helper.rb', line 20

def repository_autocomplete_tag(repository)
  [repository.name,
   tag.span(repository.acronym, class: [:feedback, 'feedback-thin', 'feedback-secondary']),
   repository.url.present? ? tag.span(repository.url, class: [:feedback, 'feedback-thin']) : nil,
   (repository.is_index_herbariorum ? tag.span('Herbarium', class: [:feedback, 'feedback-info', 'feedback-thin']) : nil),
   repository_usage_tag(repository)
  ].compact.join(' ').html_safe
end


15
16
17
18
# File 'app/helpers/repositories_helper.rb', line 15

def repository_link(repository)
  return nil if repository.nil?
  link_to(repository_tag(repository).html_safe, repository)
end

#repository_tag(repository) ⇒ Object



3
4
5
6
7
8
# File 'app/helpers/repositories_helper.rb', line 3

def repository_tag(repository)
  return nil if repository.nil?
  [repository.name,
   (repository.acronym ? "(#{repository.acronym})" : nil)
  ].join(' ').html_safe
end

#repository_usage_tag(repository) ⇒ Object

use_count comes from autocomplete pre-calculation



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/repositories_helper.rb', line 30

def repository_usage_tag(repository)
  total_in_project = repository.collection_objects.where(collection_objects: {project_id: sessions_current_project_id}).count 
  total_current_in_project = repository.current_collection_objects.where(collection_objects: {project_id: sessions_current_project_id}).count

  total = (repository.respond_to?(:use_count) ? repository.use_count : repository.collection_objects.count)  
  total_current = repository.current_collection_objects.count

  a = total + total_current 
  b = total_in_project + total_current_in_project

  if a > 0
    uses_tag = tag.span(("Used: " + a.to_s).html_safe, class: [:feedback, 'feedback-thin', 'feedback-primary'])
    in_project_tag = tag.span(("Project: " + b.to_s).html_safe, class: [:feedback, 'feedback-thin', 'feedback-success']) if b > 0
  else
    uses_tag = tag.span('Unused', class: [:feedback, 'feedback-thin', 'feedback-warning'])
  end

  [uses_tag, in_project_tag].compact.join(' ')
end