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
render :layout => false
end
def projects
@projects = Project.where(id: params[:ids]).to_a
if @projects.empty?
render_404
return
end
if @projects.size == 1
@project = @projects.first
end
render layout: false
end
end
app/views/context_menus/projects.html.erb
<ul>
<% if @project %>
<% if @project.archived? %>
<li><%= context_menu_link l(:button_unarchive), unarchive_project_path(@project), method: :post, class: 'icon icon-unlock' %></li>
<% else %>
<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>
<% end %>
<li>
<%= context_menu_link l(:button_copy), copy_project_path(@projects), class: 'icon icon-copy' %>
</li>
<li>
<%= context_menu_link l(:button_delete), project_path(@project, back_url: @back),
method: :delete, data: {confirm: l(:text_project_destroy_confirmation)}, class: 'icon icon-del' %>
</li>
<% end %>
</ul>
app/views/projects/_list.html.erb
<% @admin_list = User.current.admin? && controller_name == 'admin' && action_name == 'projects' %>
<%= render_query_totals(@query) %>
<%= form_tag({}, data: {cm_url: projects_context_menu_path}) do -%>
<%= hidden_field_tag 'back_url', url_for(params: request.query_parameters), id: nil %>
<div class="autoscroll">
<table class="list projects odd-even <%= @query.css_classes %>">
<thead>
<tr>
<% if @admin_list %>
<th class="checkbox hide-when-print">
<input type="checkbox" name="check_all" id="check_all" value="" class="toggle-selection" title="Check all/Uncheck all">
</th>
<% end %>
<% @query.inline_columns.each do |column| %>
<%= column_header(@query, column) %>
<% end %>
<% if controller_name == 'admin' && action_name == 'projects' %>
<th></th>
<% if @admin_list %>
<th></th>
<% end %>
</tr>
</thead>
......
<%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
"toggleAllRowGroups(this)", :class => 'toggle-all') %>
</td>
<% if controller_name == 'admin' && action_name == 'projects' %>
<td></td>
<% if @admin_list %>
<td></td>
<% end %>
</tr>
<% end %>
<tr id="project-<%= entry.id %>" class="<%= cycle('odd', 'even') %> <%= entry.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
<tr id="project-<%= entry.id %>" class="<%= cycle('odd', 'even') %> hascontextmenu <%= entry.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
<% if @admin_list %>
<td class="checkbox hide-when-print"><%= check_box_tag("ids[]", entry.id, false, :id => nil) %></td>
<% end %>
<% @query.inline_columns.each do |column| %>
<%= content_tag('td', column_content(column, entry), :class => column.css_classes) %>
<% end %>
<% if controller_name == 'admin' && action_name == 'projects' %>
<td class="buttons">
<%= 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? %>
<%= link_to(l(:button_unarchive), unarchive_project_path(entry, :status => params[:status]), :method => :post, :class => 'icon icon-unlock') if entry.archived? %>
<%= link_to(l(:button_copy), copy_project_path(entry), :class => 'icon icon-copy') %>
<%= link_to(l(:button_delete), project_path(entry), :method => :delete, :class => 'icon icon-del') %>
</td>
<% if @admin_list %>
<td class="buttons"><%= link_to_context_menu %></td>
<% end %>
</tr>
<% end -%>
</tbody>
</table>
</div>
<% end -%>
<span class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></span>
<div id="csv-export-options" style="display:none;">
......
</p>
<% end %>
</div>
<%= context_menu if @admin_list %>
config/routes.rb
post 'admin/test_email', :to => 'admin#test_email', :as => 'test_email'
post 'admin/default_configuration', :to => 'admin#default_configuration'
match '/admin/projects_context_menu', :to => 'context_menus#projects', :as => 'projects_context_menu', :via => [:get, :post]
resources :auth_sources do
member do
get 'test_connection', :as => 'try_connection'
(4-4/6)