3531: Fix horizontal alignment of selectable and non-selectable things.
[arvados.git] / apps / workbench / app / views / projects / _show_sharing.html.erb
1 <%
2    uuid_map = {}
3    [@users, @groups].each do |obj_list|
4      obj_list.each { |o| uuid_map[o.uuid] = o }
5    end
6    perm_name_desc_map = {}
7    perm_desc_name_map = {}
8    perms_json = []
9    ['Read', 'Write', 'Manage'].each do |link_desc|
10      link_name = "can_#{link_desc.downcase}"
11      perm_name_desc_map[link_name] = link_desc
12      perm_desc_name_map[link_desc] = link_name
13      perms_json << {value: link_name, text: link_desc}
14    end
15    perms_json = perms_json.to_json
16    choose_filters = {
17      "groups" => [["group_class", "=", nil]],
18    }
19    choose_filters.default = []
20    owner_icon = fa_icon_class_for_uuid(@object.owner_uuid)
21    if owner_icon == "fa-users"
22      owner_icon = "fa-folder"
23      owner_type = "parent project"
24    else
25      owner_type = "owning user"
26    end
27 %>
28
29 <div class="pull-right">
30   <% ["users", "groups"].each do |share_class| %>
31
32   <%= link_to(send("choose_#{share_class}_path",
33       title: "Share with #{share_class}",
34       by_project: false,
35       preview_pane: false,
36       multiple: true,
37       limit: 10000,
38       filters: choose_filters[share_class].to_json,
39       action_method: 'post',
40       action_href: share_with_project_path,
41       action_name: 'Add',
42       action_data: {selection_param: 'uuids[]', success: 'tab-refresh'}.to_json),
43       class: "btn btn-primary btn-sm", remote: true, method: 'get') do %>
44   <i class="fa fa-fw fa-plus"></i> Share with <%= share_class %>&hellip;
45   <% end %>
46
47   <% end %>
48 </div>
49
50 <p>Permissions for this project are inherited from the <%= owner_type %>
51   <i class="fa fa-fw <%= owner_icon %>"></i>
52   <%= link_to_if_arvados_object @object.owner_uuid, friendly_name: true %>.
53 </p>
54
55 <table id="project_sharing" class="topalign table" style="clear: both; margin-top: 1em;">
56   <tr>
57     <th>User/Group Name</th>
58     <th colspan="2">Project Access</th>
59   </tr>
60
61   <% @share_links.andand.each do |link|
62        shared_with = uuid_map[link.tail_uuid]
63        if shared_with.nil?
64          link_name = link.tail_uuid
65        elsif shared_with.respond_to?(:full_name)
66          link_name = shared_with.full_name
67        else
68          link_name = shared_with.name
69        end %>
70   <tr data-object-uuid="<%= link.uuid %>">
71     <td>
72       <i class="fa fa-fw <%= fa_icon_class_for_uuid(link.tail_uuid) %>"></i>
73       <%= link_to_if_arvados_object(link.tail_uuid, link_text: link_name) %>
74     </td>
75     <td><%= link_to perm_name_desc_map[link.name], '#', {
76       "data-emptytext" => "Read",
77       "data-placement" => "bottom",
78       "data-type" => "select",
79       "data-url" => url_for(action: "update", id: link.uuid, controller: "links", merge: true),
80       "data-title" => "Set #{link_name}'s access level",
81       "data-name" => "[name]",
82       "data-pk" => {id: link.tail_uuid, key: "link"}.to_json,
83       "data-value" => link.name,
84       "data-clear" => false,
85       "data-source" => perms_json,
86       "data-tpl" => "<select id=\"share_change_level\"></select>",
87       "class" => "editable form-control",
88       } %>
89     </td>
90     <td>
91       <%= link_to(
92           {action: 'destroy', id: link.uuid, controller: "links"},
93           {title: 'Revoke', class: 'btn btn-default btn-nodecorate', method: :delete,
94            data: {confirm: "Revoke #{link_name}'s access to this project?",
95                   remote: true}}) do %>
96       <i class="fa fa-fw fa-trash-o"></i>
97       <% end %>
98     </td>
99   </tr>
100   <% end %>
101 </table>