7c7777d472e3cb48ff5b28a2c7d67d16e30a638d
[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             <% if object.editable? %>
31             <li><%= link_to "Remove selected files", '#',
32                     method: :post,
33                     'data-href' => url_for(controller: 'collections', action: :remove_selected_files),
34                     'data-selection-param-name' => 'selection[]',
35                     'data-selection-action' => 'remove-selected-files',
36                     'data-toggle' => 'dropdown',
37                     'class' => 'btn-remove-selected-files'
38               %></li>
39             <% end %>
40           </ul>
41         </div>
42         <div class="btn-group btn-group-sm">
43           <button id="select-all" type="button" class="btn btn-default" onClick="select_all_items()">Select all</button>
44           <button id="unselect-all" type="button" class="btn btn-default" onClick="unselect_all_items()">Unselect all</button>
45         </div>
46       </div>
47       <div class="pull-right">
48         <input class="form-control filterable-control" data-filterable-target="ul#collection_files" id="file_regex" name="file_regex" placeholder="filename regex" type="text"/>
49       </div>
50     </div>
51     <p/>
52   <% end %>
53
54   <% file_tree = object.andand.files_tree %>
55   <% if file_tree.nil? or file_tree.empty? %>
56     <p>This collection is empty.</p>
57   <% else %>
58     <ul id="collection_files" class="collection_files arv-selectable-items <%=preview_selectable_container%>">
59     <% dirstack = [file_tree.first.first] %>
60     <% file_tree.take(10000).each_with_index do |(dirname, filename, size), index| %>
61       <% file_path = CollectionsHelper::file_path([dirname, filename]) %>
62       <% while dirstack.any? and (dirstack.last != dirname) %>
63         <% dirstack.pop %></ul></li>
64       <% end %>
65       <li>
66       <% if size.nil?  # This is a subdirectory. %>
67         <% dirstack.push(File.join(dirname, filename)) %>
68         <div class="collection_files_row">
69          <div class="collection_files_name"><i class="fa fa-fw fa-folder-open"></i> <%= filename %></div>
70         </div>
71         <ul class="collection_files">
72       <% else %>
73         <% link_params = {controller: 'collections', action: 'show_file',
74                           uuid: object.portable_data_hash, file: file_path, size: size} %>
75          <div class="collection_files_row filterable <%=preview_selectable%>" href="<%=object.uuid%>/<%=file_path%>">
76           <div class="collection_files_buttons pull-right">
77             <%= raw(human_readable_bytes_html(size)) %>
78             <%= link_to(raw('<i class="fa fa-search"></i>'),
79                         link_params.merge(disposition: 'inline'),
80                         {title: "View #{file_path}", class: "btn btn-info btn-sm", disabled: !preview_allowed_for(file_path)}) %>
81             <%= link_to(raw('<i class="fa fa-download"></i>'),
82                         link_params.merge(disposition: 'attachment'),
83                         {title: "Download #{file_path}", class: "btn btn-info btn-sm"}) %>
84           </div>
85
86           <div class="collection_files_name">
87             <% if (!defined? no_checkboxes or !no_checkboxes) and current_user %>
88             <%= check_box_tag 'uuids[]', "#{object.uuid}/#{file_path}", false, {
89                   :class => "persistent-selection",
90                   :friendly_type => "File",
91                   :friendly_name => "#{object.uuid}/#{file_path}",
92                   :href => url_for(controller: 'collections', action: 'show_file',
93                                    uuid: object.portable_data_hash, file: file_path),
94                   :title => "Include #{file_path} in your selections",
95                   :id => "#{object.uuid}_file_#{index}",
96                 } %>
97             <span>&nbsp;</span>
98             <% end %>
99
100             <% if object.editable? %>
101                 <span class="btn-collection-remove-file-span">
102                 <%= link_to({controller: 'collections', action: 'remove_selected_files', id: object.uuid, selection: [object.portable_data_hash+'/'+file_path]}, method: :post, remote: true, data: {confirm: "Remove #{file_path}?", toggle: 'tooltip', placement: 'top'}, class: 'btn btn-sm btn-default btn-nodecorate btn-collection-file-control', title: 'Remove this file') do %>
103                   <i class="fa fa-fw fa-trash-o"></i>
104                 <% end %>
105                 </span>
106             <% end %>
107         <% if CollectionsHelper::is_image(filename) %>
108             <i class="fa fa-fw fa-bar-chart-o"></i>
109               <% if object.editable? %>
110                 <span class="btn-collection-rename-file-span">
111                 <%= render_editable_attribute object, 'filename', filename, {'data-value' => file_path, 'data-toggle' => 'manual', 'selection_path' => 'rename-file-path:'+file_path}, {tiptitle: 'Edit name or directory or both for this file', btnclass: 'collection-file-control'} %>
112                 </span>
113               <% else %>
114                 <%= filename %>
115               <% end %>
116             </div>
117           <div class="collection_files_inline">
118             <%= link_to(image_tag("#{url_for object}/#{file_path}"),
119                         link_params.merge(disposition: 'inline'),
120                         {title: file_path}) %>
121           </div>
122          </div>
123         <% else %>
124               <% if object.editable? %>
125                 <i class="fa fa-fw fa-file"></i><span class="btn-collection-rename-file-span"><%= render_editable_attribute object, 'filename', filename, {'data-value' => file_path, 'data-toggle' => 'manual', 'selection_name' => 'rename-file-path:'+file_path}, {tiptitle: 'Edit name or directory or both for this file', btnclass: 'collection-file-control'}  %>
126                 </span>
127               <% else %>
128                 <i class="fa fa-fw fa-file" href="<%=object.uuid%>/<%=file_path%>" ></i> <%= filename %>
129               <% end %>
130             </div>
131          </div>
132         <% end %>
133         </li>
134       <% end  # if file or directory %>
135     <% end  # file_tree.each %>
136     <%= raw(dirstack.map { |_| "</ul>" }.join("</li>")) %>
137   <% end  # if file_tree %>
138 </div>
139
140 <% content_for :footer_html do %>
141 <div id="collection-sharing-modal-window" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
142 <% end %>