From a99da79550536bdbe413dcd8b3702fd930d0f567 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Tue, 14 Mar 2023 18:27:38 +0100 Subject: [PATCH] Disable sorttable on tables without rows Otherwise, the first element of the table body is being fetched which might result in an error for empty tables. Fixes CODEOCEAN-JZ --- app/views/error_template_attributes/index.html.slim | 2 +- app/views/error_templates/index.html.slim | 2 +- app/views/error_templates/show.html.slim | 2 +- app/views/execution_environments/statistics.html.slim | 2 +- app/views/exercise_collections/statistics.html.slim | 2 +- app/views/exercises/statistics.html.slim | 4 ++-- app/views/external_users/statistics.html.slim | 2 +- app/views/request_for_comments/index.html.slim | 2 +- app/views/study_groups/_form.html.slim | 2 +- app/views/study_groups/show.html.slim | 2 +- app/views/tips/index.html.slim | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/views/error_template_attributes/index.html.slim b/app/views/error_template_attributes/index.html.slim index 11eae9e4..a695fded 100644 --- a/app/views/error_template_attributes/index.html.slim +++ b/app/views/error_template_attributes/index.html.slim @@ -1,7 +1,7 @@ h1 = ErrorTemplateAttribute.model_name.human(count: 2) .table-responsive - table.sortable.table + table.table class="#{@error_template_attributes.present? ? 'sortable' : ''}" thead tr th diff --git a/app/views/error_templates/index.html.slim b/app/views/error_templates/index.html.slim index fb2b9c3d..a4765980 100644 --- a/app/views/error_templates/index.html.slim +++ b/app/views/error_templates/index.html.slim @@ -1,7 +1,7 @@ h1 = ErrorTemplate.model_name.human(count: 2) .table-responsive - table.sortable.table + table.table class="#{@error_templates.present? ? 'sortable' : ''}" thead tr th = t('activerecord.attributes.error_template.name') diff --git a/app/views/error_templates/show.html.slim b/app/views/error_templates/show.html.slim index 37fb86ef..65e4069a 100644 --- a/app/views/error_templates/show.html.slim +++ b/app/views/error_templates/show.html.slim @@ -13,7 +13,7 @@ h2.mt-4 = t 'error_templates.attributes' .table-responsive - table.sortable.table + table.table class="#{@error_templates.error_template_attributes.present? ? 'sortable' : ''}" thead tr th diff --git a/app/views/execution_environments/statistics.html.slim b/app/views/execution_environments/statistics.html.slim index 2b12137d..a296b1ca 100644 --- a/app/views/execution_environments/statistics.html.slim +++ b/app/views/execution_environments/statistics.html.slim @@ -1,7 +1,7 @@ h1 = @execution_environment .table-responsive - table.table.table-striped.sortable + table.table.table-striped class="#{@execution_environment.present? ? 'sortable' : ''}" thead tr - ['.exercise', '.users', '.score', '.maximum_score', '.stddev_score', '.percentage_correct', '.runs', '.worktime', '.stddev_worktime'].each do |title| diff --git a/app/views/exercise_collections/statistics.html.slim b/app/views/exercise_collections/statistics.html.slim index 4b256cdc..bab6b76b 100644 --- a/app/views/exercise_collections/statistics.html.slim +++ b/app/views/exercise_collections/statistics.html.slim @@ -28,7 +28,7 @@ h1 = @exercise_collection h4.mt-4 = t('activerecord.attributes.exercise_collections.exercises') .table-responsive#exercise-list - table.table.sortable + table.table class="#{@exercise_collection.items.present? ? 'sortable' : ''}" thead tr th = '#' diff --git a/app/views/exercises/statistics.html.slim b/app/views/exercises/statistics.html.slim index e5bbe68c..a4df97ef 100644 --- a/app/views/exercises/statistics.html.slim +++ b/app/views/exercises/statistics.html.slim @@ -61,8 +61,9 @@ h1 = @exercise - if !policy(@exercise).detailed_statistics? - submissions = submissions.final - if submissions.any? + - users = symbol.to_s.classify.constantize.where(id: submissions.joins(symbol).group(:user_id).select(:user_id).distinct) .table-responsive - table.table.table-striped.sortable + table.table.table-striped class="#{users.present? ? 'sortable' : ''}" thead tr th.header = t('.user') @@ -71,7 +72,6 @@ h1 = @exercise th.header = t('.runs') if policy(@exercise).detailed_statistics? th.header = t('.worktime') if policy(@exercise).detailed_statistics? tbody - - users = symbol.to_s.classify.constantize.where(id: submissions.joins(symbol).group(:user_id).select(:user_id).distinct) - users.each do |user| - if user_statistics[user.class.name][user.id] then us = user_statistics[user.class.name][user.id] else us = {"maximum_score" => nil, "runs" => nil} - label = "#{user.displayname}" diff --git a/app/views/external_users/statistics.html.slim b/app/views/external_users/statistics.html.slim index 71d71564..38f32252 100644 --- a/app/views/external_users/statistics.html.slim +++ b/app/views/external_users/statistics.html.slim @@ -7,7 +7,7 @@ h1 = t('.title') - if submissions.any? .table-responsive - table.table.table-striped.sortable + table.table.table-striped class="#{exercises.present? ? 'sortable' : ''}" thead tr th.header = t('.exercise') diff --git a/app/views/request_for_comments/index.html.slim b/app/views/request_for_comments/index.html.slim index fa461119..bade3637 100644 --- a/app/views/request_for_comments/index.html.slim +++ b/app/views/request_for_comments/index.html.slim @@ -17,7 +17,7 @@ h1 = RequestForComment.model_name.human(count: 2) { class: 'form-control', multiple: true, "data-placeholder": t('request_for_comments.index.study_groups.placeholder') }) .table-responsive - table.table.sortable.mt-4 + table.table.mt-4 class="#{@request_for_comments.present? ? 'sortable' : ''}" thead tr th diff --git a/app/views/study_groups/_form.html.slim b/app/views/study_groups/_form.html.slim index 3e93dcaa..fc2407f8 100644 --- a/app/views/study_groups/_form.html.slim +++ b/app/views/study_groups/_form.html.slim @@ -6,7 +6,7 @@ h3 = t('activerecord.attributes.study_group.members') .table-responsive - table.sortable.table + table.table class="#{@members.present? ? 'sortable' : ''}" thead tr th = t('activerecord.attributes.exercise.selection') diff --git a/app/views/study_groups/show.html.slim b/app/views/study_groups/show.html.slim index 84d6d1fa..f25921e9 100644 --- a/app/views/study_groups/show.html.slim +++ b/app/views/study_groups/show.html.slim @@ -12,7 +12,7 @@ h1 h2.mt-4 = t('activerecord.attributes.study_group.members') .table-responsive - table.sortable.table + table.table class="#{@study_group.users.present? ? 'sortable' : ''}" thead tr th = t('navigation.sections.users') diff --git a/app/views/tips/index.html.slim b/app/views/tips/index.html.slim index 01edc1ad..2e257374 100644 --- a/app/views/tips/index.html.slim +++ b/app/views/tips/index.html.slim @@ -1,7 +1,7 @@ h1 = Tip.model_name.human(count: 2) .table-responsive - table.sortable.table + table.table class="#{@tips.present? ? 'sortable' : ''}" thead tr th = t('activerecord.attributes.tip.title')