Module: ConceptsHelper

Defined in:
app/helpers/concepts_helper.rb

Overview

Copyright 2011-2013 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Instance Method Summary collapse

Instance Method Details

#concept_header(concept, &block) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/concepts_helper.rb', line 85

def concept_header(concept, &block)
  desc = concept.class.model_name.human

  if concept.expired_at
    desc += " #{t('txt.views.concepts.expired_at', date: l(concept.expired_at, format: :long))} "
  end

  title = concept.pref_label || concept.origin

  page_header(title: title.to_s, desc: desc.html_safe, &block)
end

#concept_view_data(concept) ⇒ Object

Renders associated objects of a given concept to a hash structure. This hash is taken by view/layouts/_sections to be rendered.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/concepts_helper.rb', line 51

def concept_view_data(concept)
  res = {}

  render_concept_association(res, concept, Collection::Member::Base)

  Iqvoc::Concept.labeling_classes.each do |labeling_class, languages|
    render_concept_association(res, concept, labeling_class, available_languages: languages || Iqvoc.available_languages)
  end

  Iqvoc::Concept.relation_classes.each do |relation_class|
    render_concept_association(res, concept, relation_class)
  end

  render_match_association(res, concept, Iqvoc::Concept.match_classes)

  Iqvoc::Concept.note_classes.each do |note_class|
    render_concept_association(res, concept, note_class)
  end

  Iqvoc::Concept.notation_classes.each do |notation_class|
    render_concept_association(res, concept, notation_class)
  end

  Iqvoc::Concept.additional_association_classes.keys.each do |assoc_class|
    render_concept_association(res, concept, assoc_class)
  end

  res
end

#delete_button_text(concept) ⇒ Object



81
82
83
# File 'app/helpers/concepts_helper.rb', line 81

def delete_button_text(concept)
  concept.never_published? ? t("txt.views.versioning.delete") : t("txt.views.versioning.delete_copy")
end

#letter_selector(letters = ('A'..'Z').to_a, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/concepts_helper.rb', line 38

def letter_selector(letters = ('A'..'Z').to_a, &block)
  fallback = (@letters&.include?('A')) ? 'a' : @letters&.first
  highlighted_letter = params[:prefix] || fallback || 'a'
   :ul, class: 'letter-selector list-unstyled' do
    letters.map do |letter|
       :li, link_to(letter, yield(letter)),
        class: ('active' if highlighted_letter.to_s.downcase == letter.to_s.downcase)
    end.join('').html_safe
  end
end

#nested_list(hash, options = {}) ⇒ Object

turns a hash of concept/relations pairs of arbitrary nesting depth into the corresponding HTML list



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/concepts_helper.rb', line 25

def nested_list(hash, options={})
  ordered = options[:ordered] || false
  options.delete(:ordered)

  (ordered ? 'ol' : 'ul', options) do
    hash.map do |concept, rels|
      rels.empty? ? ('li', concept) : ('li') do
        h(concept) + nested_list(rels, ordered: ordered) # NB: recursive
      end
    end.join("\n").html_safe
  end
end

#treeview(concepts, broader = false, dragabble = false) ⇒ Object

if ‘broader` is supplied, the tree’s direction is reversed (descendants represent broader relations)



19
20
21
# File 'app/helpers/concepts_helper.rb', line 19

def treeview(concepts, broader = false, dragabble = false)
  render "concepts/hierarchical/treeview", concepts: concepts, broader: broader, dragabble: dragabble
end