From bd794c28c2065226aa04f4ff2977200f5b0fc974 Mon Sep 17 00:00:00 2001 From: Ghislain Beaulac Date: Fri, 29 May 2020 11:31:54 -0400 Subject: [PATCH] fix(core): review all equality checks and make them all triple signs --- src/app/examples/custom-angularComponentEditor.ts | 2 +- src/app/examples/grid-editor.component.ts | 3 ++- .../modules/angular-slickgrid/aggregators/avgAggregator.ts | 2 +- .../modules/angular-slickgrid/aggregators/maxAggregator.ts | 4 ++-- .../modules/angular-slickgrid/aggregators/minAggregator.ts | 4 ++-- .../modules/angular-slickgrid/aggregators/sumAggregator.ts | 2 +- .../grouping-formatters/avgTotalsDollarFormatter.ts | 2 +- .../grouping-formatters/avgTotalsFormatter.ts | 2 +- .../grouping-formatters/avgTotalsPercentageFormatter.ts | 2 +- .../grouping-formatters/maxTotalsFormatter.ts | 2 +- .../grouping-formatters/minTotalsFormatter.ts | 2 +- .../grouping-formatters/sumTotalsBoldFormatter.ts | 2 +- .../grouping-formatters/sumTotalsColoredFormatter.ts | 2 +- .../grouping-formatters/sumTotalsDollarBoldFormatter.ts | 2 +- .../sumTotalsDollarColoredBoldFormatter.ts | 2 +- .../grouping-formatters/sumTotalsDollarColoredFormatter.ts | 2 +- .../grouping-formatters/sumTotalsDollarFormatter.ts | 2 +- .../grouping-formatters/sumTotalsFormatter.ts | 2 +- .../services/__tests__/excelExport.service.spec.ts | 2 +- .../modules/angular-slickgrid/services/excelExport.service.ts | 4 ++-- src/app/modules/angular-slickgrid/services/export.service.ts | 4 ++-- src/assets/lib/multiple-select/multiple-select.js | 2 +- 22 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/app/examples/custom-angularComponentEditor.ts b/src/app/examples/custom-angularComponentEditor.ts index 4a61c4630..13e3c93a9 100644 --- a/src/app/examples/custom-angularComponentEditor.ts +++ b/src/app/examples/custom-angularComponentEditor.ts @@ -161,7 +161,7 @@ export class CustomAngularComponentEditor implements Editor { } isValueChanged() { - return (!(this.componentRef.instance.selectedId === '' && this.defaultId == null)) && (this.componentRef.instance.selectedId !== this.defaultId); + return (!(this.componentRef.instance.selectedId === '' && (this.defaultId === null || this.defaultId === undefined))) && (this.componentRef.instance.selectedId !== this.defaultId); } validate(): EditorValidatorOutput { diff --git a/src/app/examples/grid-editor.component.ts b/src/app/examples/grid-editor.component.ts index df08b1bd3..2a152e161 100644 --- a/src/app/examples/grid-editor.component.ts +++ b/src/app/examples/grid-editor.component.ts @@ -41,7 +41,7 @@ const myCustomTitleValidator: EditorValidator = (value: any, args: EditorArgs) = // don't use "editor" property since that one is what SlickGrid uses internally by it's editor factory const columnEditor = args && args.column && args.column.internalColumnEditor; - if (value == null || value === undefined || !value.length) { + if (value === null || value === undefined || !value.length) { return { valid: false, msg: 'This is a required field' }; } else if (!/^Task\s\d+$/.test(value)) { return { valid: false, msg: 'Your title is invalid, it must start with "Task" followed by a number' }; @@ -644,6 +644,7 @@ export class GridEditorComponent implements OnInit { undo() { const command = this._commandQueue.pop(); + const item = this.angularGrid.dataView.getItem(command.row); if (command && Slick.GlobalEditorLock.cancelCurrentEdit()) { command.undo(); this.gridObj.gotoCell(command.row, command.cell, false); diff --git a/src/app/modules/angular-slickgrid/aggregators/avgAggregator.ts b/src/app/modules/angular-slickgrid/aggregators/avgAggregator.ts index 0919481a3..374a55700 100644 --- a/src/app/modules/angular-slickgrid/aggregators/avgAggregator.ts +++ b/src/app/modules/angular-slickgrid/aggregators/avgAggregator.ts @@ -19,7 +19,7 @@ export class AvgAggregator implements Aggregator { accumulate(item: any) { const val = (item && item.hasOwnProperty(this._field)) ? item[this._field] : null; this._count++; - if (val != null && val !== '' && !isNaN(val)) { + if (val !== null && val !== undefined && val !== '' && !isNaN(val)) { this._nonNullCount++; this._sum += parseFloat(val); } diff --git a/src/app/modules/angular-slickgrid/aggregators/maxAggregator.ts b/src/app/modules/angular-slickgrid/aggregators/maxAggregator.ts index 73eb95994..6dda33718 100644 --- a/src/app/modules/angular-slickgrid/aggregators/maxAggregator.ts +++ b/src/app/modules/angular-slickgrid/aggregators/maxAggregator.ts @@ -14,8 +14,8 @@ export class MaxAggregator implements Aggregator { accumulate(item: any) { const val = (item && item.hasOwnProperty(this._field)) ? item[this._field] : null; - if (val != null && val !== '' && !isNaN(val)) { - if (this._max == null || val > this._max) { + if (val !== null && val !== undefined && val !== '' && !isNaN(val)) { + if (this._max === null || this._max === undefined || val > this._max) { this._max = parseFloat(val); } } diff --git a/src/app/modules/angular-slickgrid/aggregators/minAggregator.ts b/src/app/modules/angular-slickgrid/aggregators/minAggregator.ts index f48752f0b..ac6649728 100644 --- a/src/app/modules/angular-slickgrid/aggregators/minAggregator.ts +++ b/src/app/modules/angular-slickgrid/aggregators/minAggregator.ts @@ -14,8 +14,8 @@ export class MinAggregator implements Aggregator { accumulate(item: any) { const val = (item && item.hasOwnProperty(this._field)) ? item[this._field] : null; - if (val != null && val !== '' && !isNaN(val)) { - if (this._min == null || val < this._min) { + if (val !== null && val !== undefined && val !== '' && !isNaN(val)) { + if (this._min === null || this._min === undefined || val < this._min) { this._min = parseFloat(val); } } diff --git a/src/app/modules/angular-slickgrid/aggregators/sumAggregator.ts b/src/app/modules/angular-slickgrid/aggregators/sumAggregator.ts index 3448ee69a..1a1cb2c3f 100644 --- a/src/app/modules/angular-slickgrid/aggregators/sumAggregator.ts +++ b/src/app/modules/angular-slickgrid/aggregators/sumAggregator.ts @@ -14,7 +14,7 @@ export class SumAggregator implements Aggregator { accumulate(item: any) { const val = (item && item.hasOwnProperty(this._field)) ? item[this._field] : null; - if (val != null && val !== '' && !isNaN(val)) { + if (val !== null && val !== undefined && val !== '' && !isNaN(val)) { this._sum += parseFloat(val); } } diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsDollarFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsDollarFormatter.ts index ab2776b85..58e4e0920 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsDollarFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsDollarFormatter.ts @@ -14,7 +14,7 @@ export const avgTotalsDollarFormatter: GroupTotalsFormatter = (totals: any, colu const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '$', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; } diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsFormatter.ts index 15377393e..35ca86529 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsFormatter.ts @@ -14,7 +14,7 @@ export const avgTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { if (val < 0) { val = Math.abs(val); if (!displayNegativeNumberWithParentheses) { diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsPercentageFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsPercentageFormatter.ts index 88a011284..7155ffa87 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsPercentageFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/avgTotalsPercentageFormatter.ts @@ -14,7 +14,7 @@ export const avgTotalsPercentageFormatter: GroupTotalsFormatter = (totals: any, const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { if (val < 0) { val = Math.abs(val); if (!displayNegativeNumberWithParentheses) { diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/maxTotalsFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/maxTotalsFormatter.ts index c299a78cb..99a4f0334 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/maxTotalsFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/maxTotalsFormatter.ts @@ -14,7 +14,7 @@ export const maxTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; } diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/minTotalsFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/minTotalsFormatter.ts index b9d450d43..c31c2eb5d 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/minTotalsFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/minTotalsFormatter.ts @@ -14,7 +14,7 @@ export const minTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; } diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsBoldFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsBoldFormatter.ts index 6413101c4..a6632ab80 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsBoldFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsBoldFormatter.ts @@ -14,7 +14,7 @@ export const sumTotalsBoldFormatter: GroupTotalsFormatter = (totals: any, column const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; } diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsColoredFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsColoredFormatter.ts index 4593c6e66..6b2ed4e70 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsColoredFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsColoredFormatter.ts @@ -14,7 +14,7 @@ export const sumTotalsColoredFormatter: GroupTotalsFormatter = (totals: any, col const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const colorStyle = (val >= 0) ? 'green' : 'red'; const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarBoldFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarBoldFormatter.ts index b513d1556..9d1898ccb 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarBoldFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarBoldFormatter.ts @@ -14,7 +14,7 @@ export const sumTotalsDollarBoldFormatter: GroupTotalsFormatter = (totals: any, const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '$', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; } diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarColoredBoldFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarColoredBoldFormatter.ts index e6a422265..2db74d9b3 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarColoredBoldFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarColoredBoldFormatter.ts @@ -14,7 +14,7 @@ export const sumTotalsDollarColoredBoldFormatter: GroupTotalsFormatter = (totals const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const colorStyle = (val >= 0) ? 'green' : 'red'; const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '$', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarColoredFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarColoredFormatter.ts index b5d3aed37..0feae0ef0 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarColoredFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarColoredFormatter.ts @@ -14,7 +14,7 @@ export const sumTotalsDollarColoredFormatter: GroupTotalsFormatter = (totals: an const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const colorStyle = (val >= 0) ? 'green' : 'red'; const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '$', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarFormatter.ts index dafad9bc6..48dd19f62 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsDollarFormatter.ts @@ -14,7 +14,7 @@ export const sumTotalsDollarFormatter: GroupTotalsFormatter = (totals: any, colu const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '$', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; } diff --git a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsFormatter.ts b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsFormatter.ts index d3ab525c1..088bfc5aa 100644 --- a/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsFormatter.ts +++ b/src/app/modules/angular-slickgrid/grouping-formatters/sumTotalsFormatter.ts @@ -14,7 +14,7 @@ export const sumTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: const thousandSeparator = getValueFromParamsOrFormatterOptions('thousandSeparator', columnDef, grid, ''); const displayNegativeNumberWithParentheses = getValueFromParamsOrFormatterOptions('displayNegativeNumberWithParentheses', columnDef, grid, false); - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { const formattedNumber = formatNumber(val, minDecimal, maxDecimal, displayNegativeNumberWithParentheses, '', '', decimalSeparator, thousandSeparator); return `${prefix}${formattedNumber}${suffix}`; } diff --git a/src/app/modules/angular-slickgrid/services/__tests__/excelExport.service.spec.ts b/src/app/modules/angular-slickgrid/services/__tests__/excelExport.service.spec.ts index b154fda1d..6624458a3 100644 --- a/src/app/modules/angular-slickgrid/services/__tests__/excelExport.service.spec.ts +++ b/src/app/modules/angular-slickgrid/services/__tests__/excelExport.service.spec.ts @@ -25,7 +25,7 @@ const myUppercaseFormatter: Formatter = (row, cell, value, columnDef, dataContex const myUppercaseGroupTotalFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column) => { const field = columnDef.field || ''; const val = totals.sum && totals.sum[field]; - if (val != null && !isNaN(+val)) { + if (val !== null && val !== undefined && !isNaN(+val)) { return `Custom: ${val}`; } return ''; diff --git a/src/app/modules/angular-slickgrid/services/excelExport.service.ts b/src/app/modules/angular-slickgrid/services/excelExport.service.ts index 69e83f79d..350f0c206 100644 --- a/src/app/modules/angular-slickgrid/services/excelExport.service.ts +++ b/src/app/modules/angular-slickgrid/services/excelExport.service.ts @@ -446,9 +446,9 @@ export class ExcelExportService { // loop through all the grid rows of data for (let rowNumber = 0; rowNumber < lineCount; rowNumber++) { const itemObj = this._dataView.getItem(rowNumber); - if (itemObj != null) { + if (itemObj) { // Normal row (not grouped by anything) would have an ID which was predefined in the Grid Columns definition - if (itemObj[this.datasetIdName] != null) { + if (itemObj[this.datasetIdName] !== null && itemObj[this.datasetIdName] !== undefined) { // get regular row item data originalDaraArray.push(this.readRegularRowData(columns, rowNumber, itemObj)); } else if (this._hasGroupedItems && itemObj.__groupTotals === undefined) { diff --git a/src/app/modules/angular-slickgrid/services/export.service.ts b/src/app/modules/angular-slickgrid/services/export.service.ts index f358392ad..67fd059ed 100644 --- a/src/app/modules/angular-slickgrid/services/export.service.ts +++ b/src/app/modules/angular-slickgrid/services/export.service.ts @@ -229,9 +229,9 @@ export class ExportService { // loop through all the grid rows of data for (let rowNumber = 0; rowNumber < lineCount; rowNumber++) { const itemObj = this._dataView.getItem(rowNumber); - if (itemObj != null) { + if (itemObj) { // Normal row (not grouped by anything) would have an ID which was predefined in the Grid Columns definition - if (itemObj[this.datasetIdName] != null) { + if (itemObj[this.datasetIdName] !== null && itemObj[this.datasetIdName] !== undefined) { // get regular row item data outputDataStrings.push(this.readRegularRowData(columns, rowNumber, itemObj)); } else if (this._hasGroupedItems && itemObj.__groupTotals === undefined) { diff --git a/src/assets/lib/multiple-select/multiple-select.js b/src/assets/lib/multiple-select/multiple-select.js index 8b27ab2ef..e3626fe6c 100644 --- a/src/assets/lib/multiple-select/multiple-select.js +++ b/src/assets/lib/multiple-select/multiple-select.js @@ -403,7 +403,7 @@ }).off('keyup').on('keyup', function (e) { // enter or space // Avoid selecting/deselecting if no choices made - if (that.options.filterAcceptOnEnter && (e.which === 13 || e.which == 32) && that.$searchInput.val()) { + if (that.options.filterAcceptOnEnter && (e.which === 13 || e.which === 32) && that.$searchInput.val()) { that.$selectAll.click(); that.close(); that.focus();