Skip to content

Commit

Permalink
Adds internet archive book viewer.
Browse files Browse the repository at this point in the history
NOTE: Had to upgrade bookviewer.js to use newer versions of jQuery/jQuery-UI and a few plugins. Future work will probably have to be done.
  • Loading branch information
Trey Terrell committed Feb 25, 2014
1 parent 2f1b134 commit 665cbb1
Show file tree
Hide file tree
Showing 61 changed files with 8,085 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ braceros-tiffs
# Ignore derived tiffs - in production they probably won't live here, but we still don't want
# to accidentally push any up during dev/test
/media
public/media

This comment has been minimized.

Copy link
@jechols

jechols Feb 25, 2014

Contributor

This should be /public/media if we don't want to accidentally match something like spec/fixtures/public/media

Probably not horribly important, just a thought..


# Ignore deploy configuration files for God and Unicorn
# These sit on our production server and are symlinked in.
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'

gem 'jquery-rails', '~>3.0.4'
gem 'jquery-ui-rails'
gem 'cocoon', '~>1.2.0'

# Nicer form development
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ GEM
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (4.2.0)
railties (>= 3.2.16)
json (1.8.1)
json-ld (1.1.0)
rdf (>= 1.0.8)
Expand Down Expand Up @@ -515,6 +517,7 @@ DEPENDENCIES
jettywrapper
jquery-fileupload-rails (~> 0.4.1)
jquery-rails (~> 3.0.4)
jquery-ui-rails
linkeddata
metadata-ingest-form (~> 2.2)
mini_magick
Expand Down
12 changes: 11 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.ui.slider
//= require jquery.ui.draggable
//= require jquery.ui.effect.all
//
// Required by Blacklight
//= require blacklight/blacklight
Expand All @@ -24,4 +27,11 @@
//= require twitter/typeahead.min
//
// OpenSeaDragon for image viewers.
//= require openseadragon
//= require openseadragon
//
// BookReader
//= require bookreader/dragscrollable
//= require bookreader/jquery.colorbox
//= require bookreader/jquery.ui.ipad
//= require bookreader/jquery.bt.min
//= require bookreader/BookReader
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
jQuery ->
window.BookReaderManager = new BookReaderManager
class BookReaderManager
constructor: ->
return unless $("#BookReader").length > 0
@element = $("#BookReader")
@br = this.initialize_bookreader()
$('#BRtoolbar').find('.read').hide();
$('#textSrch').hide();
$('#btnSrch').hide();
initialize_bookreader: ->
@br = new BookReader()
@br.imagesBaseURL = "/assets/bookreader/images/"
@br.getPageWidth = (index) -> 1000
@br.getPageHeight = (index) -> 1000
@br.getPageURI = this.getPageURI
@br.getPageSide = this.getPageSide
@br.getSpreadIndices = this.getSpreadIndices
@br.getPageNum = (index) -> index+1
@br.numLeafs = @element.data("pages")
@br.bookTitle = @element.data("title")
@br.bookUrl = ''
@br.getEmbedCode = -> return "Embedding is disabled."
@br.init()
return @br
getPageURI: (index, reduce, rotate) =>
"#{@element.data("root")}/page-#{index+1}.png"
getPageSide: (index) ->
if 0 == (index & 0x1)
return'R'
else
return'L'
getSpreadIndices: (pindex) =>
spreadIndices = [null, null];
if 'rl' == @br.pageProgression
if this.getPageSide(pindex) == 'R'
spreadIndices[1] = pindex
spreadIndices[0] = pindex + 1
else
spreadIndices[0] = pindex
spreadIndices[1] = pindex-1
else
if this.getPageSide(pindex) == 'L'
spreadIndices[0] = pindex
spreadIndices[1] = pindex + 1;
else
spreadIndices[1] = pindex
spreadIndices[0] = pindex-1
return spreadIndices
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require jquery.ui.slider
*= require bookreader/bookreader
*= require_tree .
*/

Expand Down
12 changes: 12 additions & 0 deletions app/assets/stylesheets/viewers/document_viewer.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#document-viewer {
position: relative;
width: 800px;
height: 600px;
overflow: hidden;
#BRnav {
position: absolute;
}
#BRcontainer {
margin-top: 41px;
}
}
28 changes: 28 additions & 0 deletions app/decorators/document_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,32 @@ def view_partial
"document_viewer"
end

def view_div(&block)
h.content_tag(:div, :id => "BookReader", :data => data_hash) do
block.call if block_given?
end
end

private

def data_hash
{
:pages => pages,
:title => title,
:root => root
}
end

def pages
datastreams.keys.select{|x| x.start_with?("page")}.length
end

def title
object.descMetadata.title.first
end

def root
"/media/document_pages/#{pages_location.relative_path_from(base_pages_path)}"
end

end
7 changes: 6 additions & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
class Document < GenericAsset
makes_derivatives do |obj|
obj.transform_datastream :content, {:pages => {:output_path => obj.pages_location}}, :processor => :docsplit_processor
obj.save
end

def pages_location
fd = OregonDigital::FileDistributor.new(pid)
fd.base_path = APP_CONFIG["document_pages_path"] || Rails.root.join("media", "document_pages")
fd.base_path = base_pages_path
fd.extension = ""
return Pathname.new(fd.path)
end

def base_pages_path
Pathname.new(APP_CONFIG["document_pages_path"] || Rails.root.join("media", "document_pages"))
end

end
6 changes: 5 additions & 1 deletion app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ class Image < GenericAsset
has_file_datastream :name => 'thumbnail', :control_group => "E"
has_file_datastream :name => 'pyramidal', :control_group => "E"

makes_derivatives :create_thumbnail, :create_pyramidal
makes_derivatives do |obj|
obj.create_thumbnail
obj.create_pyramidal
obj.save
end


# Derivative Creation Methods
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_document_viewer.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<div id="document-viewer">
TODO: Get document viewer back in
<%= decorated_object.view_div %>
</div>
</div>
1 change: 1 addition & 0 deletions lib/hydra/derivatives/docsplit_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def split_images(format, sizes, output_path)
page_path = Pathname.new(file)
new_path = File.join(output_path, "page-#{page}#{page_path.extname}")
File.rename(file, new_path.to_s)
output_datastream("page-#{page}").content = "external"
output_datastream("page-#{page}").dsLocation = "file://#{new_path.to_s}"
end
ensure
Expand Down
2 changes: 1 addition & 1 deletion spec/models/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
it "should create a derivative per page" do
(1..2).each do |page|
expect(document.datastreams.keys).to include("page-#{page}")
expect(document.datastreams["page-#{page}"].content).to be_nil
expect(document.datastreams["page-#{page}"].dsLocation).to eq "file://#{document.pages_location}/page-#{page}.png"
expect(Document.find(document.pid).datastreams.keys).to include("page-#{page}")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
FileUtils.rm(image.thumbnail_location) if File.exists?(image.thumbnail_location)
end
it 'should populate the external thumbnail datastream' do
expect(image.thumbnail.content).to be_nil
expect(image.thumbnail.dsLocation).to eq("file://#{image.thumbnail_location}")
expect(Image.find(image.pid).thumbnail.dsLocation).to eq("file://#{image.thumbnail_location}")
end
it "should save the external thumbnail" do
mime_type = FileMagic.new(FileMagic::MAGIC_MIME).file(image.thumbnail_location).split(';')[0]
Expand All @@ -46,7 +46,7 @@
end
it 'should populate the external pyramidal datastream' do
expect(image.pyramidal.dsLocation).to eq("file://" + image.pyramidal_tiff_location)
expect(image.pyramidal.content).to be_nil
expect(Image.find(image.pid).pyramidal.dsLocation).to eq("file://#{image.pyramidal_tiff_location}")
end
it 'should save the external pyramidal datastream' do
mime_type = FileMagic.new(FileMagic::MAGIC_MIME).file(image.pyramidal_tiff_location).split(';')[0]
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendor/assets/images/bookreader/images/booksplit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendor/assets/images/bookreader/images/slider.png

0 comments on commit 665cbb1

Please sign in to comment.