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