2753: Workbench shows Collection files in a tree.
[arvados.git] / apps / workbench / app / views / collections / _show_files.html.erb
1 <% content_for :css do %>
2 ul.collection_files {
3   line-height: 2.5em;
4   list-style-type: none;
5   background: #FFF;
6 }
7
8 ul.collection_files li {
9   clear: both;
10 }
11
12 li.collection_files_row_even {
13   background: #FFF;
14 }
15
16 li.collection_files_row_odd {
17   background: #EEE;
18 }
19
20 .collection_files_inline {
21   clear: both;
22   width: 80%;
23   height: auto;
24   max-height: 6em;
25   margin: 0 1em;
26 }
27
28 .collection_files_name {
29   padding-left: .5em;
30   white-space: nowrap;
31   overflow: hidden;
32   text-overflow: ellipsis;
33 }
34
35 .collection_files_name i.fa {
36   display: block-inline;
37   width: 1.75em;
38   text-align: center;
39 }
40
41 .collection_files_buttons {
42   float: right;
43 }
44 <% end %>
45
46 <% content_for :tab_line_buttons do %>
47 <div class="row">
48   <div class="col-md-6"></div>
49   <div class="col-md-6">
50     <div class="pull-right">
51       Collection storage status:
52       <%= render partial: 'toggle_persist', locals: { uuid: @object.uuid, current_state: (@is_persistent ? 'persistent' : 'cache') } %>
53     </div>
54   </div>
55 </div>
56 <% end %>
57
58 <% file_tree = @object.andand.files_tree %>
59 <% if file_tree.nil? or file_tree.empty? %>
60   <p>This collection is empty.</p>
61 <% else %>
62   <ul id="collection_files" class="collection_files">
63   <% dirstack = [file_tree.first.first] %>
64   <% file_tree.each_with_index do |(dirname, filename, size), index| %>
65     <% file_path = CollectionsHelper::file_path([dirname, filename]) %>
66     <% while dirstack.any? and (dirstack.last != dirname) %>
67       <% dirstack.pop %></ul></li>
68     <% end %>
69     <li class="collection_files_row_<%= (index.odd?) ? 'odd' : 'even' %>">
70     <% if size.nil?  # This is a subdirectory. %>
71       <% dirstack.push(File.join(dirname, filename)) %>
72       <div class="collection_files_name"><i class="fa fa-folder-open"></i> <%= filename %></div>
73         <ul class="collection_files">
74     <% else %>
75       <% link_params = {controller: 'collections', action: 'show_file',
76                         uuid: @object.uuid, file: file_path, size: size} %>
77         <div class="collection_files_buttons">
78           <%= raw(human_readable_bytes_html(size)) %>
79           <%= check_box_tag 'uuids[]', "#{@object.uuid}/#{file_path}", false, {
80                 :class => 'persistent-selection',
81                 :friendly_type => "File",
82                 :friendly_name => "#{@object.uuid}/#{file_path}",
83                 :href => url_for(controller: 'collections', action: 'show_file',
84                                  uuid: @object.uuid, file: file_path),
85                 :title => "Include #{file_path} in your selections",
86               } %>
87           <%= link_to(raw('<i class="fa fa-search"></i>'),
88                       link_params.merge(disposition: 'inline'),
89                       {title: "View #{file_path}", class: "btn btn-info btn-sm"}) %>
90           <%= link_to(raw('<i class="fa fa-download"></i>'),
91                       link_params.merge(disposition: 'attachment'),
92                       {title: "Download #{file_path}", class: "btn btn-info btn-sm"}) %>
93         </div>
94       <% if CollectionsHelper::is_image(filename) %>
95         <div class="collection_files_name"><i class="fa fa-bar-chart-o"></i> <%= filename %></div>
96         <div class="collection_files_inline">
97           <%= link_to(image_tag("#{url_for @object}/#{file_path}"),
98                       link_params.merge(disposition: 'inline'),
99                       {title: file_path}) %>
100         </div>
101       <% else %>
102         <div class="collection_files_name"><i class="fa fa-file"></i> <%= filename %></div>
103       <% end %>
104       </li>
105     <% end  # if file or directory %>
106   <% end  # file_tree.each %>
107   </ul>
108 <% end  # if file_tree %>