Module: SourcesHelper
- Defined in:
- app/helpers/sources_helper.rb
Instance Method Summary collapse
- #add_source_to_project_form(source) ⇒ Object
- #history_link(source) ⇒ Object
-
#label_for_source(source) ⇒ Object
This is an exception to the no HTML currently in that it returns curator supplied tags (they are the only allowed.
- #project_source_for_source(source) ⇒ Object
-
#short_sources_tag(sources) ⇒ String
No HTML.
-
#short_sources_year_tag(sources) ⇒ String
No HTML.
- #source_attributes_for(source) ⇒ Object
-
#source_author_year_label(source) ⇒ String
No HTML, no nil.
- #source_author_year_tag(source) ⇒ Object
-
#source_citation_totals(sources) ⇒ Object
Hash a vectorized count of totals per source.
- #source_document_viewer_option_tag(source) ⇒ Object
- #source_in_other_project?(source) ⇒ Boolean
- #source_in_other_project_tag(object) ⇒ Object
- #source_in_project?(source) ⇒ Boolean
- #source_link(source) ⇒ Object
- #source_nomenclature_tag(source, topics) ⇒ Object
- #source_related_attributes(source) ⇒ Object
- #source_tag(source) ⇒ Object
- #sources_autocomplete_tag(source, term) ⇒ Object
- #sources_search_form ⇒ Object
Instance Method Details
#add_source_to_project_form(source) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/helpers/sources_helper.rb', line 130 def add_source_to_project_form(source) if !source_in_project?(source) form_for(ProjectSource.new(source_id: source.to_param, project_id: sessions_current_project_id), remote: true) do |f| f.hidden_field(:source_id) + f.hidden_field(:project_id) + f.submit('Add to project', data: { 'source-to-project': source.id.to_s }, class: 'button-submit') end else ('Remove from project', project_source_path(project_source_for_source(source)), method: :delete, remote: true, data: { 'source-to-project': source.id.to_s }, class: 'button-delete') end end |
#history_link(source) ⇒ Object
76 77 78 79 |
# File 'app/helpers/sources_helper.rb', line 76 def history_link(source) tag.em(' in ') + link_to(tag.span((source), title: source.cached, class: :history__in), send(:nomenclature_by_source_task_path, source_id: source.id) ) # return content_tag(:span, content_tag(:em, ' in ') + b, class: [:history__in]) end |
#label_for_source(source) ⇒ Object
This is an exception to the no HTML currently in that it returns curator supplied tags (they are the only allowed
11 12 13 14 |
# File 'app/helpers/sources_helper.rb', line 11 def label_for_source(source) return nil if source.nil? source.cached end |
#project_source_for_source(source) ⇒ Object
142 143 144 |
# File 'app/helpers/sources_helper.rb', line 142 def project_source_for_source(source) ProjectSource.find_by(source_id: source.to_param, project_id: sessions_current_project_id) end |
#short_sources_tag(sources) ⇒ String
Returns no HTML.
82 83 84 85 |
# File 'app/helpers/sources_helper.rb', line 82 def short_sources_tag(sources) return nil if !sources.load.any? sources.collect{|s| (s) }.join('; ') end |
#short_sources_year_tag(sources) ⇒ String
Returns no HTML.
88 89 90 91 |
# File 'app/helpers/sources_helper.rb', line 88 def short_sources_year_tag(sources) return nil if !sources.load.any? sources.collect{|s| s.year }.compact.sort.join('; ') end |
#source_attributes_for(source) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/sources_helper.rb', line 100 def source_attributes_for(source) w = tag.em('ERROR, unkown class of Source, contact developers', class: :warning) content_for :attributes do case source.class.name when 'Source::Bibtex' render '/sources/bibtex/attributes' when 'Source::Verbatim' render '/sources/verbatim/attributes' when 'Source::Source' w else w end end end |
#source_author_year_label(source) ⇒ String
Returns No HTML, no nil.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/sources_helper.rb', line 43 def (source) not_provided = 'Author, year not yet provided for source.' case source&.type when 'Source::Human' source.cached when 'Source::Bibtex' (source..presence || not_provided) else not_provided end end |
#source_author_year_tag(source) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/sources_helper.rb', line 55 def (source) not_provided = 'Author, year not yet provided for source.' case source&.type when 'Source::Human' source.cached when 'Source::Bibtex' (source..presence || not_provided) else tag.span(not_provided, class: [:feedback, 'feedback-thin', 'feedback-warning']) end end |
#source_citation_totals(sources) ⇒ Object
Returns Hash a vectorized count of totals per source.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'app/helpers/sources_helper.rb', line 187 def source_citation_totals(sources) data = {} max_total = 0 Citation..each do |k| row = [] sources.each do |s| row.push Citation.where(project_id: sessions_current_project_id, source: s, citation_object_type: k).count end if row.sum > 0 data[k] = row max_total = row.sum if max_total < row.sum end end ids_missing_data = [] sources.each_with_index do |s, i| has_data = false data.each do |k, v| if data[k][i] > 0 has_data = true break end end ids_missing_data.push(s.id) unless has_data end return { data: data, metadata: { ids_missing_data: ids_missing_data, max_total: max_total } } end |
#source_document_viewer_option_tag(source) ⇒ Object
93 94 95 96 97 98 |
# File 'app/helpers/sources_helper.rb', line 93 def source_document_viewer_option_tag(source) return nil if !source.documents.load.any? tag.span(class: 'pdfviewerItem flexbox gap-small') do source.documents.collect{|d| tag.a('View', class: 'circle-button', data: { pdfviewer: d.document_file(:original, false), sourceid: source.id}) if d.document_file_content_type == 'application/pdf'}.join.html_safe end.html_safe end |
#source_in_other_project?(source) ⇒ Boolean
150 151 152 |
# File 'app/helpers/sources_helper.rb', line 150 def source_in_other_project?(source) source.project_sources.where.not(project_id: sessions_current_project_id).references(:projects_sources).any? end |
#source_in_other_project_tag(object) ⇒ Object
154 155 156 157 158 |
# File 'app/helpers/sources_helper.rb', line 154 def source_in_other_project_tag(object) if source_in_other_project?(object) tag.h3('This source is used in another project.', class: :warning) end end |
#source_in_project?(source) ⇒ Boolean
146 147 148 |
# File 'app/helpers/sources_helper.rb', line 146 def source_in_project?(source) ProjectSource.exists?(project_id: sessions_current_project_id, source_id: source.to_param) end |
#source_link(source) ⇒ Object
71 72 73 74 |
# File 'app/helpers/sources_helper.rb', line 71 def source_link(source) return nil if source.nil? link_to(source_tag(source).html_safe, source. ) end |
#source_nomenclature_tag(source, topics) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/helpers/sources_helper.rb', line 160 def source_nomenclature_tag(source, topics) t = [tag.span(source_tag(source))] t.push [':', topic_list_tag(topics).html_safe] if topics.present? content_tag(:div, t.flatten.compact.join(' ').html_safe + content_tag(:div, content_tag(:div, radial_annotator(source) + (source), class: 'flex-row gap-small' ), class: 'd-inline-block margin-small-left') ) end |
#source_related_attributes(source) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/helpers/sources_helper.rb', line 116 def (source) content_for :related_attributes do if source.class.name == 'Source::Bibtex' tag.h3( 'Authors') do tag.ul do source..collect{|a| tag.li(a.last_name)} end end else end end end |
#source_tag(source) ⇒ Object
3 4 5 6 7 |
# File 'app/helpers/sources_helper.rb', line 3 def source_tag(source) return nil if source.nil? # TODO: sanitize should happen at the model validation level, not here! source.cached ? sanitize(source.cached, tags: ['i']).html_safe : (source.new_record? ? nil : 'ERROR - Source cache not set, please notify admin.') end |
#sources_autocomplete_tag(source, term) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/sources_helper.rb', line 16 def sources_autocomplete_tag(source, term) return nil if source.nil? s = mark_tag(source.cached, term, html_safe: false) + ' ' # In project is the project_if if present in this project see lib/queries/source/autocomplete if source.respond_to?(:in_project) && !source.in_project.nil? s += ' ' + tag.span('in', class: [:feedback, 'feedback-primary', 'feedback-thin']) c = source.use_count s += ' ' + ( c > 0 ? tag.span("#{c} #{'citations'.pluralize(c)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin']) : '' ) s += ' ' + tag.span('doc/pdf', class: [:feedback, 'feedback-success', 'feedback-thin']) if source.documentation.where(project_id: sessions_current_project_id).any? elsif source.is_in_project?(sessions_current_project_id) s += ' ' + tag.span('in', class: [:feedback, 'feedback-primary', 'feedback-thin']) c = source.citations.where(project_id: sessions_current_project_id).count s += ' ' + ( c > 0 ? tag.span("#{c} #{'citations'.pluralize(c)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin']) : '' ) s += ' ' + tag.span('doc/pdf', class: [:feedback, 'feedback-success', 'feedback-thin']) if source.documentation.where(project_id: sessions_current_project_id).any? else s += ' ' + tag.span('out', class: [:feedback, 'feedback-warning', 'feedback-thin']) end s += ' ' + tag.span(label_for_language(source.source_language), class: [:feedback, 'feedback-secondary', 'feedback-thin']) if source.language_id.present? s.html_safe end |
#sources_search_form ⇒ Object
67 68 69 |
# File 'app/helpers/sources_helper.rb', line 67 def sources_search_form render('/sources/quick_search_form') end |