Module: SourcesHelper
- Defined in:
- app/helpers/sources_helper.rb
Instance Method Summary collapse
- #add_source_to_project_form(source) ⇒ Object
- #project_source_for_source(source) ⇒ Object
- #short_sources_tag(sources) ⇒ Object
- #source_attributes_for(source) ⇒ Object
- #source_author_year_tag(source) ⇒ Object
- #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
88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/sources_helper.rb', line 88 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 |
#project_source_for_source(source) ⇒ Object
100 101 102 |
# File 'app/helpers/sources_helper.rb', line 100 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) ⇒ Object
46 47 48 49 |
# File 'app/helpers/sources_helper.rb', line 46 def short_sources_tag(sources) return nil if !sources.load.any? sources.collect{|s| (s) }.join('; ') end |
#source_attributes_for(source) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/sources_helper.rb', line 58 def source_attributes_for(source) w = content_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_tag(source) ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/helpers/sources_helper.rb', line 29 def (source) if source && source.type == 'Source::Bibtex' && source..present? source. else content_tag(:span, 'Author, year not yet provided for source.', class: [:feedback, 'feedback-thin', 'feedback-warning']) end end |
#source_document_viewer_option_tag(source) ⇒ Object
51 52 53 54 55 56 |
# File 'app/helpers/sources_helper.rb', line 51 def source_document_viewer_option_tag(source) return nil if !source.documents.load.any? content_tag(:span, class: 'pdfviewerItem') do source.documents.collect{|d| content_tag(:a, 'View', class: 'circle-button', data: { pdfviewer: d.document_file(:original, false), sourceid: source.id})}.join.html_safe end.html_safe end |
#source_in_other_project?(source) ⇒ Boolean
108 109 110 |
# File 'app/helpers/sources_helper.rb', line 108 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
112 113 114 115 116 |
# File 'app/helpers/sources_helper.rb', line 112 def source_in_other_project_tag(object) if source_in_other_project?(object) content_tag(:h3, 'This source is used in another project.', class: :warning) end end |
#source_in_project?(source) ⇒ Boolean
104 105 106 |
# File 'app/helpers/sources_helper.rb', line 104 def source_in_project?(source) ProjectSource.exists?(project_id: sessions_current_project_id, source_id: source.to_param) end |
#source_link(source) ⇒ Object
41 42 43 44 |
# File 'app/helpers/sources_helper.rb', line 41 def source_link(source) return nil if source.nil? link_to(source_tag(source).html_safe, source. ) end |
#source_nomenclature_tag(source, topics) ⇒ Object
118 119 120 121 122 123 |
# File 'app/helpers/sources_helper.rb', line 118 def source_nomenclature_tag(source, topics) t = [content_tag(:span, source_tag(source))] t.push [':', topic_list_tag(topics).html_safe] if !topics.blank? t.push (source) t.flatten.compact.join(' ').html_safe end |
#source_related_attributes(source) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/sources_helper.rb', line 74 def (source) content_for :related_attributes do if source.class.name == 'Source::Bibtex' content_tag(:h3, 'Authors') do content_tag(:ul) do source..collect{|a| content_tag(:li, a.last_name)} end end else end end end |
#source_tag(source) ⇒ Object
3 4 5 6 |
# File 'app/helpers/sources_helper.rb', line 3 def source_tag(source) return nil if source.nil? 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
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/sources_helper.rb', line 8 def sources_autocomplete_tag(source, term) return nil if source.nil? if term s = source.cached.gsub(/#{Regexp.escape(term)}/i, "<mark>#{term}</mark>") + ' ' # weee bit simpler else s = source.cached + ' ' end if source.is_in_project?(sessions_current_project_id) s += ' ' + content_tag(:span, 'in', class: [:feedback, 'feedback-primary', 'feedback-thin']) c = source.citations.where(project_id: sessions_current_project_id).count s += ' ' + ( c > 0 ? content_tag(:span, "#{c.to_s} #{'citations'.pluralize(c)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin']) : '' ) s += ' ' + content_tag(:span, 'doc/pdf', class: [:feedback, 'feedback-success', 'feedback-thin']) if source.documentation.where(project_id: sessions_current_project_id).any? else s += ' ' + content_tag(:span, 'out', class: [:feedback, 'feedback-warning', 'feedback-thin']) end s.html_safe end |
#sources_search_form ⇒ Object
37 38 39 |
# File 'app/helpers/sources_helper.rb', line 37 def sources_search_form render('/sources/quick_search_form') end |