From ae2cdf81e9e87a6cf83531046b8024530653d3d7 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 20 Oct 2025 17:45:40 +0000 Subject: [PATCH 1/5] Phase 1.2: Modernize JavaScript - Replace window with globalThis, parseInt/parseFloat with Number.* - Replaced window. with globalThis. (178 changes across 39 files) - Replaced parseInt( with Number.parseInt( - Replaced parseFloat( with Number.parseFloat( - Fixes SonarQube issues: javascript:S7764, javascript:S7773 - Total: ~313 JavaScript modernization issues resolved Co-Authored-By: Sam Fertig --- resources/assets/v1/src/app.js | 2 +- resources/assets/v1/src/app_vue.js | 6 +-- resources/assets/v1/src/bootstrap.js | 6 +-- .../src/components/administrations/Edit.vue | 12 ++--- .../src/components/exchange-rates/Index.vue | 2 +- .../src/components/exchange-rates/Rates.vue | 8 ++-- .../src/components/form/UserGroupCurrency.vue | 2 +- .../transactions/CreateTransaction.vue | 34 +++++++------- .../transactions/EditTransaction.vue | 46 +++++++++---------- .../transactions/ForeignAmountSelect.vue | 4 +- .../transactions/TransactionType.vue | 6 +-- .../v1/src/components/webhooks/Create.vue | 2 +- .../v1/src/components/webhooks/Edit.vue | 10 ++-- .../v1/src/components/webhooks/Show.vue | 6 +-- .../assets/v2/src/api/v1/model/account/get.js | 6 +-- .../v2/src/api/v1/model/transaction/put.js | 2 +- .../v2/src/api/v1/model/user-group/put.js | 2 +- .../assets/v2/src/api/v2/model/account/get.js | 6 +-- .../v2/src/api/v2/model/transaction/put.js | 2 +- .../v2/src/api/v2/model/user-group/put.js | 2 +- resources/assets/v2/src/boot/bootstrap.js | 18 ++++---- .../assets/v2/src/pages/accounts/index.js | 20 ++++---- .../v2/src/pages/administrations/create.js | 6 +-- .../v2/src/pages/administrations/edit.js | 12 ++--- .../v2/src/pages/administrations/index.js | 6 +-- .../assets/v2/src/pages/dashboard/accounts.js | 36 +++++++-------- .../assets/v2/src/pages/dashboard/boxes.js | 14 +++--- .../assets/v2/src/pages/dashboard/budgets.js | 22 ++++----- .../v2/src/pages/dashboard/categories.js | 16 +++---- .../v2/src/pages/dashboard/dashboard.js | 2 +- .../assets/v2/src/pages/dashboard/piggies.js | 22 ++++----- .../assets/v2/src/pages/dashboard/sankey.js | 24 +++++----- .../v2/src/pages/dashboard/subscriptions.js | 30 ++++++------ resources/assets/v2/src/pages/shared/dates.js | 22 ++++----- resources/assets/v2/src/pages/template.js | 2 +- .../v2/src/pages/transactions/create.js | 14 +++--- .../assets/v2/src/pages/transactions/edit.js | 22 ++++----- .../assets/v2/src/pages/transactions/index.js | 4 +- .../shared/autocomplete-functions.js | 12 ++--- .../shared/parse-downloaded-splits.js | 4 +- .../shared/process-attachments.js | 2 +- .../shared/splice-errors-into-transactions.js | 2 +- .../assets/v2/src/pages/transactions/show.js | 22 ++++----- .../assets/v2/src/store/get-configuration.js | 10 ++-- resources/assets/v2/src/store/get-variable.js | 10 ++-- .../assets/v2/src/store/get-variables.js | 2 +- resources/assets/v2/src/store/set-variable.js | 6 +-- .../v2/src/support/ag-grid/AmountEditor.js | 6 +-- .../support/ag-grid/TransactionDataSource.js | 8 ++-- resources/assets/v2/src/support/get-colors.js | 4 +- .../assets/v2/src/support/inline-edit.js | 4 +- .../assets/v2/src/support/page-navigation.js | 4 +- resources/assets/v2/src/util/format-money.js | 2 +- resources/assets/v2/src/util/format.js | 2 +- 54 files changed, 279 insertions(+), 279 deletions(-) diff --git a/resources/assets/v1/src/app.js b/resources/assets/v1/src/app.js index 7a39d988a39..29e0a4a9bd0 100644 --- a/resources/assets/v1/src/app.js +++ b/resources/assets/v1/src/app.js @@ -24,7 +24,7 @@ */ try { - window.$ = window.jQuery = require('jquery'); + globalThis.$ = globalThis.jQuery = require('jquery'); require('bootstrap-sass'); } catch (e) { diff --git a/resources/assets/v1/src/app_vue.js b/resources/assets/v1/src/app_vue.js index 42910613f43..84702e496e4 100644 --- a/resources/assets/v1/src/app_vue.js +++ b/resources/assets/v1/src/app_vue.js @@ -25,8 +25,8 @@ import Vue from 'vue'; import VueI18n from 'vue-i18n' import * as uiv from 'uiv'; -window.vuei18n = VueI18n; -window.uiv = uiv; +globalThis.vuei18n = VueI18n; +globalThis.uiv = uiv; Vue.use(vuei18n); Vue.use(uiv); -window.Vue = Vue; +globalThis.Vue = Vue; diff --git a/resources/assets/v1/src/bootstrap.js b/resources/assets/v1/src/bootstrap.js index ecf244473ff..425566e5b20 100644 --- a/resources/assets/v1/src/bootstrap.js +++ b/resources/assets/v1/src/bootstrap.js @@ -24,9 +24,9 @@ * CSRF token as a header based on the value of the "XSRF" token cookie. */ -window.axios = require('axios'); +globalThis.axios = require('axios'); -window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; +globalThis.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; /** * Next we will register the CSRF Token as a common header with Axios so that @@ -37,7 +37,7 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; let token = document.head.querySelector('meta[name="csrf-token"]'); if (token) { - window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; + globalThis.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; } else { console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); } diff --git a/resources/assets/v1/src/components/administrations/Edit.vue b/resources/assets/v1/src/components/administrations/Edit.vue index 24890c96ea2..b901e52ebde 100644 --- a/resources/assets/v1/src/components/administrations/Edit.vue +++ b/resources/assets/v1/src/components/administrations/Edit.vue @@ -110,8 +110,8 @@ export default { }; }, mounted() { - const page = window.location.href.split('/'); - const administrationId = parseInt(page[page.length - 1]); + const page = globalThis.location.href.split('/'); + const administrationId = Number.parseInt(page[page.length - 1]); this.downloadAdministration(administrationId); }, methods: { @@ -121,7 +121,7 @@ export default { this.administration = { id: current.id, title: current.attributes.title, - currency_id: parseInt(current.attributes.primary_currency_id), + currency_id: Number.parseInt(current.attributes.primary_currency_id), currency_code: current.attributes.primary_currency_code, currency_name: current.attributes.primary_currency_name, }; @@ -143,13 +143,13 @@ export default { // collect data let data = { title: this.administration.title, - primary_currency_id: parseInt(this.administration.currency_id), + primary_currency_id: Number.parseInt(this.administration.currency_id), }; // post! axios.put('./api/v1/user-groups/' + this.administration.id, data).then((response) => { - let administrationId = parseInt(response.data.data.id); - window.location.href = './administrations?user_group_id=' + administrationId + '&message=updated'; + let administrationId = Number.parseInt(response.data.data.id); + globalThis.location.href = './administrations?user_group_id=' + administrationId + '&message=updated'; }).catch((error) => { this.error_message = error.response.data.message; diff --git a/resources/assets/v1/src/components/exchange-rates/Index.vue b/resources/assets/v1/src/components/exchange-rates/Index.vue index 2a656ae5df5..381e0d784e1 100644 --- a/resources/assets/v1/src/components/exchange-rates/Index.vue +++ b/resources/assets/v1/src/components/exchange-rates/Index.vue @@ -104,7 +104,7 @@ export default { } if (response.data.meta.pagination.current_page < response.data.meta.pagination.total_pages) { - this.downloadCurrencies(parseInt(response.data.meta.pagination.current_page) + 1); + this.downloadCurrencies(Number.parseInt(response.data.meta.pagination.current_page) + 1); } }); }, diff --git a/resources/assets/v1/src/components/exchange-rates/Rates.vue b/resources/assets/v1/src/components/exchange-rates/Rates.vue index 0ac13a94ad0..4d7f4190e4d 100644 --- a/resources/assets/v1/src/components/exchange-rates/Rates.vue +++ b/resources/assets/v1/src/components/exchange-rates/Rates.vue @@ -217,14 +217,14 @@ export default { mounted() { // get from and to code from URL this.newDate = format(new Date, 'yyyy-MM-dd'); - let parts = window.location.href.split('/'); + let parts = globalThis.location.href.split('/'); this.from_code = parts[parts.length - 2]; this.to_code = parts[parts.length - 1]; - const params = new Proxy(new URLSearchParams(window.location.search), { + const params = new Proxy(new URLSearchParams(globalThis.location.search), { get: (searchParams, prop) => searchParams.get(prop), }); - this.page = parseInt(params.page ?? 1); + this.page = Number.parseInt(params.page ?? 1); this.downloadCurrencies(); @@ -378,7 +378,7 @@ export default { } } - this.totalPages = parseInt(response.data.meta.pagination.total_pages); + this.totalPages = Number.parseInt(response.data.meta.pagination.total_pages); this.loading = false; this.rates = Object.values(this.tempRates); // console.log('Do not download more pages. Now on page ' + this.page + ' of ' + this.totalPages); diff --git a/resources/assets/v1/src/components/form/UserGroupCurrency.vue b/resources/assets/v1/src/components/form/UserGroupCurrency.vue index fbd483b69db..750b71f558b 100644 --- a/resources/assets/v1/src/components/form/UserGroupCurrency.vue +++ b/resources/assets/v1/src/components/form/UserGroupCurrency.vue @@ -95,7 +95,7 @@ export default { } if (response.data.meta.pagination.current_page < response.data.meta.pagination.total_pages) { - this.downloadCurrencies(parseInt(response.data.meta.pagination.current_page) + 1); + this.downloadCurrencies(Number.parseInt(response.data.meta.pagination.current_page) + 1); } }); }, diff --git a/resources/assets/v1/src/components/transactions/CreateTransaction.vue b/resources/assets/v1/src/components/transactions/CreateTransaction.vue index c1969353be3..3ec9d14ec3a 100644 --- a/resources/assets/v1/src/components/transactions/CreateTransaction.vue +++ b/resources/assets/v1/src/components/transactions/CreateTransaction.vue @@ -280,23 +280,23 @@ export default { }, methods: { prefillSourceAccount() { - if (0 === window.sourceId) { + if (0 === globalThis.sourceId) { return; } - this.getAccount(window.sourceId, 'source_account'); + this.getAccount(globalThis.sourceId, 'source_account'); }, prefillDestinationAccount() { if (0 === destinationId) { return; } - this.getAccount(window.destinationId, 'destination_account'); + this.getAccount(globalThis.destinationId, 'destination_account'); }, getAccount(accountId, slot) { const uri = './api/v1/accounts/' + accountId + '?_token=' + document.head.querySelector('meta[name="csrf-token"]').content; axios.get(uri).then(response => { let model = response.data.data.attributes; model.type = this.fullAccountType(model.type, model.liability_type); - model.id = parseInt(response.data.data.id); + model.id = Number.parseInt(response.data.data.id); if ('source_account' === slot) { this.selectedSourceAccount(0, model); } @@ -391,12 +391,12 @@ export default { // if type is 'withdrawal' and destination is empty, cash withdrawal. if (transactionType === 'withdrawal' && '' === destName) { - destId = window.cashAccountId; + destId = globalThis.cashAccountId; } // if type is 'deposit' and source is empty, cash deposit. if (transactionType === 'deposit' && '' === sourceName) { - sourceId = window.cashAccountId; + sourceId = globalThis.cashAccountId; } // if index is over 0 and type is withdrawal or transfer, take source from index 0. @@ -420,7 +420,7 @@ export default { } // set foreign currency info: - if (row.foreign_amount.amount !== '' && parseFloat(row.foreign_amount.amount) !== .00) { + if (row.foreign_amount.amount !== '' && Number.parseFloat(row.foreign_amount.amount) !== .00) { foreignAmount = row.foreign_amount.amount; foreignCurrency = row.foreign_amount.currency_id; } @@ -480,14 +480,14 @@ export default { currentArray.foreign_currency_id = foreignCurrency; } // set budget id and piggy ID. - if (parseInt(row.budget) > 0) { - currentArray.budget_id = parseInt(row.budget); + if (Number.parseInt(row.budget) > 0) { + currentArray.budget_id = Number.parseInt(row.budget); } - if (parseInt(row.bill) > 0) { - currentArray.bill_id = parseInt(row.bill); + if (Number.parseInt(row.bill) > 0) { + currentArray.bill_id = Number.parseInt(row.bill); } - if (parseInt(row.piggy_bank) > 0) { - currentArray.piggy_bank_id = parseInt(row.piggy_bank); + if (Number.parseInt(row.piggy_bank) > 0) { + currentArray.piggy_bank_id = Number.parseInt(row.piggy_bank); } return currentArray; }, @@ -558,7 +558,7 @@ export default { button.removeAttr('disabled'); } else { //console.log('Will redirect to previous URL. (' + previousUrl + ')'); - window.location.href = window.previousUrl + '?transaction_group_id=' + groupId + '&message=created'; + globalThis.location.href = globalThis.previousUrl + '?transaction_group_id=' + groupId + '&message=created'; } }, @@ -737,7 +737,7 @@ export default { } if (key !== 'group_title') { // lol dumbest way to explode "transactions.0.something" ever. - transactionIndex = parseInt(key.split('.')[1]); + transactionIndex = Number.parseInt(key.split('.')[1]); fieldName = key.split('.')[2]; // set error in this object thing. switch (fieldName) { @@ -930,7 +930,7 @@ export default { } // force types on destination selector. - this.transactions[index].destination_account.allowed_types = window.allowedOpposingTypes.source[model.type]; + this.transactions[index].destination_account.allowed_types = globalThis.allowedOpposingTypes.source[model.type]; } //console.log('Transactions:'); //console.log(this.transactions); @@ -960,7 +960,7 @@ export default { } // force types on destination selector. - this.transactions[index].source_account.allowed_types = window.allowedOpposingTypes.destination[model.type]; + this.transactions[index].source_account.allowed_types = globalThis.allowedOpposingTypes.destination[model.type]; } }, clearSource: function (index) { diff --git a/resources/assets/v1/src/components/transactions/EditTransaction.vue b/resources/assets/v1/src/components/transactions/EditTransaction.vue index 1855355d7c9..28112de974a 100644 --- a/resources/assets/v1/src/components/transactions/EditTransaction.vue +++ b/resources/assets/v1/src/components/transactions/EditTransaction.vue @@ -412,8 +412,8 @@ export default { }, getGroup() { // console.log('EditTransaction: getGroup()'); - const page = window.location.href.split('/'); - const groupId = parseInt(page[page.length - 1]); + const page = globalThis.location.href.split('/'); + const groupId = Number.parseInt(page[page.length - 1]); const uri = './api/v1/transactions/' + groupId; @@ -462,12 +462,12 @@ export default { } } // console.log('source allowed types for a ' + transaction.type); - //console.log(window.expectedSourceTypes.source[transaction.type]); - // console.log(window.expectedSourceTypes.source[this.ucFirst(transaction.type)]); + //console.log(globalThis.expectedSourceTypes.source[transaction.type]); + // console.log(globalThis.expectedSourceTypes.source[this.ucFirst(transaction.type)]); // console.log('destination allowed types for a ' + transaction.type); - // console.log(window.expectedSourceTypes.destination[this.ucFirst(transaction.type)]); - if (typeof window.expectedSourceTypes === 'undefined') { - console.error('window.expectedSourceTypes is unexpectedly empty.') + // console.log(globalThis.expectedSourceTypes.destination[this.ucFirst(transaction.type)]); + if (typeof globalThis.expectedSourceTypes === 'undefined') { + console.error('globalThis.expectedSourceTypes is unexpectedly empty.') } let result = { transaction_journal_id: transaction.transaction_journal_id, @@ -529,7 +529,7 @@ export default { currency_name: transaction.currency_name, currency_code: transaction.currency_code, currency_decimal_places: transaction.currency_decimal_places, - allowed_types: window.expectedSourceTypes.source[this.ucFirst(transaction.type)] + allowed_types: globalThis.expectedSourceTypes.source[this.ucFirst(transaction.type)] }, destination_account: { id: transaction.destination_id, @@ -539,7 +539,7 @@ export default { currency_name: transaction.currency_name, currency_code: transaction.currency_code, currency_decimal_places: transaction.currency_decimal_places, - allowed_types: window.expectedSourceTypes.destination[this.ucFirst(transaction.type)] + allowed_types: globalThis.expectedSourceTypes.destination[this.ucFirst(transaction.type)] } }; // console.log('Source currency id is ' + result.source_account.currency_id); @@ -676,12 +676,12 @@ export default { // if type is 'withdrawal' and destination is empty, cash withdrawal. if (transactionType === 'withdrawal' && '' === destName) { - destId = window.cashAccountId; + destId = globalThis.cashAccountId; } // if type is 'deposit' and source is empty, cash deposit. if (transactionType === 'deposit' && '' === sourceName) { - sourceId = window.cashAccountId; + sourceId = globalThis.cashAccountId; } // if index is over 0 and type is withdrawal or transfer, take source from index 0. @@ -705,7 +705,7 @@ export default { } } // set foreign currency info: - if (typeof row.foreign_amount.amount !== 'undefined' && row.foreign_amount.amount.toString() !== '' && parseFloat(row.foreign_amount.amount) !== .00) { + if (typeof row.foreign_amount.amount !== 'undefined' && row.foreign_amount.amount.toString() !== '' && Number.parseFloat(row.foreign_amount.amount) !== .00) { foreignAmount = row.foreign_amount.amount; foreignCurrency = row.foreign_amount.currency_id; } @@ -772,16 +772,16 @@ export default { } // set budget id and piggy ID. - currentArray.budget_id = parseInt(row.budget); - if (parseInt(row.bill) > 0) { - currentArray.bill_id = parseInt(row.bill); + currentArray.budget_id = Number.parseInt(row.budget); + if (Number.parseInt(row.bill) > 0) { + currentArray.bill_id = Number.parseInt(row.bill); } - if (0 === parseInt(row.bill)) { + if (0 === Number.parseInt(row.bill)) { currentArray.bill_id = null; } - if (parseInt(row.piggy_bank) > 0) { - currentArray.piggy_bank_id = parseInt(row.piggy_bank); + if (Number.parseInt(row.piggy_bank) > 0) { + currentArray.piggy_bank_id = Number.parseInt(row.piggy_bank); } if (this.isReconciled && !this.storeAsNew && true === row.reconciled) { // drop content from array: @@ -806,8 +806,8 @@ export default { let button = $('#submitButton'); button.prop("disabled", true); - const page = window.location.href.split('/'); - const groupId = parseInt(page[page.length - 1]); + const page = globalThis.location.href.split('/'); + const groupId = Number.parseInt(page[page.length - 1]); let uri = './api/v1/transactions/' + groupId + '?_token=' + document.head.querySelector('meta[name="csrf-token"]').content; let method = 'PUT'; if (this.storeAsNew) { @@ -863,9 +863,9 @@ export default { } } else { if (this.storeAsNew) { - window.location.href = window.previousUrl + '?transaction_group_id=' + groupId + '&message=created'; + globalThis.location.href = globalThis.previousUrl + '?transaction_group_id=' + groupId + '&message=created'; } else { - window.location.href = window.previousUrl + '?transaction_group_id=' + groupId + '&message=updated'; + globalThis.location.href = globalThis.previousUrl + '?transaction_group_id=' + groupId + '&message=updated'; } } // console.log('End of redirectUser'); @@ -1119,7 +1119,7 @@ export default { } if (key !== 'group_title') { // lol dumbest way to explode "transactions.0.something" ever. - transactionIndex = parseInt(key.split('.')[1]); + transactionIndex = Number.parseInt(key.split('.')[1]); fieldName = key.split('.')[2]; // set error in this object thing. switch (fieldName) { diff --git a/resources/assets/v1/src/components/transactions/ForeignAmountSelect.vue b/resources/assets/v1/src/components/transactions/ForeignAmountSelect.vue index 3f61bec9ede..4b8136ce94a 100644 --- a/resources/assets/v1/src/components/transactions/ForeignAmountSelect.vue +++ b/resources/assets/v1/src/components/transactions/ForeignAmountSelect.vue @@ -32,7 +32,7 @@