From b3e4b1480023700083ac6e778fb511b7171aad5c Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 9 May 2024 12:08:33 +0200 Subject: [PATCH] Add sorting to task comments --- app/javascript/vue/my_modules/list.vue | 2 +- app/services/lists/my_modules_service.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/javascript/vue/my_modules/list.vue b/app/javascript/vue/my_modules/list.vue index 8d6c0bf9b..0b96dc6d9 100644 --- a/app/javascript/vue/my_modules/list.vue +++ b/app/javascript/vue/my_modules/list.vue @@ -174,7 +174,7 @@ export default { columns.push({ field: 'comments', headerName: this.i18n.t('experiments.table.column.comments_html'), - sortable: false, + sortable: true, cellRenderer: CommentsRenderer, notSelectable: true }); diff --git a/app/services/lists/my_modules_service.rb b/app/services/lists/my_modules_service.rb index 30793b81d..439f24854 100644 --- a/app/services/lists/my_modules_service.rb +++ b/app/services/lists/my_modules_service.rb @@ -49,7 +49,8 @@ module Lists designated: 'designated', results: 'results', tags: 'tags', - signatures: 'signatures' + signatures: 'signatures', + comments: 'comments' } end @@ -83,6 +84,14 @@ module Lists @records = @records.order(:my_module_status_id) when 'status_DESC' @records = @records.order(my_module_status_id: :desc) + when 'comments_ASC' + @records = @records.left_joins(:task_comments) + .group('my_modules.id') + .order(Arel.sql('COUNT(DISTINCT comments.id) ASC')) + when 'comments_DESC' + @records = @records.left_joins(:task_comments) + .group('my_modules.id') + .order(Arel.sql('COUNT(DISTINCT comments.id) DESC')) when 'designated_ASC' @records = @records.left_joins(:user_my_modules) .group('my_modules.id')