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