diff --git a/app/assets/javascripts/shared/async_dropdown.js b/app/assets/javascripts/shared/async_dropdown.js new file mode 100644 index 000000000..87711b783 --- /dev/null +++ b/app/assets/javascripts/shared/async_dropdown.js @@ -0,0 +1,7 @@ +$(document).on('click', '.dropdown-async button', function(e) { + var $parent = $(e.currentTarget).parent(); + + $.get($parent.data('dropdown-url'), function(data) { + $parent.find('ul').replaceWith(data.html); + }); +}); diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1b608219d..37dbde62a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -12,9 +12,9 @@ class ProjectsController < ApplicationController helper_method :current_folder before_action :switch_team_with_param, only: :index - before_action :load_vars, only: %i(show edit update notifications sidebar experiments_cards view_type) + before_action :load_vars, only: %i(show edit update notifications sidebar experiments_cards view_type actions_dropdown) before_action :load_current_folder, only: %i(index cards new show) - before_action :check_view_permissions, only: %i(show notifications sidebar experiments_cards view_type) + before_action :check_view_permissions, only: %i(show notifications sidebar experiments_cards view_type actions_dropdown) before_action :check_create_permissions, only: %i(new create) before_action :check_manage_permissions, only: :edit before_action :load_exp_sort_var, only: :show @@ -339,6 +339,19 @@ class ProjectsController < ApplicationController render json: { cards_view_type_class: cards_view_type_class(view_type_params) }, status: :ok end + def actions_dropdown + respond_to do |format| + format.json do + render json: { + html: render_to_string( + partial: 'projects/index/project_actions_dropdown.html.erb', + locals: { project: @project, view: @project.current_view_state(current_user) } + ) + } + end + end + end + private def project_params diff --git a/app/views/projects/index/_project_actions_dropdown.html.erb b/app/views/projects/index/_project_actions_dropdown.html.erb index b62e95b49..0912d3e7b 100644 --- a/app/views/projects/index/_project_actions_dropdown.html.erb +++ b/app/views/projects/index/_project_actions_dropdown.html.erb @@ -1,84 +1,79 @@ <% cache [current_user, project] do %> -
+ + <% if project.active? && can_manage_project?(project) %> +-
+
+
+ <%= t('projects.index.edit_option') %>
+
+
<% end %>
-
- - <% if project.active? && can_manage_project?(project) %> --
-
-
- <%= t('projects.index.edit_option') %>
-
-
- <% end %>
-
- <% if project.active? && can_archive_project?(project) %>
- -
- <%= button_to(project_path(project, format: :json),
- method: :put,
- remote: true,
- class: 'btn btn-light',
- form_class: 'project-archive-restore-form',
- data: { confirm: t('projects.index.archive_confirm') },
- params: { project: { archived: true } }) do %>
-
- <%= t('projects.index.archive_option') %>
- <% end %>
-
- <% elsif project.archived? && can_restore_project?(project) %>
- -
- <%= button_to(project_path(project, format: :json),
- method: :put,
- remote: true,
- class: 'btn btn-light',
- form_class: 'project-archive-restore-form',
- params: { project: { archived: false } }) do %>
-
- <%= t('projects.index.restore_option') %>
- <% end %>
-
- <% end %>
-
- <% if can_read_project?(project) %>
- -
- <%= link_to can_manage_project_users?(project) ? edit_access_permissions_project_path(project) : access_permissions_project_path(project),
+
+ <% if project.active? && can_archive_project?(project) %>
+
-
+ <%= button_to(project_path(project, format: :json),
+ method: :put,
+ remote: true,
class: 'btn btn-light',
- data: { action: 'remote-modal'} do %>
-
- <%= I18n.t('projects.index.project_members_access') %>
- <% end %>
-
- <% end %>
-
- -
-
-
-
- <%= t('projects.index.comments_option', comments_count: project.comment_count) %>
-
-
+ form_class: 'project-archive-restore-form',
+ data: { confirm: t('projects.index.archive_confirm') },
+ params: { project: { archived: true } }) do %>
+
+ <%= t('projects.index.archive_option') %>
+ <% end %>
-
- -
-
-
- <%= t('projects.index.activities_option') %>
-
+ <% elsif project.archived? && can_restore_project?(project) %>
+
-
+ <%= button_to(project_path(project, format: :json),
+ method: :put,
+ remote: true,
+ class: 'btn btn-light',
+ form_class: 'project-archive-restore-form',
+ params: { project: { archived: false } }) do %>
+
+ <%= t('projects.index.restore_option') %>
+ <% end %>
-
-