-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernise javascript #402
base: main
Are you sure you want to change the base?
Modernise javascript #402
Changes from all commits
a910a9e
ae8b7ae
91944f0
1531c4a
795ec03
df33de7
42e770a
e71fb30
6257d46
ed4b7e2
bb07c67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,21 +3,18 @@ | |
|
||
$( document ).on('ready turbolinks:load', function() { | ||
|
||
var windowObjectReference; | ||
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"; | ||
|
||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find its call. Could you please check if there is? |
||
|
||
|
||
$('.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'); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
|
@@ -42,18 +42,22 @@ $( 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 )) { | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tested edge cases? AFAIK there is a difference between null != undefined // false
null !== undefined // true |
||||||||||||||||||||||||||||||
// 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 )) { | ||||||||||||||||||||||||||||||
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/, ''); | ||||||||||||||||||||||||||||||
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('?')); | ||||||||||||||||||||||||||||||
Comment on lines
+53
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the whole purpose of these lines are to clean up the url. In this case we should wrap it into one function. Please, take this code as an example only:
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// 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); | ||||||||||||||||||||||||||||||
document.title = clean_title; | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
|
||
|
||
function refreshParent() { | ||
window.opener.location.reload(); | ||
} | ||
const refreshParent = () => window.opener.location.reload(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find its call. Could you please check if there is? |
||
|
||
$('#open-scorecard').click(function (event) { | ||
event.preventDefault(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 teamUrlData = $("#team_data_set_url").val().split("/dataset/"); | ||
|
||
var data = { | ||
id: separated[1] | ||
id: teamUrlData[1] | ||
} | ||
$.ajax({ | ||
type: "GET", | ||
data: data, | ||
url: separated[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); | ||
|
||
$("#hiddendescription").width($("#data_set_description").width()); | ||
var content = data.result.notes.replace(/\n/g, "<br>"); | ||
|
||
const content = data.result.notes.replace(/\n/g, "<br>"); | ||
|
||
$("#hiddendescription").html(content); | ||
$("#team_data_set_description").css("height", $("#hiddendescription").outerHeight()); | ||
}, | ||
|
@@ -27,10 +27,12 @@ $( document ).on('ready turbolinks:load', function() { | |
}); | ||
try { | ||
$("#hiddendescription").width($("#data_set_description").width()); | ||
var content = $("#team_data_set_description").val().replace(/\n/g, "<br>"); | ||
|
||
const content = $("#team_data_set_description").val().replace(/\n/g, "<br>"); | ||
|
||
$("#hiddendescription").html(content); | ||
$("#team_data_set_description").css("height", $("#hiddendescription").outerHeight()); | ||
} catch (e) { | ||
|
||
console.error('An error occured.', e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dp we use some error monitoring service like BugSnag? |
||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is windowObjectReference used somewhere?