Merge branch 'master' into 9352-many-nodes-make-workbench-faster
[arvados.git] / apps / workbench / app / views / collections / _show_files.html.erb
1 <%
2   preview_selectable_container = ''
3   preview_selectable = ''
4   padding_left = '1em'
5   if !params['use_preview_selection'].nil? and params['use_preview_selection'] == 'true'
6     preview_selectable_container = 'preview-selectable-container selectable-container'
7     preview_selectable = 'preview-selectable selectable'
8     padding_left = '0em'
9   end
10 %>
11
12 <% object = @object unless object %>
13
14 <div class="selection-action-container" style="padding-left: <%=padding_left%>">
15   <% if Collection.creatable? and (!defined? no_checkboxes or !no_checkboxes) %>
16     <div class="row">
17       <div class="pull-left">
18         <div class="btn-group btn-group-sm">
19           <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Selection... <span class="caret"></span></button>
20           <ul class="dropdown-menu" role="menu">
21             <li><%= link_to "Create new collection with selected files", '#',
22                     method: :post,
23                     'data-href' => combine_selected_path(
24                       action_data: {current_project_uuid: object.owner_uuid}.to_json
25                     ),
26                     'data-selection-param-name' => 'selection[]',
27                     'data-selection-action' => 'combine-collections',
28                     'data-toggle' => 'dropdown'
29               %></li>
30           </ul>
31         </div>
32         <div class="btn-group btn-group-sm">
33           <button id="select-all" type="button" class="btn btn-default" onClick="select_all_items()">Select all</button>
34           <button id="unselect-all" type="button" class="btn btn-default" onClick="unselect_all_items()">Unselect all</button>
35         </div>
36       </div>
37       <div class="pull-right">
38         <input class="form-control filterable-control" data-filterable-target="ul#collection_files" id="file_regex" name="file_regex" placeholder="filename regex" type="text"/>
39       </div>
40     </div>
41     <p/>
42   <% end %>
43
44   <% file_tree = object.andand.files_tree %>
45   <% if file_tree.nil? or file_tree.empty? %>
46     <p>This collection is empty.</p>
47   <% else %>
48     <ul id="collection_files" class="collection_files arv-selectable-items <%=preview_selectable_container%>">
49     <% dirstack = [file_tree.first.first] %>
50     <% file_tree.take(10000).each_with_index do |(dirname, filename, size), index| %>
51       <% file_path = CollectionsHelper::file_path([dirname, filename]) %>
52       <% while dirstack.any? and (dirstack.last != dirname) %>
53         <% dirstack.pop %></ul></li>
54       <% end %>
55       <li>
56       <% if size.nil?  # This is a subdirectory. %>
57         <% dirstack.push(File.join(dirname, filename)) %>
58         <div class="collection_files_row">
59          <div class="collection_files_name"><i class="fa fa-fw fa-folder-open"></i> <%= filename %></div>
60         </div>
61         <ul class="collection_files">
62       <% else %>
63         <% link_params = {controller: 'collections', action: 'show_file',
64                           uuid: object.portable_data_hash, file: file_path, size: size} %>
65          <div class="collection_files_row filterable <%=preview_selectable%>" href="<%=object.uuid%>/<%=file_path%>">
66           <div class="collection_files_buttons pull-right">
67             <%= raw(human_readable_bytes_html(size)) %>
68             <%= link_to(raw('<i class="fa fa-search"></i>'),
69                         link_params.merge(disposition: 'inline'),
70                         {title: "View #{file_path}", class: "btn btn-info btn-sm", disabled: !preview_allowed_for(file_path)}) %>
71             <%= link_to(raw('<i class="fa fa-download"></i>'),
72                         link_params.merge(disposition: 'attachment'),
73                         {title: "Download #{file_path}", class: "btn btn-info btn-sm"}) %>
74           </div>
75
76           <div class="collection_files_name">
77             <% if (!defined? no_checkboxes or !no_checkboxes) and current_user %>
78             <%= check_box_tag 'uuids[]', "#{object.uuid}/#{file_path}", false, {
79                   :class => "persistent-selection",
80                   :friendly_type => "File",
81                   :friendly_name => "#{object.uuid}/#{file_path}",
82                   :href => url_for(controller: 'collections', action: 'show_file',
83                                    uuid: object.portable_data_hash, file: file_path),
84                   :title => "Include #{file_path} in your selections",
85                   :id => "#{object.uuid}_file_#{index}",
86                 } %>
87             <span>&nbsp;</span>
88             <% end %>
89         <% if CollectionsHelper::is_image(filename) %>
90             <i class="fa fa-fw fa-bar-chart-o"></i> <%= filename %></div>
91           <div class="collection_files_inline">
92             <%= link_to(image_tag("#{url_for object}/#{file_path}"),
93                         link_params.merge(disposition: 'inline'),
94                         {title: file_path}) %>
95           </div>
96          </div>
97         <% else %>
98             <i class="fa fa-fw fa-file" href="<%=object.uuid%>/<%=file_path%>" ></i> <%= filename %></div>
99          </div>
100         <% end %>
101         </li>
102       <% end  # if file or directory %>
103     <% end  # file_tree.each %>
104     <%= raw(dirstack.map { |_| "</ul>" }.join("</li>")) %>
105   <% end  # if file_tree %>
106 </div>
107
108 <% content_for :footer_html do %>
109 <div id="collection-sharing-modal-window" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
110 <% end %>