3824: Merge branch 'master' into 3824-crunch-container-setup
[arvados.git] / apps / workbench / app / views / collections / _show_files.html.erb
1 <div class="selection-action-container" style="padding-left: 1em">
2   <% if !defined? no_checkboxes or !no_checkboxes %>
3   <div class="row">
4     <div class="pull-left">
5       <div class="btn-group btn-group-sm">
6         <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Selection... <span class="caret"></span></button>
7         <ul class="dropdown-menu" role="menu">
8           <li><%= link_to "Create new collection with selected files", '#',
9                   'data-href' => combine_selected_path(
10                     action_data: {current_project_uuid: @object.owner_uuid}.to_json
11                   ),
12                   'data-selection-param-name' => 'selection[]',
13                   'data-selection-action' => 'combine-collections',
14                   'method' => 'post',
15                   'data-toggle' => 'dropdown'
16             %></li>
17         </ul>
18       </div>
19     </div>
20     <div class="pull-right col-lg-3">
21       <%= form_tag collection_path(@object.uuid), {method: 'get'} do %>
22         <div class="input-group">
23           <input class="form-control" id="file_regex" name="file_regex" placeholder="regular expression" value="<%= params[:file_regex] %>" type="text"/>
24           <span class="input-group-btn">
25             <button id="file_regex_submit" type="submit" class="btn btn-primary" autofocus>Filter</button>
26           </span>
27         </div>
28       <% end %>
29     </div>
30   </div>
31   <p/>
32   <% end %>
33
34 <% file_regex = nil %>
35 <% if params[:file_regex] %>
36   <% begin %>
37     <% file_regex = Regexp.new(params[:file_regex]) %>
38   <% rescue RegexpError %>
39     <% # If the pattern is not a valid regex, quote it %>
40     <% # (i.e. use it as a simple substring search) %>
41     <div class="alert alert-info">
42       <p>The search term <code><%= params[:file_regex] %></code> could not be parsed as a regular expression.</p>
43       <p>Searching for files named <code><%= params[:file_regex] %></code> instead.</p>
44     </div>
45     <% file_regex = Regexp.new(Regexp.quote(params[:file_regex])) %>
46   <% end %>
47 <% end %>
48
49 <% file_tree = @object.andand.files_tree %>
50 <% if file_tree.nil? or file_tree.empty? %>
51   <p>This collection is empty.</p>
52 <% else %>
53   <ul id="collection_files" class="collection_files">
54   <% dirstack = [file_tree.first.first] %>
55   <% file_tree.reject { |(dirname, filename, size)|
56        # Eliminate any files that don't match file_regex
57        # (or accept all files if no file_regex was given)
58        size and file_regex and !file_regex.match(filename)
59        }
60        .take(10000)
61        .each_with_index do |(dirname, filename, size), index| %>
62     <% file_path = CollectionsHelper::file_path([dirname, filename]) %>
63     <% while dirstack.any? and (dirstack.last != dirname) %>
64       <% dirstack.pop %></ul></li>
65     <% end %>
66     <li>
67     <% if size.nil?  # This is a subdirectory. %>
68       <% dirstack.push(File.join(dirname, filename)) %>
69       <div class="collection_files_row">
70        <div class="collection_files_name"><i class="fa fa-fw fa-folder-open"></i> <%= filename %></div>
71       </div>
72       <ul class="collection_files">
73     <% else %>
74       <% link_params = {controller: 'collections', action: 'show_file',
75                         uuid: @object.portable_data_hash, file: file_path, size: size} %>
76        <div class="collection_files_row">
77         <div class="collection_files_buttons pull-right">
78           <%= raw(human_readable_bytes_html(size)) %>
79           <% disable_search = (Rails.configuration.filename_suffixes_with_view_icon.include? file_path.split('.')[-1]) ? false : true %>
80           <%= link_to(raw('<i class="fa fa-search"></i>'),
81                       link_params.merge(disposition: 'inline'),
82                       {title: "View #{file_path}", class: "btn btn-info btn-sm", disabled: disable_search}) %>
83           <%= link_to(raw('<i class="fa fa-download"></i>'),
84                       link_params.merge(disposition: 'attachment'),
85                       {title: "Download #{file_path}", class: "btn btn-info btn-sm"}) %>
86         </div>
87
88         <div class="collection_files_name">
89           <% if !defined? no_checkboxes or !no_checkboxes %>
90           <%= check_box_tag 'uuids[]', "#{@object.uuid}/#{file_path}", false, {
91                 :class => 'persistent-selection',
92                 :friendly_type => "File",
93                 :friendly_name => "#{@object.uuid}/#{file_path}",
94                 :href => url_for(controller: 'collections', action: 'show_file',
95                                  uuid: @object.portable_data_hash, file: file_path),
96                 :title => "Include #{file_path} in your selections",
97               } %>
98           <span>&nbsp;</span>
99           <% end %>
100       <% if CollectionsHelper::is_image(filename) %>
101           <i class="fa fa-fw fa-bar-chart-o"></i> <%= filename %></div>
102        </div>
103         <div class="collection_files_inline">
104           <%= link_to(image_tag("#{url_for @object}/#{file_path}"),
105                       link_params.merge(disposition: 'inline'),
106                       {title: file_path}) %>
107         </div>
108       <% else %>
109           <i class="fa fa-fw fa-file"></i> <%= filename %></div>
110        </div>
111       <% end %>
112       </li>
113     <% end  # if file or directory %>
114   <% end  # file_tree.each %>
115   <%= raw(dirstack.map { |_| "</ul>" }.join("</li>")) %>
116 <% end  # if file_tree %>
117
118 <% content_for :footer_html do %>
119 <div id="collection-sharing-modal-window" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
120 <% end %>
121
122 </div>