Commit 43d83b5fd59c2e9bb87599da9250b16d54c395d5
1 parent
bd2045ba
Exists in
staging
and in
7 other branches
dspace_plugin : improve function to show icon by item mimetype
Showing
3 changed files
with
88 additions
and
9 deletions
Show diff stats
plugins/dspace/lib/dspace/item.rb
plugins/dspace/lib/dspace_plugin/item_helper.rb
1 | 1 | module DspacePlugin::ItemHelper |
2 | 2 | |
3 | + TEXT_MIMETYPES = [ 'text/plain; charset=utf-8', | |
4 | + 'text/html', | |
5 | + 'text/xml', | |
6 | + 'text/plain', | |
7 | + 'text/html', | |
8 | + 'text/css', | |
9 | + 'text/richtext' ] | |
10 | + | |
11 | + AUDIO_MIMETYPES = [ 'audio/x-pn-realaudio', | |
12 | + 'audio/x-mpeg', | |
13 | + 'audio/x-aiff', | |
14 | + 'audio/basic', | |
15 | + 'audio/x-wav' ] | |
16 | + | |
17 | + DOCUMENT_MIMETYPES = [ 'application/msword', | |
18 | + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | |
19 | + 'application/vnd.oasis.opendocument.text', | |
20 | + 'application/vnd.oasis.opendocument.text-template', | |
21 | + 'application/vnd.oasis.opendocument.text-web', | |
22 | + 'application/vnd.oasis.opendocument.text-master', | |
23 | + 'application/vnd.sun.xml.writer', | |
24 | + 'application/vnd.sun.xml.writer.template', | |
25 | + 'application/vnd.sun.xml.writer.global', | |
26 | + 'application/vnd.stardivision.writer', | |
27 | + 'application/vnd.stardivision.writer-global' ] | |
28 | + | |
29 | + PICTURE_MIMETYPES = [ 'image/x-photo-cd', | |
30 | + 'image/x-ms-bmp', | |
31 | + 'image/jpeg', | |
32 | + 'image/gif', | |
33 | + 'image/png', | |
34 | + 'image/tiff', | |
35 | + 'application/x-photoshop', | |
36 | + 'application/postscript' ] | |
37 | + | |
38 | + SPREADSHEET_MIMETYPES = [ 'application/vnd.ms-excel', | |
39 | + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | |
40 | + 'application/vnd.oasis.opendocument.spreadsheet', | |
41 | + 'application/vnd.oasis.opendocument.spreadsheet-template', | |
42 | + 'application/vnd.sun.xml.calc', | |
43 | + 'application/vnd.sun.xml.calc.template', | |
44 | + 'application/vnd.sun.xml.math', | |
45 | + 'application/vnd.stardivision.calc' ] | |
46 | + | |
47 | + VIDEO_MIMETYPES = [ 'video/quicktime', | |
48 | + 'video/mpeg' ] | |
49 | + | |
50 | + | |
3 | 51 | def remove_slash_at_end_url(url) |
4 | 52 | url.gsub!(/\/$/,'') if url =~ /\/$/ |
5 | 53 | url |
6 | 54 | end |
7 | 55 | |
56 | + def class_for_item_mimetype(mimetype) | |
57 | + | |
58 | + case | |
59 | + | |
60 | + when mimetype == 'application/pdf' | |
61 | + mimetype_class = 'pdf' | |
62 | + | |
63 | + when TEXT_MIMETYPES.include?(mimetype) | |
64 | + mimetype_class = 'text' | |
65 | + | |
66 | + when AUDIO_MIMETYPES.include?(mimetype) | |
67 | + mimetype_class = 'audio' | |
68 | + | |
69 | + when DOCUMENT_MIMETYPES.include?(mimetype) | |
70 | + mimetype_class = 'document' | |
71 | + | |
72 | + when PICTURE_MIMETYPES.include?(mimetype) | |
73 | + mimetype_class = 'picture' | |
74 | + | |
75 | + when SPREADSHEET_MIMETYPES.include?(mimetype) | |
76 | + mimetype_class = 'spreadsheet' | |
77 | + | |
78 | + when VIDEO_MIMETYPES.include?(mimetype) | |
79 | + mimetype_class = 'video' | |
80 | + | |
81 | + else | |
82 | + mimetype_class = 'other' | |
83 | + | |
84 | + end | |
85 | + | |
86 | + "icon-#{mimetype_class}" | |
87 | + | |
88 | + end | |
89 | + | |
8 | 90 | end | ... | ... |
plugins/dspace/views/content_viewer/_item.html.erb
1 | 1 | <li class="item"> |
2 | - <div> | |
3 | - | |
4 | - <% if item.files.first.mimetype == 'application/pdf' %> | |
5 | - <img src="/plugins/dspace/icons/pdf.png" style="display: inline-block;"/> | |
6 | - <% else %> | |
7 | - <img src="/plugins/dspace/icons/text.png" style="display: inline-block;"/> | |
8 | - <% end %> | |
9 | - | |
2 | + <div style="vertical-align: top;"> | |
3 | + <div class="icon-item <%= item.class_for_item_mimetype(item.mimetype) %>"></div> | |
10 | 4 | <div style="display: inline-block; width: 92%;"> |
11 | 5 | <span class="name"><%= link_to item.name, :controller => 'dspace_plugin', :action => 'view_item', :id => item.id, :collection_id => @page.id %></span><br /> |
12 | 6 | <span class="authors"><%= item.author %></span> <span class="date_issued">(<%= item.issue_date %>)</span> |
13 | 7 | </div> |
14 | - | |
15 | 8 | </div> |
16 | 9 | </li> | ... | ... |