From eb69697b9a8e1b76799aa5741e00656117d3cf5e Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Wed, 3 Nov 2021 16:02:21 +0100 Subject: [PATCH] Fix missing routes incompatible with a subpath --- app/assets/javascripts/error_templates.js | 7 ++++--- .../javascripts/exercise_collections.js.erb | 2 +- app/assets/javascripts/external_users.js | 15 ++++++++------- .../javascripts/statistics_activity_history.js | 2 +- app/assets/javascripts/statistics_graphs.js | 4 ++-- app/views/error_templates/show.html.slim | 2 +- app/views/external_users/show.html.slim | 2 +- app/views/request_for_comments/show.html.slim | 4 ++-- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/error_templates.js b/app/assets/javascripts/error_templates.js index 3cb7dcaf..d98840a7 100644 --- a/app/assets/javascripts/error_templates.js +++ b/app/assets/javascripts/error_templates.js @@ -1,7 +1,8 @@ $(document).on('turbolinks:load', function() { if ($.isController('error_templates')) { - $('#add-attribute').find('button').on('click', function () { - $.ajax('//' + location.host + location.pathname + '/attribute.json', { + const button = $('#add-attribute').find('button') + button.on('click', function () { + $.ajax(Routes.attribute_error_template_path(button.data('template-id')), { method: 'POST', data: { _method: 'PUT', @@ -15,4 +16,4 @@ $(document).on('turbolinks:load', function() { }); }); } -}); \ No newline at end of file +}); diff --git a/app/assets/javascripts/exercise_collections.js.erb b/app/assets/javascripts/exercise_collections.js.erb index 38e2fb13..c5930fb5 100644 --- a/app/assets/javascripts/exercise_collections.js.erb +++ b/app/assets/javascripts/exercise_collections.js.erb @@ -100,7 +100,7 @@ $(document).on('turbolinks:load', function() { tooltip.style("display", "none"); }) .on("click", function (_event, d) { - Turbolinks.visit("/exercises/" + d.exercise_id + "/statistics"); + Turbolinks.visit(Routes.statistics_exercise_path(d.exercise_id)); }) .attr("x", function (d) { return x(d.index); diff --git a/app/assets/javascripts/external_users.js b/app/assets/javascripts/external_users.js index 402c5473..f97436e3 100644 --- a/app/assets/javascripts/external_users.js +++ b/app/assets/javascripts/external_users.js @@ -1,13 +1,14 @@ $(document).on('turbolinks:load', function() { - var grid = $('#tag-grid'); + const grid = $('#tag-grid'); if ($.isController('external_users') && grid.isPresent()) { - var spinner = $('#loading'); - var noElements = $('#no-elements'); + const spinner = $('#loading'); + const user_id = spinner.data('user-id'); + const noElements = $('#no-elements'); - var buildTagContainer = function(tag) { + const buildTagContainer = function(tag) { return '\ - \ + \
\
' + tag.key + '
\
\ @@ -17,7 +18,7 @@ $(document).on('turbolinks:load', function() { '; }; - var jqxhr = $.ajax('//' + location.host + location.pathname + '/tag_statistics', { + const jqxhr = $.ajax(Routes.tag_statistics_external_user_path(user_id), { dataType: 'json', method: 'GET' }); @@ -26,7 +27,7 @@ $(document).on('turbolinks:load', function() { if (response.length === 0) { noElements.show(); } else { - var elements = response.map(buildTagContainer); + const elements = response.map(buildTagContainer); grid.append(elements); } }); diff --git a/app/assets/javascripts/statistics_activity_history.js b/app/assets/javascripts/statistics_activity_history.js index c4f03e5b..7126d428 100644 --- a/app/assets/javascripts/statistics_activity_history.js +++ b/app/assets/javascripts/statistics_activity_history.js @@ -49,7 +49,7 @@ $(document).on('turbolinks:load', function() { var refreshData = function (callback) { var params = new URLSearchParams(window.location.search.slice(1)); - var jqxhr = $.ajax('/statistics/graphs/' + prefix + '-activity-history.json', { + var jqxhr = $.ajax(Routes[`statistics_graphs_${prefix}_activity_history_path`](), { dataType: 'json', data: {from: params.get('from'), to: params.get('to'), interval: params.get('interval')}, method: 'GET' diff --git a/app/assets/javascripts/statistics_graphs.js b/app/assets/javascripts/statistics_graphs.js index 8caabe1a..bda79fa6 100644 --- a/app/assets/javascripts/statistics_graphs.js +++ b/app/assets/javascripts/statistics_graphs.js @@ -101,7 +101,7 @@ $(document).on('turbolinks:load', function() { }); } - manageGraph('user-activity', '/statistics/graphs/user-activity', 10); - manageGraph('rfc-activity', '/statistics/graphs/rfc-activity', 30); + manageGraph('user-activity', Routes.statistics_graphs_user_activity_path(), 10); + manageGraph('rfc-activity', Routes.statistics_graphs_rfc_activity_path(), 30); } }); diff --git a/app/views/error_templates/show.html.slim b/app/views/error_templates/show.html.slim index 19903fd8..66864c9a 100644 --- a/app/views/error_templates/show.html.slim +++ b/app/views/error_templates/show.html.slim @@ -41,4 +41,4 @@ h2.mt-4 = collection_select({}, :error_template_attribute_id, ErrorTemplateAttribute.where.not(id: @error_template.error_template_attributes.select(:id).to_a).order('important DESC', :key), :id, :key, {include_blank: false}, class: '') - button.btn.btn-outline-primary = t('error_templates.add_attribute') + button.btn.btn-outline-primary data-template-id=@error_template.id = t('error_templates.add_attribute') diff --git a/app/views/external_users/show.html.slim b/app/views/external_users/show.html.slim index e956256b..6477fa25 100644 --- a/app/views/external_users/show.html.slim +++ b/app/views/external_users/show.html.slim @@ -12,7 +12,7 @@ h4.mt-4 = link_to(t('.exercise_statistics'), statistics_external_user_path(@user - if current_user.admin? h4.mt-4 = t('.tag_statistics') - #loading + #loading data-user-id=@user.id .spinner = t('.loading_tag_statistics') #no-elements diff --git a/app/views/request_for_comments/show.html.slim b/app/views/request_for_comments/show.html.slim index c25d8ab6..890d371c 100644 --- a/app/views/request_for_comments/show.html.slim +++ b/app/views/request_for_comments/show.html.slim @@ -109,7 +109,7 @@ javascript: $.ajax({ dataType: 'json', method: 'GET', - url: '//' + location.host + location.pathname + '/mark_as_solved' + url: '#{ mark_as_solved_request_for_comment_path(@request_for_comment) }' }).done(function(response){ if(response.solved){ solvedButton.removeClass('btn-primary'); @@ -127,7 +127,7 @@ javascript: $.ajax({ dataType: 'json', method: 'POST', - url: '//' + location.host + location.pathname + '/set_thank_you_note', + url: '#{ set_thank_you_note_request_for_comment_path(@request_for_comment) }', data: { note: value }