Skip to content

Commit

Permalink
Add eslint hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain-S committed Nov 15, 2023
1 parent 24640d2 commit 5353eb1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ repos:
tests|
scripts
)
- repo: https://github.com/pre-commit/mirrors-eslint
rev: 'v8.53.0'
hooks:
- id: eslint
25 changes: 13 additions & 12 deletions rctab/static/scripts/download_table.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*ToDo*/
function download_table_as_csv(table_id, start_date, separator = ',') {
"use strict";

function downloadTableAsCsv(table_id, start_date, separator = ',') {
// see https://stackoverflow.com/questions/15547198/export-html-table-to-csv-using-vanilla-javascript
// Select rows from table_id
var rows = document.querySelectorAll('table#' + table_id + ' tr');
var fulltable = document.getElementById("fullusagetable")
let rows = document.querySelectorAll('table#' + table_id + ' tr');
let fulltable = document.getElementById("fullusagetable")
fulltable.style.display = "block"
// Construct csv
var csv = [];
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll('td, th');
for (var j = 0; j < cols.length; j++) {
let csv = [];
for (let i = 0; i < rows.length; i++) {
let row = [], cols = rows[i].querySelectorAll('td, th');
for (let j = 0; j < cols.length; j++) {
// Clean innertext to remove multiple spaces and jumpline (break csv)
var data = cols[j].innerText.replace(/(\r\n|\n|\r)/gm, '').replace(/(\s\s)/gm, ' ')
let data = cols[j].innerText.replace(/(\r\n|\n|\r)/gm, '').replace(/(\s\s)/gm, ' ')
// Escape double-quote with double-double-quote
data = data.replace(/"/g, '""');
// Push escaped string
row.push('"' + data + '"');
}
csv.push(row.join(separator));
}
var csv_string = csv.join('\n');
let csv_string = csv.join('\n');
// Download it
var filename = table_id + '_' + new Date().toLocaleDateString().replace(/\//g, '-') + '_' + start_date + '.csv';
var link = document.createElement('a');
let filename = table_id + '_' + new Date().toLocaleDateString().replace(/\//g, '-') + '_' + start_date + '.csv';
let link = document.createElement('a');
link.style.display = 'none';
link.setAttribute('target', '_blank');
link.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv_string));
Expand Down
13 changes: 6 additions & 7 deletions rctab/static/scripts/tab_functions.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
"use strict";

/*ToDo*/
function openTab(evt, tabName) {
// Show the selected tab (tabName). Set the selected tab to be the active
// tab. The the selected tab will then be activated on page refresh.
sessionStorage.setItem('currentTab', tabName + "_btn")

// Declare all variables
var i, tabcontent, tablinks;

// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
let tabcontent = document.getElementsByClassName("tabcontent");
for (let i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}

// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
let tablinks = document.getElementsByClassName("tablinks");
for (let i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}

Expand Down
33 changes: 17 additions & 16 deletions rctab/static/scripts/tables.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/*ToDo*/
$(document).ready( function () {
// Only run on the main page
if ($('#subscription_table_all').length > 0) {
$('#subscription_table_all').DataTable({
columnDefs: [
{ orderable: false, targets: 0 }
],
order: [[2, 'asc']],
paging: false,
});
// Hide abolished rows by default
hideAbolishedRows(true);
document.getElementById("show_abolished_checkbox").checked = false;
}
} );
"use strict";

function hideAbolishedRows(input) {
// Hide or show abolished rows by finding rows with the red x and turning
Expand All @@ -31,3 +16,19 @@ function hideAbolishedRows(input) {
}
})
}

$(document).ready( function () {
// Only run on the main page
if ($('#subscription_table_all').length > 0) {
$('#subscription_table_all').DataTable({
columnDefs: [
{ orderable: false, targets: 0 }
],
order: [[2, 'asc']],
paging: false,
});
// Hide abolished rows by default
hideAbolishedRows(true);
document.getElementById("show_abolished_checkbox").checked = false;
}
} );
2 changes: 1 addition & 1 deletion rctab/templates/azure_usage_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% else %}
<div>
<h3>Subscription usage since {{ time_frame_start }}</h3>
<button id="download_btn" class="download" onclick="download_table_as_csv('subscription_usage', '{{ time_frame_start }}');">Download full usage data as CSV</button>
<button id="download_btn" class="download" onclick="downloadTableAsCsv('subscription_usage', '{{ time_frame_start }}');">Download full usage data as CSV</button>
</div>
<div class="col usageFigure">
{{ usage_fig | safe }}
Expand Down

0 comments on commit 5353eb1

Please sign in to comment.