From 94441eb7469a8b61b51cdd66f4a7d60d6ed12690 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 21 Feb 2022 10:19:03 +0800 Subject: [PATCH 2/4] Adds context menu to admin projects list --- app/controllers/context_menus_controller.rb | 13 +++++++++ app/views/context_menus/projects.html.erb | 16 +++++++++++ app/views/projects/_list.html.erb | 32 +++++++++++++-------- config/routes.rb | 2 ++ 4 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 app/views/context_menus/projects.html.erb diff --git a/app/controllers/context_menus_controller.rb b/app/controllers/context_menus_controller.rb index 1fd34aabd3..f4ecb9547f 100644 --- a/app/controllers/context_menus_controller.rb +++ b/app/controllers/context_menus_controller.rb @@ -95,4 +95,17 @@ class ContextMenusController < ApplicationController 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 diff --git a/app/views/context_menus/projects.html.erb b/app/views/context_menus/projects.html.erb new file mode 100644 index 0000000000..d6a1177c77 --- /dev/null +++ b/app/views/context_menus/projects.html.erb @@ -0,0 +1,16 @@ + diff --git a/app/views/projects/_list.html.erb b/app/views/projects/_list.html.erb index ba26e9d61e..39978ee641 100644 --- a/app/views/projects/_list.html.erb +++ b/app/views/projects/_list.html.erb @@ -1,13 +1,21 @@ +<% @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 %>
+ <% if @admin_list %> + + <% end %> <% @query.inline_columns.each do |column| %> <%= column_header(@query, column) %> <% end %> - <% if controller_name == 'admin' && action_name == 'projects' %> - + <% if @admin_list %> + <% end %> @@ -26,28 +34,27 @@ <%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}", "toggleAllRowGroups(this)", :class => 'toggle-all') %> - <% if controller_name == 'admin' && action_name == 'projects' %> - + <% if @admin_list %> + <% end %> <% end %> - "> + "> + <% if @admin_list %> + + <% 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' %> - + <% if @admin_list %> + <% end %> <% end -%>
+ +
<%= check_box_tag("ids[]", entry.id, false, :id => nil) %> - <%= 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') %> - <%= link_to_context_menu %>
+<% end -%> <%= pagination_links_full @entry_pages, @entry_count %> +<%= context_menu if @admin_list %> diff --git a/config/routes.rb b/config/routes.rb index 5cb0055e57..9d6c541321 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -363,6 +363,8 @@ Rails.application.routes.draw do 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' -- 2.20.1