From d226bb5622614546374c05c7b2fc50874ab64770 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Thu, 2 Jul 2020 14:35:48 +0200 Subject: [PATCH] Fix date columns sorting in repositories list --- app/assets/javascripts/repositories/index.js | 20 ++++++++++++-- app/controllers/repositories_controller.rb | 2 +- app/helpers/repositories_datatable_helper.rb | 10 +++++-- app/views/repositories/index.html.erb | 29 ++------------------ 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/app/assets/javascripts/repositories/index.js b/app/assets/javascripts/repositories/index.js index 00480663e..6bc6a6a94 100644 --- a/app/assets/javascripts/repositories/index.js +++ b/app/assets/javascripts/repositories/index.js @@ -31,8 +31,8 @@ } function initRepositoriesDataTable(tableContainer, archived = false) { - var tableTemplate = archived ? $('#archivedRepositoriesListTable').html() : $('#activeRepositoriesListTable').html(); - $.get($(tableTemplate).data('source'), function(data) { + var tableTemplate = $('#RepositoriesListTable').html(); + $.get($(tableTemplate).data('source'), {archived: archived}, function(data) { if (REPOSITORIES_TABLE) REPOSITORIES_TABLE.destroy(); CHECKBOX_SELECTOR = null; $('.content-body').html(tableTemplate); @@ -61,6 +61,22 @@ render: function(value, type, row) { return `${value}`; } + }, { + targets: 5, + render: { + _: 'display', + sort: 'sort' + } + }, { + targets: 7, + visible: archived, + render: { + _: 'display', + sort: 'sort' + } + }, { + targets: 8, + visible: archived }], fnInitComplete: function(e) { var dataTableWrapper = $(e.nTableWrapper); diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 18fd71ad3..5bde474de 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -374,7 +374,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 diff --git a/app/helpers/repositories_datatable_helper.rb b/app/helpers/repositories_datatable_helper.rb index af27171b2..512c0f762 100644 --- a/app/helpers/repositories_datatable_helper.rb +++ b/app/helpers/repositories_datatable_helper.rb @@ -13,9 +13,15 @@ module RepositoriesDatatableHelper '2': repository.repository_rows.size, '3': repository.shared_with?(team), '4': escape_input(repository.team.name), - '5': I18n.l(repository.created_at, format: :full), + '5': { + display: I18n.l(repository.created_at, format: :full), + sort: repository.created_at.to_i + }, '6': escape_input(repository.created_by.full_name), - '7': (I18n.l(repository.archived_on, format: :full) if repository.archived_on), + '7': { + display: (I18n.l(repository.archived_on, format: :full) if repository.archived_on), + sort: repository.archived_on&.to_i + }, '8': escape_input(repository.archived_by&.full_name), 'repositoryUrl': repository_path(repository), 'DT_RowAttr': { diff --git a/app/views/repositories/index.html.erb b/app/views/repositories/index.html.erb index fdcd7fa5d..7978f226b 100644 --- a/app/views/repositories/index.html.erb +++ b/app/views/repositories/index.html.erb @@ -23,35 +23,10 @@ <% end %> - -