diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ca5bb3..09fb26e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -67,3 +67,7 @@ repos: tests| scripts ) + - repo: https://github.com/pre-commit/mirrors-eslint + rev: 'v8.53.0' + hooks: + - id: eslint diff --git a/rctab/static/scripts/download_table.js b/rctab/static/scripts/download_table.js index 36e90ad..49e5671 100644 --- a/rctab/static/scripts/download_table.js +++ b/rctab/static/scripts/download_table.js @@ -1,17 +1,18 @@ -/*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 @@ -19,10 +20,10 @@ function download_table_as_csv(table_id, start_date, separator = ',') { } 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)); diff --git a/rctab/static/scripts/tab_functions.js b/rctab/static/scripts/tab_functions.js index 549d433..bf8687e 100644 --- a/rctab/static/scripts/tab_functions.js +++ b/rctab/static/scripts/tab_functions.js @@ -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", ""); } diff --git a/rctab/static/scripts/tables.js b/rctab/static/scripts/tables.js index 655a7ef..3599d3b 100644 --- a/rctab/static/scripts/tables.js +++ b/rctab/static/scripts/tables.js @@ -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 @@ -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; + } +} ); diff --git a/rctab/templates/azure_usage_info.html b/rctab/templates/azure_usage_info.html index a4f52fa..aa8f6ed 100644 --- a/rctab/templates/azure_usage_info.html +++ b/rctab/templates/azure_usage_info.html @@ -3,7 +3,7 @@ {% else %}

Subscription usage since {{ time_frame_start }}

- +
{{ usage_fig | safe }}