• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / 00dbc10b-d747-4ad7-b211-7b26d753abbb

14 Aug 2025 01:25PM UTC coverage: 0.483% (-94.9%) from 95.343%
00dbc10b-d747-4ad7-b211-7b26d753abbb

push

circleci

web-flow
Merge pull request #5181 from pulibrary/dependabot/bundler/activestorage-7.2.2.2

Bump activestorage from 7.2.2.1 to 7.2.2.2

47 of 9721 relevant lines covered (0.48%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/controllers/bookmarks_controller.rb
1
# frozen_string_literal: true
2

3
require 'csv'
×
4

5
class BookmarksController < CatalogController
×
6
  include Blacklight::Bookmarks
×
7
  configure_blacklight do |_config|
×
8
    blacklight_config.show.document_actions[:print] =
×
9
      {
×
10
        partial: 'document_action',
×
11
        name: :print,
×
12
        modal: false
×
13
      }
×
14
  end
×
15

16
  def print
×
17
    fetch_bookmarked_documents
×
18
    @url_gen_params = {}
×
19
    render('orangelight/record_mailer/email_record', formats: [:text])
×
20
  end
×
21

22
  def citation
×
23
    bookmarks = token_or_current_or_guest_user.bookmarks
×
24
    bookmark_ids = bookmarks.collect { |bookmark| bookmark.document_id.to_s }
×
25
    @documents = search_service.fetch(bookmark_ids, { rows: bookmark_ids.count, fl: "author_citation_display, title_citation_display, pub_citation_display, number_of_pages_citation_display, pub_date_start_sort, edition_display, format" })
×
26
  end
×
27

28
  def csv
×
29
    fetch_bookmarked_documents
×
30
    send_data csv_output, type: 'text/csv', filename: "bookmarks-#{Time.zone.today}.csv"
×
31
  end
×
32

33
  private
×
34

35
    def fetch_bookmarked_documents
×
36
      bookmark_ids = token_or_current_or_guest_user.bookmarks.collect { |bookmark| bookmark.document_id.to_s }
×
37
      @documents = search_service.fetch(bookmark_ids, rows: bookmark_ids.length, fl: '*')
×
38
    end
×
39

40
    # byte-order-mark declaring our output as UTF-8 (required for non-ASCII to be handled by Excel)
41
    def csv_bom
×
42
      %w[EF BB BF].map { |a| a.hex.chr }.join
×
43
    end
×
44

45
    def csv_fields
×
46
      {
×
47
        id: 'ID',
×
48
        title_citation_display: ['Title', 'Title (Original Script)'],
×
49
        author_display: ['Author', 'Author (Original Script)'],
×
50
        format: 'Format',
×
51
        language_facet: 'Language',
×
52
        pub_citation_display: 'Published/Created',
×
53
        pub_date_display: 'Date',
×
54
        description_display: 'Description',
×
55
        series_display: 'Series',
×
56
        location: 'Library',
×
57
        location_display: 'Location',
×
58
        call_number_display: 'Call Number',
×
59
        notes_display: 'Notes',
×
60
        edition_display: 'Edition'
×
61
      }
×
62
    end
×
63

64
    def csv_output
×
65
      CSV.generate(csv_bom, headers: true) do |csv|
×
66
        csv << csv_fields.values.flatten
×
67
        @documents.each do |doc|
×
68
          csv << csv_fields.keys.map { |field| csv_values(doc, field) }.flatten
×
69
        end
×
70
      end
×
71
    end
×
72

73
    def csv_values(doc, field)
×
74
      if csv_fields[field] == 'ID'
×
75
        "'#{doc[field]}'"
×
76
      elsif csv_fields[field].is_a?(Array)
×
77
        two_values(doc[field])
×
78
      else
×
79
        Array(doc[field]).join('; ')
×
80
      end
×
81
    end
×
82

83
    def two_values(arr)
×
84
      values = arr || ['', '']
×
85
      values << '' if values.length == 1
×
86
      values.map { |v| v.chomp(' /') }
×
87
    end
×
88
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc