diff --git a/plugins/dspace/lib/dspace/item.rb b/plugins/dspace/lib/dspace/item.rb index ffc9470..e95a025 100644 --- a/plugins/dspace/lib/dspace/item.rb +++ b/plugins/dspace/lib/dspace/item.rb @@ -78,6 +78,10 @@ class Dspace::Item < Dspace::Resource end + if item.files.count > 0 + item.mimetype = item.files.first.mimetype + end + item end diff --git a/plugins/dspace/lib/dspace_plugin/item_helper.rb b/plugins/dspace/lib/dspace_plugin/item_helper.rb index aaa0c7b..1fdd6cd 100644 --- a/plugins/dspace/lib/dspace_plugin/item_helper.rb +++ b/plugins/dspace/lib/dspace_plugin/item_helper.rb @@ -1,8 +1,90 @@ module DspacePlugin::ItemHelper + TEXT_MIMETYPES = [ 'text/plain; charset=utf-8', + 'text/html', + 'text/xml', + 'text/plain', + 'text/html', + 'text/css', + 'text/richtext' ] + + AUDIO_MIMETYPES = [ 'audio/x-pn-realaudio', + 'audio/x-mpeg', + 'audio/x-aiff', + 'audio/basic', + 'audio/x-wav' ] + + DOCUMENT_MIMETYPES = [ 'application/msword', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'application/vnd.oasis.opendocument.text', + 'application/vnd.oasis.opendocument.text-template', + 'application/vnd.oasis.opendocument.text-web', + 'application/vnd.oasis.opendocument.text-master', + 'application/vnd.sun.xml.writer', + 'application/vnd.sun.xml.writer.template', + 'application/vnd.sun.xml.writer.global', + 'application/vnd.stardivision.writer', + 'application/vnd.stardivision.writer-global' ] + + PICTURE_MIMETYPES = [ 'image/x-photo-cd', + 'image/x-ms-bmp', + 'image/jpeg', + 'image/gif', + 'image/png', + 'image/tiff', + 'application/x-photoshop', + 'application/postscript' ] + + SPREADSHEET_MIMETYPES = [ 'application/vnd.ms-excel', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'application/vnd.oasis.opendocument.spreadsheet', + 'application/vnd.oasis.opendocument.spreadsheet-template', + 'application/vnd.sun.xml.calc', + 'application/vnd.sun.xml.calc.template', + 'application/vnd.sun.xml.math', + 'application/vnd.stardivision.calc' ] + + VIDEO_MIMETYPES = [ 'video/quicktime', + 'video/mpeg' ] + + def remove_slash_at_end_url(url) url.gsub!(/\/$/,'') if url =~ /\/$/ url end + def class_for_item_mimetype(mimetype) + + case + + when mimetype == 'application/pdf' + mimetype_class = 'pdf' + + when TEXT_MIMETYPES.include?(mimetype) + mimetype_class = 'text' + + when AUDIO_MIMETYPES.include?(mimetype) + mimetype_class = 'audio' + + when DOCUMENT_MIMETYPES.include?(mimetype) + mimetype_class = 'document' + + when PICTURE_MIMETYPES.include?(mimetype) + mimetype_class = 'picture' + + when SPREADSHEET_MIMETYPES.include?(mimetype) + mimetype_class = 'spreadsheet' + + when VIDEO_MIMETYPES.include?(mimetype) + mimetype_class = 'video' + + else + mimetype_class = 'other' + + end + + "icon-#{mimetype_class}" + + end + end diff --git a/plugins/dspace/views/content_viewer/_item.html.erb b/plugins/dspace/views/content_viewer/_item.html.erb index 5cff69c..dbdc7a6 100644 --- a/plugins/dspace/views/content_viewer/_item.html.erb +++ b/plugins/dspace/views/content_viewer/_item.html.erb @@ -1,16 +1,9 @@