diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index ccf83aa2f..1cfb98a2c 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -7,7 +7,7 @@ // - refresh project users tab after manage user modal is closed // - refactor view handling using library, ex. backbone.js -/* global HelperModule dropdownSelector Sidebar Turbolinks filterDropdown InfiniteScroll GLOBAL_CONSTANTS */ +/* global HelperModule dropdownSelector Sidebar Turbolinks filterDropdown InfiniteScroll AsyncDropdown GLOBAL_CONSTANTS */ /* eslint-disable no-use-before-define */ var ProjectsIndex = (function() { @@ -655,6 +655,7 @@ var ProjectsIndex = (function() { initProjectsFilters(); initArchiveRestoreButton(); loadCardsView(); + AsyncDropdown.init($(projectsWrapper)); $(projectsWrapper).on('click', '.folder-card-selector', function() { let folderCard = $(this).closest('.folder-card'); diff --git a/app/assets/javascripts/shared/async_dropdown.js b/app/assets/javascripts/shared/async_dropdown.js new file mode 100644 index 000000000..d9b6c47c0 --- /dev/null +++ b/app/assets/javascripts/shared/async_dropdown.js @@ -0,0 +1,20 @@ +/* eslint-disable no-unused-vars */ + +var AsyncDropdown = { + init: function($container) { + $container.on('click', '.dropdown-async button', function(e) { + var $parent = $(e.currentTarget).parent(); + + if ($parent.data('async-dropdown-initialized')) return; + + $parent.on('show.bs.dropdown', function() { + $parent.find('ul').empty().hide(); + $.get($parent.data('dropdown-url'), function(data) { + $parent.find('ul').replaceWith(data.html); + }); + }); + + $parent.data('async-dropdown-initialized', true); + }); + } +}; diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1b608219d..1ff2f57e9 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -12,9 +12,11 @@ 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 +341,17 @@ class ProjectsController < ApplicationController render json: { cards_view_type_class: cards_view_type_class(view_type_params) }, status: :ok end + def actions_dropdown + if stale?(@project) + render json: { + html: render_to_string( + partial: 'projects/index/project_actions_dropdown.html.erb', + locals: { project: @project } + ) + } + 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..7987fb71d 100644 --- a/app/views/projects/index/_project_actions_dropdown.html.erb +++ b/app/views/projects/index/_project_actions_dropdown.html.erb @@ -1,84 +1,77 @@ -<% cache [current_user, project] do %> -
diff --git a/app/views/projects/index/_project_card.html.erb b/app/views/projects/index/_project_card.html.erb index 2beb628fe..f13ccb631 100644 --- a/app/views/projects/index/_project_card.html.erb +++ b/app/views/projects/index/_project_card.html.erb @@ -27,7 +27,14 @@ <% 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),
- 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) %>
-
-
-
-
- -
-
-
- <%= t('projects.index.activities_option') %>
-
-
-
-