9b39b61d44240e44a81ef913487cd30ed768c4d7
[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">
21       <%= form_tag collection_path(@object.uuid), {method: 'get'} do %>
22         <input class="form-control" id="file_regex" name="file_regex" value="<%= params[:file_regex] %>" type="text"/>
23         <button id="file_regex_submit" type="submit" class="btn btn-primary" autofocus>Filter</button>
24       <% end %>
25     </div>
26   </div>
27   <p/>
28   <% end %>
29
30 <%
31   file_regex = nil
32   if params[:file_regex]
33     begin
34       file_regex = Regexp.new(params[:file_regex])
35     rescue RegexpError
36       # If the pattern is not a valid regex, quote it
37       # (i.e. use it as a simple substring search)
38       file_regex = Regexp.new(Regexp.quote(params[:file_regex]))
39     end
40   end
41 %>
42
43 <% file_tree = @object.andand.files_tree %>
44 <% if file_tree.nil? or file_tree.empty? %>
45   <p>This collection is empty.</p>
46 <% else %>
47   <ul id="collection_files" class="collection_files">
48   <% dirstack = [file_tree.first.first] %>
49   <% file_tree.take(10000).each_with_index do |(dirname, filename, size), index| %>
50     <% file_path = CollectionsHelper::file_path([dirname, filename]) %>
51     <% while dirstack.any? and (dirstack.last != dirname) %>
52       <% dirstack.pop %></ul></li>
53     <% end %>
54     <li>
55     <% if size.nil?  # This is a subdirectory. %>
56       <% dirstack.push(File.join(dirname, filename)) %>
57       <div class="collection_files_row">
58        <div class="collection_files_name"><i class="fa fa-fw fa-folder-open"></i> <%= filename %></div>
59       </div>
60       <ul class="collection_files">
61     <% else %>
62       <% if !file_regex.nil? and !file_regex.match(filename) %>
63         <% next %>
64       <% end %>
65       <% link_params = {controller: 'collections', action: 'show_file',
66                         uuid: @object.portable_data_hash, file: file_path, size: size} %>
67        <div class="collection_files_row">
68         <div class="collection_files_buttons pull-right">
69           <%= raw(human_readable_bytes_html(size)) %>
70           <% disable_search = (Rails.configuration.filename_suffixes_with_view_icon.include? file_path.split('.')[-1]) ? false : true %>
71           <%= link_to(raw('<i class="fa fa-search"></i>'),
72                       link_params.merge(disposition: 'inline'),
73                       {title: "View #{file_path}", class: "btn btn-info btn-sm", disabled: disable_search}) %>
74           <%= link_to(raw('<i class="fa fa-download"></i>'),
75                       link_params.merge(disposition: 'attachment'),
76                       {title: "Download #{file_path}", class: "btn btn-info btn-sm"}) %>
77         </div>
78
79         <div class="collection_files_name">
80           <% if !defined? no_checkboxes or !no_checkboxes %>
81           <%= check_box_tag 'uuids[]', "#{@object.uuid}/#{file_path}", false, {
82                 :class => 'persistent-selection',
83                 :friendly_type => "File",
84                 :friendly_name => "#{@object.uuid}/#{file_path}",
85                 :href => url_for(controller: 'collections', action: 'show_file',
86                                  uuid: @object.portable_data_hash, file: file_path),
87                 :title => "Include #{file_path} in your selections",
88               } %>
89           <span>&nbsp;</span>
90           <% end %>
91       <% if CollectionsHelper::is_image(filename) %>
92           <i class="fa fa-fw fa-bar-chart-o"></i> <%= filename %></div>
93        </div>
94         <div class="collection_files_inline">
95           <%= link_to(image_tag("#{url_for @object}/#{file_path}"),
96                       link_params.merge(disposition: 'inline'),
97                       {title: file_path}) %>
98         </div>
99       <% else %>
100           <i class="fa fa-fw fa-file"></i> <%= filename %></div>
101        </div>
102       <% end %>
103       </li>
104     <% end  # if file or directory %>
105   <% end  # file_tree.each %>
106   <%= raw(dirstack.map { |_| "</ul>" }.join("</li>")) %>
107 <% end  # if file_tree %>
108
109 <% content_for :footer_html do %>
110 <div id="collection-sharing-modal-window" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
111 <% end %>
112
113 </div>