From a910a9ede427e52a8260ca5c70631f9d2e880266 Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 15:37:15 +0930 Subject: [PATCH 01/11] the !== operator is used for strict inequality comparison, while the != operator is used for non-strict inequality comparison. Here are a few reasons why you might prefer to use !== instead of !=: The !== operator checks both the value and the type of the operands, whereas the != operator performs type coercion, which can lead to unexpected results. By using !==, you ensure that the values being compared are of the same type, making your code more robust and less prone to errors. --- app/assets/javascripts/application.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index c0c5e9ae..e0a846c8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -42,14 +42,14 @@ $( document ).on('turbolinks:load', function() { }); // Check if filter needs to be applied - if ((window._search != undefined) && (window._search.length > 0 )) { + if ((window._search !== undefined) && (window._search.length > 0 )) { // Apply the filter param to the filter box. table.search(window._search); table.draw(); // Clear the filter in the URL when the search param is updated. table.on( 'search.dt', function () { - if ((table.search() != window._search) && (window._search.length > 0 )) { + if ((table.search() !== window._search) && (window._search.length > 0 )) { var url = window.location.href; var tail = url.substring(url.lastIndexOf('/') + 1); var clean_tail = tail.substring(0, tail.lastIndexOf('?')); From ae8b7ae593793b1b2911b39d426e3543b272d255 Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 15:41:52 +0930 Subject: [PATCH 02/11] replacing var with const because const is immutable and the variables declared do not change --- app/assets/javascripts/application.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e0a846c8..f58e4913 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -30,7 +30,7 @@ $(document).ready(function() { $( document ).on('turbolinks:load', function() { // Initilize the table and save any state changes. - var table = $('[id$="table"]').DataTable({ + const table = $('[id$="table"]').DataTable({ stateSave: true, responsive: true }); @@ -50,10 +50,10 @@ $( document ).on('turbolinks:load', function() { // Clear the filter in the URL when the search param is updated. table.on( 'search.dt', function () { if ((table.search() !== window._search) && (window._search.length > 0 )) { - var url = window.location.href; - var tail = url.substring(url.lastIndexOf('/') + 1); - var clean_tail = tail.substring(0, tail.lastIndexOf('?')); - var clean_title = document.title.replace(/#(.*?)\s/, ''); + const url = window.location.href; + const tail = url.substring(url.lastIndexOf('/') + 1); + const clean_tail = tail.substring(0, tail.lastIndexOf('?')); + const clean_title = document.title.replace(/#(.*?)\s/, ''); history.replaceState({}, clean_title, clean_tail); document.title = clean_title; From 91944f0dd2652a3ff1f2151142e2f85846aeea73 Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 16:00:06 +0930 Subject: [PATCH 03/11] added commenting to better explain how the url is being manipulated --- app/assets/javascripts/application.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f58e4913..8243b77d 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -52,7 +52,11 @@ $( document ).on('turbolinks:load', function() { if ((table.search() !== window._search) && (window._search.length > 0 )) { const url = window.location.href; const tail = url.substring(url.lastIndexOf('/') + 1); + + // Remove any query parameters from the segment const clean_tail = tail.substring(0, tail.lastIndexOf('?')); + + // Clean up the document title by removing text after '#' symbol and whitespace const clean_title = document.title.replace(/#(.*?)\s/, ''); history.replaceState({}, clean_title, clean_tail); From 1531c4a47681c4bb39e4f8cb37d7e578f06d0a5d Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 16:07:18 +0930 Subject: [PATCH 04/11] replaced var with const where applicable and console logged the error --- .../javascripts/team_management/team_data_sets.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/team_management/team_data_sets.js b/app/assets/javascripts/team_management/team_data_sets.js index 1b39def4..4d1a544f 100644 --- a/app/assets/javascripts/team_management/team_data_sets.js +++ b/app/assets/javascripts/team_management/team_data_sets.js @@ -3,8 +3,8 @@ $(document).ready(function() { $("#team_data_set_url").blur(function() { - var url = $("#team_data_set_url").val(); - var separated = url.split("/dataset/"); + const url = $("#team_data_set_url").val(); + const separated = url.split("/dataset/"); var data = { id: separated[1] @@ -18,7 +18,9 @@ $(document).ready(function() { $("#team_data_set_description").val(data.result.notes); $("#hiddendescription").width($("#team_data_set_description").width()); - var content = data.result.notes.replace(/\n/g, "
"); + + const content = data.result.notes.replace(/\n/g, "
"); + $("#hiddendescription").html(content); $("#team_data_set_description").css("height", $("#hiddendescription").outerHeight()); }, @@ -27,10 +29,12 @@ $(document).ready(function() { }); try { $("#hiddendescription").width($("#team_data_set_description").width()); - var content = $("#team_data_set_description").val().replace(/\n/g, "
"); + + const content = $("#team_data_set_description").val().replace(/\n/g, "
"); + $("#hiddendescription").html(content); $("#team_data_set_description").css("height", $("#hiddendescription").outerHeight()); } catch (e) { - + console.error("An error occurred:", e); } }); \ No newline at end of file From 795ec032521ac8d04ee3942ca3a0d455f4d41274 Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 16:11:51 +0930 Subject: [PATCH 05/11] Update team_data_sets.js --- app/assets/javascripts/team_management/team_data_sets.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/assets/javascripts/team_management/team_data_sets.js b/app/assets/javascripts/team_management/team_data_sets.js index 4d1a544f..f69fb839 100644 --- a/app/assets/javascripts/team_management/team_data_sets.js +++ b/app/assets/javascripts/team_management/team_data_sets.js @@ -27,14 +27,19 @@ $(document).ready(function() { dataType: "jsonp" }) }); + try { + $("#hiddendescription").width($("#team_data_set_description").width()); const content = $("#team_data_set_description").val().replace(/\n/g, "
"); $("#hiddendescription").html(content); $("#team_data_set_description").css("height", $("#hiddendescription").outerHeight()); + } catch (e) { + console.error("An error occurred:", e); + } }); \ No newline at end of file From df33de72dcbf6404ad3098ac2038add72d5ed8a6 Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 16:46:55 +0930 Subject: [PATCH 06/11] Update scorecards.js --- app/assets/javascripts/admin/teams/scorecards.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/admin/teams/scorecards.js b/app/assets/javascripts/admin/teams/scorecards.js index 3b60ba50..aee916af 100644 --- a/app/assets/javascripts/admin/teams/scorecards.js +++ b/app/assets/javascripts/admin/teams/scorecards.js @@ -3,16 +3,13 @@ $( document ).on('ready turbolinks:load', function() { - var windowObjectReference; var strWindowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=700,height=800"; - function openRequestedPopup(team_scorecards_path) { - windowObjectReference = window.open(team_scorecards_path, 'Team Scorecards', strWindowFeatures); - } + const openRequestedPopup = (team_scorecards_path) => windowObjectReference = window.open(team_scorecards_path, 'Team Scorecards', strWindowFeatures); - function refreshParent() { - window.opener.location.reload(); - } + + const refreshParent = () => window.opener.location.reload(); + $('.open-team-scorecards').click(function (event) { event.preventDefault(); From 42e770a99a8ff29e9189f75fd8484ff148cde1e5 Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 16:47:02 +0930 Subject: [PATCH 07/11] Update projects.js --- app/assets/javascripts/projects.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/projects.js b/app/assets/javascripts/projects.js index 1f809780..acc7962c 100644 --- a/app/assets/javascripts/projects.js +++ b/app/assets/javascripts/projects.js @@ -2,16 +2,12 @@ // All this logic will automatically be available in application.js. $( document ).on('ready turbolinks:load', function() { - var windowObjectReference; - var strWindowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=500,height=800"; + const strWindowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=500,height=800"; - function openRequestedPopup() { - windowObjectReference = window.open(_scorecard_path, 'Scorecard', strWindowFeatures); - } + const openRequestedPopup = () => windowObjectReference = window.open(_scorecard_path, 'Scorecard', strWindowFeatures); + - function refreshParent() { - window.opener.location.reload(); - } + const refreshParent = () => window.opener.location.reload(); $('#open-scorecard').click(function (event) { event.preventDefault(); From e71fb3002738794f669545a7cf913469f588767b Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 16:51:36 +0930 Subject: [PATCH 08/11] Update entries.js we did not need to separate the URL variable into a separate "separated" variable so i changed it to one variable to get and split the variable. also replaced some of the vars with const --- .../javascripts/team_management/entries.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/team_management/entries.js b/app/assets/javascripts/team_management/entries.js index b2c275d6..300dde70 100644 --- a/app/assets/javascripts/team_management/entries.js +++ b/app/assets/javascripts/team_management/entries.js @@ -3,22 +3,22 @@ $( document ).on('ready turbolinks:load', function() { $("#team_data_set_url").blur(function() { - var url = $("#team_data_set_url").val(); - var separated = url.split("/dataset/"); - console.log(url); + const dataset = $("#team_data_set_url").val().split("/dataset/"); + var data = { - id: separated[1] + id: dataset[1] } $.ajax({ type: "GET", data: data, - url: separated[0] + "/api/3/action/package_show", + url: dataset[0] + "/api/3/action/package_show", success: function (data) { $("#team_data_set_name").val(data.result.title); $("#team_data_set_description").val(data.result.notes); - $("#hiddendescription").width($("#data_set_description").width()); - var content = data.result.notes.replace(/\n/g, "
"); + + const content = data.result.notes.replace(/\n/g, "
"); + $("#hiddendescription").html(content); $("#team_data_set_description").css("height", $("#hiddendescription").outerHeight()); }, @@ -27,7 +27,9 @@ $( document ).on('ready turbolinks:load', function() { }); try { $("#hiddendescription").width($("#data_set_description").width()); - var content = $("#team_data_set_description").val().replace(/\n/g, "
"); + + const content = $("#team_data_set_description").val().replace(/\n/g, "
"); + $("#hiddendescription").html(content); $("#team_data_set_description").css("height", $("#hiddendescription").outerHeight()); } catch (e) { From 6257d468d8d49021f7e6007889adef43010c190b Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 16:53:49 +0930 Subject: [PATCH 09/11] made name relate more to the function of the variable --- app/assets/javascripts/team_management/entries.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/team_management/entries.js b/app/assets/javascripts/team_management/entries.js index 300dde70..99736530 100644 --- a/app/assets/javascripts/team_management/entries.js +++ b/app/assets/javascripts/team_management/entries.js @@ -3,15 +3,15 @@ $( document ).on('ready turbolinks:load', function() { $("#team_data_set_url").blur(function() { - const dataset = $("#team_data_set_url").val().split("/dataset/"); + const teamUrlData = $("#team_data_set_url").val().split("/dataset/"); var data = { - id: dataset[1] + id: teamUrlData[1] } $.ajax({ type: "GET", data: data, - url: dataset[0] + "/api/3/action/package_show", + url: teamUrlData[0] + "/api/3/action/package_show", success: function (data) { $("#team_data_set_name").val(data.result.title); $("#team_data_set_description").val(data.result.notes); From ed4b7e27542c315ef9da96a767e68ee40801bba1 Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Tue, 23 May 2023 16:54:56 +0930 Subject: [PATCH 10/11] added error log to catch --- app/assets/javascripts/team_management/entries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/team_management/entries.js b/app/assets/javascripts/team_management/entries.js index 99736530..2b5bde03 100644 --- a/app/assets/javascripts/team_management/entries.js +++ b/app/assets/javascripts/team_management/entries.js @@ -33,6 +33,6 @@ $( document ).on('ready turbolinks:load', function() { $("#hiddendescription").html(content); $("#team_data_set_description").css("height", $("#hiddendescription").outerHeight()); } catch (e) { - + console.error('An error occured.', e) } }); \ No newline at end of file From bb07c678f48271c2a61a7e0e504b73a44e0b75b8 Mon Sep 17 00:00:00 2001 From: Munyaradzi Magura Date: Wed, 24 May 2023 10:29:42 +0930 Subject: [PATCH 11/11] made immutable variables const --- app/assets/javascripts/admin/teams/scorecards.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/teams/scorecards.js b/app/assets/javascripts/admin/teams/scorecards.js index aee916af..ae009126 100644 --- a/app/assets/javascripts/admin/teams/scorecards.js +++ b/app/assets/javascripts/admin/teams/scorecards.js @@ -3,7 +3,7 @@ $( document ).on('ready turbolinks:load', function() { - var strWindowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=700,height=800"; + const strWindowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=700,height=800"; const openRequestedPopup = (team_scorecards_path) => windowObjectReference = window.open(team_scorecards_path, 'Team Scorecards', strWindowFeatures); @@ -13,8 +13,8 @@ $( document ).on('ready turbolinks:load', function() { $('.open-team-scorecards').click(function (event) { event.preventDefault(); - var team_id = $(this).data("id"); - var include_judges =$(this).data("include-judges"); + const team_id = $(this).data("id"); + const include_judges =$(this).data("include-judges"); openRequestedPopup(_admin_teams_path + '/' + team_id + '/scorecards?include_judges='+ include_judges +'&popup=true'); });