From b127d8c754d06f80be892284d58352648358a9c8 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Mon, 6 Jul 2020 14:03:55 +0200 Subject: [PATCH] Improve active/archive switcher --- app/assets/javascripts/repositories/index.js | 10 +++++----- app/controllers/repositories_controller.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/repositories/index.js b/app/assets/javascripts/repositories/index.js index 8fbf031d3..4c624933c 100644 --- a/app/assets/javascripts/repositories/index.js +++ b/app/assets/javascripts/repositories/index.js @@ -100,9 +100,9 @@ function reloadSidebar() { var slidePanel = $('#slide-panel'); - var archived; - if ($('.repositories-index').hasClass('archived')) archived = true; - $.get(slidePanel.data('sidebar-url'), { archived: archived }, function(data) { + $.get(slidePanel.data('sidebar-url'), { + archived: $('.repositories-index').hasClass('archived') + }, function(data) { slidePanel.html(data.html); $('.create-new-repository').initializeModal('#create-repo-modal'); }); @@ -111,12 +111,12 @@ function initRepositoryViewSwitcher() { var viewSwitch = $('.view-switch'); viewSwitch.on('click', '.view-switch-archived', function() { - $('.repositories-index').toggleClass('archived active'); + $('.repositories-index').removeClass('active').addClass('archived'); initRepositoriesDataTable('#repositoriesList', true); reloadSidebar(); }); viewSwitch.on('click', '.view-switch-active', function() { - $('.repositories-index').toggleClass('archived active'); + $('.repositories-index').removeClass('archived').addClass('active'); initRepositoriesDataTable('#repositoriesList'); reloadSidebar(); }); diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 65000e671..1d0fd6dfc 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -37,7 +37,7 @@ class RepositoriesController < ApplicationController render json: { html: render_to_string(partial: 'repositories/sidebar_list.html.erb', locals: { repositories: @repositories, - archived: params[:archived] + archived: params[:archived] == 'true' }) } end @@ -376,7 +376,7 @@ class RepositoriesController < ApplicationController def load_repositories @repositories = Repository.accessible_by_teams(current_team).order('repositories.created_at ASC') - @repositories = if params[:archived] || @repository&.archived? + @repositories = if params[:archived] == 'true' || @repository&.archived? @repositories.archived else @repositories.active