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