Project

General

Profile

Feature #33422 » 0002-Adds-context-menu-to-admin-projects-list.patch

Jens Krämer, 2022-03-31 12:49

View differences:

app/controllers/context_menus_controller.rb
95 95

  
96 96
    render :layout => false
97 97
  end
98

  
99
  def projects
100
    @projects = Project.where(id: params[:ids]).to_a
101
    if @projects.empty?
102
      render_404
103
      return
104
    end
105

  
106
    if @projects.size == 1
107
      @project = @projects.first
108
    end
109
    render layout: false
110
  end
98 111
end
app/views/context_menus/projects.html.erb
1
<ul>
2
  <% if @project %>
3
    <% if @project.archived? %>
4
      <li><%= context_menu_link l(:button_unarchive), unarchive_project_path(@project), method: :post, class: 'icon icon-unlock' %></li>
5
    <% else %>
6
      <li><%= context_menu_link l(:button_archive), archive_project_path(@project), data: {confirm: l(:text_are_you_sure)}, method: :post, class: 'icon icon-lock' %></li>
7
    <% end %>
8
    <li>
9
      <%= context_menu_link l(:button_copy), copy_project_path(@projects), class: 'icon icon-copy' %>
10
    </li>
11
    <li>
12
      <%= context_menu_link l(:button_delete), project_path(@project, back_url: @back),
13
        method: :delete, data: {confirm: l(:text_project_destroy_confirmation)}, class: 'icon icon-del' %>
14
    </li>
15
  <% end %>
16
</ul>
app/views/projects/_list.html.erb
1
<% @admin_list = User.current.admin? && controller_name == 'admin' && action_name == 'projects' %>
1 2
<%= render_query_totals(@query) %>
3
<%= form_tag({}, data: {cm_url: projects_context_menu_path}) do -%>
4
<%= hidden_field_tag 'back_url', url_for(params: request.query_parameters), id: nil %>
2 5
<div class="autoscroll">
3 6
<table class="list projects odd-even <%= @query.css_classes %>">
4 7
<thead>
5 8
  <tr>
9
    <% if @admin_list %>
10
      <th class="checkbox hide-when-print">
11
        <input type="checkbox" name="check_all" id="check_all" value="" class="toggle-selection" title="Check all/Uncheck all">
12
      </th>
13
    <% end %>
6 14
    <% @query.inline_columns.each do |column| %>
7 15
      <%= column_header(@query, column) %>
8 16
    <% end %>
9
    <% if controller_name == 'admin' && action_name == 'projects' %>
10
    <th></th>
17
    <% if @admin_list %>
18
      <th></th>
11 19
    <% end %>
12 20
  </tr>
13 21
</thead>
......
26 34
        <%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
27 35
                             "toggleAllRowGroups(this)", :class => 'toggle-all') %>
28 36
      </td>
29
      <% if controller_name == 'admin' && action_name == 'projects' %>
30
      <td></td>
37
      <% if @admin_list %>
38
        <td></td>
31 39
      <% end %>
32 40
    </tr>
33 41
  <% end %>
34
  <tr id="project-<%= entry.id %>" class="<%= cycle('odd', 'even') %> <%= entry.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
42
  <tr id="project-<%= entry.id %>" class="<%= cycle('odd', 'even') %> hascontextmenu <%= entry.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
43
    <% if @admin_list %>
44
      <td class="checkbox hide-when-print"><%= check_box_tag("ids[]", entry.id, false, :id => nil) %></td>
45
    <% end %>
35 46
    <% @query.inline_columns.each do |column| %>
36 47
    <%= content_tag('td', column_content(column, entry), :class => column.css_classes) %>
37 48
    <% end %>
38
    <% if controller_name == 'admin' && action_name == 'projects' %>
39
    <td class="buttons">
40
      <%= link_to(l(:button_archive), archive_project_path(entry, :status => params[:status]), :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless entry.archived? %>
41
      <%= link_to(l(:button_unarchive), unarchive_project_path(entry, :status => params[:status]), :method => :post, :class => 'icon icon-unlock') if entry.archived? %>
42
      <%= link_to(l(:button_copy), copy_project_path(entry), :class => 'icon icon-copy') %>
43
      <%= link_to(l(:button_delete), project_path(entry), :method => :delete, :class => 'icon icon-del') %>
44
    </td>
49
    <% if @admin_list %>
50
      <td class="buttons"><%= link_to_context_menu %></td>
45 51
    <% end %>
46 52
  </tr>
47 53
<% end -%>
48 54
</tbody>
49 55
</table>
50 56
</div>
57
<% end -%>
51 58
<span class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></span>
52 59

  
53 60
<div id="csv-export-options" style="display:none;">
......
65 72
  </p>
66 73
  <% end %>
67 74
</div>
75
<%= context_menu if @admin_list %>
config/routes.rb
363 363
  post 'admin/test_email', :to => 'admin#test_email', :as => 'test_email'
364 364
  post 'admin/default_configuration', :to => 'admin#default_configuration'
365 365

  
366
  match '/admin/projects_context_menu', :to => 'context_menus#projects', :as => 'projects_context_menu', :via => [:get, :post]
367

  
366 368
  resources :auth_sources do
367 369
    member do
368 370
      get 'test_connection', :as => 'try_connection'
(4-4/6)