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 %> - +<% project_form = nil %> +<%= form_for project, format: :json, method: :put, remote: true, html: { id: "edit-project-dropdown-form-#{project.id}" } do |f| %> + <% project_form = f %> + <%= f.hidden_field :archived, value: !project.archived %> <% end %> + 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 %>
- <%= render partial: 'projects/index/project_actions_dropdown.html.erb', locals: { project: project, view: 'cards' } %> +
diff --git a/config/routes.rb b/config/routes.rb index e7c808ff0..722c885b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -302,6 +302,7 @@ Rails.application.routes.draw do get 'notifications' get 'experiments_cards' get 'sidebar' + get 'actions_dropdown' put 'view_type' end