Skip to content

Commit

Permalink
Fix prefer-const warning for DataGrid (#12826)
Browse files Browse the repository at this point in the history
  • Loading branch information
vconst authored Apr 22, 2020
1 parent 0778a69 commit a20e6f1
Show file tree
Hide file tree
Showing 72 changed files with 1,574 additions and 3,127 deletions.
12 changes: 5 additions & 7 deletions js/ui/data_grid/aggregate_calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ function depthFirstSearch(i, depth, root, callback) {

// NOTE: https://github.com/jquery/jquery/blame/master/src/core.js#L392
function map(array, callback) {
let i; let result;
let i;

if('map' in array) {
return array.map(callback);
}

result = new Array(array.length);
const result = new Array(array.length);
for(i in array) {
result[i] = callback(array[i], i);
}
Expand Down Expand Up @@ -87,31 +87,29 @@ module.exports = Class.inherit({
},

_aggregate: function(aggregates, data, container) {
let i; let j;
const length = data.items ? data.items.length : 0;

for(i = 0; i < aggregates.length; i++) {
for(let i = 0; i < aggregates.length; i++) {
if(isCount(aggregates[i].aggregator)) {
container[i] = (container[i] || 0) + length;
continue;
}

for(j = 0; j < length; j++) {
for(let j = 0; j < length; j++) {
this._accumulate(i, aggregates[i], container, data.items[j]);
}
}
},

_calculateTotals: function(level, data) {
let i;
if(level === 0) {
this._totals = this._seed(this._totalAggregates);
}

if(level === this._groupLevel) {
this._aggregate(this._totalAggregates, data, this._totals);
} else {
for(i = 0; i < data.items.length; i++) {
for(let i = 0; i < data.items.length; i++) {
this._calculateTotals(level + 1, data.items[i]);
}
}
Expand Down
81 changes: 27 additions & 54 deletions js/ui/data_grid/ui.data_grid.export.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,8 @@ exports.DataProvider = Class.inherit({
const result = { cellSourceData: {}, value };
let column;
let value;
let i;
let summaryItems;
const columns = this.getColumns();
const correctedCellIndex = this._correctCellIndex(cellIndex);
let itemValues;
let item;

if(rowIndex < this.getHeaderRowCount()) {
const columnsRow = this.getColumns(true)[rowIndex];
Expand All @@ -229,10 +225,10 @@ exports.DataProvider = Class.inherit({
} else {
rowIndex -= this.getHeaderRowCount();

item = this._options.items.length && this._options.items[rowIndex];
const item = this._options.items.length && this._options.items[rowIndex];

if(item) {
itemValues = item.values;
const itemValues = item.values;
result.cellSourceData.rowType = item.rowType;
result.cellSourceData.column = columns[cellIndex] && columns[cellIndex].gridColumn;
switch(item.rowType) {
Expand All @@ -257,11 +253,11 @@ exports.DataProvider = Class.inherit({
result.cellSourceData.groupSummaryItems = this._convertFromGridGroupSummaryItems(item.summaryCells[0]);
result.value = this._getGroupValue(item);
} else {
summaryItems = item.values[correctedCellIndex];
const summaryItems = item.values[correctedCellIndex];
if(Array.isArray(summaryItems)) {
result.cellSourceData.groupSummaryItems = this._convertFromGridGroupSummaryItems(summaryItems);
value = '';
for(i = 0; i < summaryItems.length; i++) {
for(let i = 0; i < summaryItems.length; i++) {
value += (i > 0 ? (isExcelJS ? '\n' : ' \n ') : '') + dataGridCore.getSummaryText(summaryItems[i], this._options.summaryTexts);
}
result.value = value;
Expand Down Expand Up @@ -341,16 +337,12 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
_getColumns: function(initialColumnWidthsByColumnIndex) {
let result = [];
let i;
let j;
let column;
let columns;
const columnsController = this._columnsController;
const rowCount = columnsController.getRowCount();
let currentHeaderRow;
let currentColspan;

for(i = 0; i <= rowCount; i++) {
currentHeaderRow = [];
const currentHeaderRow = [];
columns = columnsController.getVisibleColumns(i, true);
let columnWidthsByColumnIndex;
if(i === rowCount) {
Expand All @@ -366,14 +358,14 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
}
}
}
for(j = 0; j < columns.length; j++) {
column = extend({}, columns[j], {
for(let j = 0; j < columns.length; j++) {
const column = extend({}, columns[j], {
dataType: columns[j].dataType === 'datetime' ? 'date' : columns[j].dataType,
gridColumn: columns[j],
});

if(this._needColumnExporting(column)) {
currentColspan = this._calculateExportColspan(column);
const currentColspan = this._calculateExportColspan(column);
if(isDefined(currentColspan)) {
column.exportColspan = currentColspan;
}
Expand Down Expand Up @@ -417,17 +409,13 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
_getFooterSummaryItems: function(summaryCells, isTotal) {
const result = [];
let estimatedItemsCount = 1;
let values;
let itemsLength;
let summaryCell;
let j;
let i = 0;

do {
values = [];
for(j = 0; j < summaryCells.length; j++) {
summaryCell = summaryCells[j];
itemsLength = summaryCell.length;
const values = [];
for(let j = 0; j < summaryCells.length; j++) {
const summaryCell = summaryCells[j];
const itemsLength = summaryCell.length;
if(estimatedItemsCount < itemsLength) {
estimatedItemsCount = itemsLength;
}
Expand All @@ -440,11 +428,10 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
},

_hasSummaryGroupFooters: function() {
let i;
const groupItems = this.option('summary.groupItems');

if(isDefined(groupItems)) {
for(i = 0; i < groupItems.length; i++) {
for(let i = 0; i < groupItems.length; i++) {
if(groupItems[i].showInGroupFooter) {
return true;
}
Expand All @@ -455,14 +442,12 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
},

_getItemsWithSummaryGroupFooters: function(sourceItems) {
let item;
let result = [];
let beforeGroupFooterItems = [];
let groupFooterItems = [];
let i;

for(i = 0; i < sourceItems.length; i++) {
item = sourceItems[i];
for(let i = 0; i < sourceItems.length; i++) {
const item = sourceItems[i];
if(item.rowType === 'groupFooter') {
groupFooterItems = this._getFooterSummaryItems(item.summaryCells);
result = result.concat(beforeGroupFooterItems, groupFooterItems);
Expand All @@ -476,23 +461,16 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
},

_updateGroupValuesWithSummaryByColumn: function(sourceItems) {
let item;
let summaryCells;
let summaryItem;
let summaryValues = [];
let groupColumnCount;
let k;
let j;
let i;

for(i = 0; i < sourceItems.length; i++) {
item = sourceItems[i];
summaryCells = item.summaryCells;
for(let i = 0; i < sourceItems.length; i++) {
const item = sourceItems[i];
const summaryCells = item.summaryCells;
if(item.rowType === 'group' && summaryCells && summaryCells.length > 1) {
groupColumnCount = item.values.length;
for(j = 1; j < summaryCells.length; j++) {
for(k = 0; k < summaryCells[j].length; k++) {
summaryItem = summaryCells[j][k];
const groupColumnCount = item.values.length;
for(let j = 1; j < summaryCells.length; j++) {
for(let k = 0; k < summaryCells[j].length; k++) {
const summaryItem = summaryCells[j][k];
if(summaryItem && summaryItem.alignByColumn) {
if(!Array.isArray(summaryValues[j - groupColumnCount])) {
summaryValues[j - groupColumnCount] = [];
Expand All @@ -513,20 +491,16 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
_processUnExportedItems: function(items) {
const columns = this._columnsController.getVisibleColumns(null, true);
const groupColumns = this._columnsController.getGroupColumns();
let item;
let column;
let values;
let summaryCells;
let i;
let j;

for(i = 0; i < items.length; i++) {
item = items[i];
for(let i = 0; i < items.length; i++) {
const item = items[i];
values = [];
summaryCells = [];

for(j = 0; j < columns.length; j++) {
column = columns[j];
for(let j = 0; j < columns.length; j++) {
const column = columns[j];
if(this._needColumnExporting(column)) {
if(item.values) {
if(item.rowType === 'group' && !values.length) {
Expand Down Expand Up @@ -562,7 +536,6 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
const totalItem = footerItems.length && footerItems[0];
const summaryTotalItems = that.option('summary.totalItems');
let summaryCells;
let summaryItems;

when(data).done(function(data) {
dataController.loadAll(data).done(function(sourceItems, totalAggregates) {
Expand All @@ -578,7 +551,7 @@ exports.ExportController = dataGridCore.ViewController.inherit({}).include(expor
summaryCells = dataController._getSummaryCells(summaryTotalItems, totalAggregates);
}

summaryItems = totalItem && that._getFooterSummaryItems(summaryCells, true);
const summaryItems = totalItem && that._getFooterSummaryItems(summaryCells, true);
if(summaryItems) {
sourceItems = sourceItems.concat(summaryItems);
}
Expand Down
9 changes: 3 additions & 6 deletions js/ui/data_grid/ui.data_grid.focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ gridCore.registerModule('focus', extend(true, {}, focusModule, {
const rowIndex = this.getRowIndexByKey(focusedRowKey);
const focusedRow = rowIndex >= 0 && this.getVisibleRows()[rowIndex];
const groups = columnsController.getGroupDataSourceParameters(true);
let getter;

if(focusedRow) {
for(let i = 0; i < path.length; ++i) {
getter = compileGetter(groups[i] && groups[i].selector);
const getter = compileGetter(groups[i] && groups[i].selector);

if(getter(focusedRow.data) !== path[i]) {
return false;
Expand Down Expand Up @@ -77,7 +76,6 @@ gridCore.registerModule('focus', extend(true, {}, focusModule, {
const dataSource = that._dataSource;
const filter = that._generateFilterByKey(key);
const deferred = new Deferred();
let groupPath;
const isGroupKey = Array.isArray(key);
const group = dataSource.group();

Expand All @@ -101,7 +99,7 @@ gridCore.registerModule('focus', extend(true, {}, focusModule, {
return deferred.resolve(-1).promise();
}

groupPath = that._getGroupPath(data[0]);
const groupPath = that._getGroupPath(data[0]);

that._expandGroupByPath(that, groupPath, 0).done(function() {

Expand All @@ -128,15 +126,14 @@ gridCore.registerModule('focus', extend(true, {}, focusModule, {

this._calculateGlobalRowIndexByFlatData(key, groupFilter).done(function(dataOffset) {
let count;
let currentPageOffset;
let groupContinuationCount;

if(dataOffset < 0) {
deferred.resolve(-1);
return;
}

currentPageOffset = (groupOffset % pageSize) || pageSize;
const currentPageOffset = (groupOffset % pageSize) || pageSize;

count = currentPageOffset + dataOffset - groupPath.length;

Expand Down
18 changes: 6 additions & 12 deletions js/ui/data_grid/ui.data_grid.grouping.collapsed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ exports.GroupingHelper = GroupingHelper.inherit((function() {
};

var processGroupItems = function(that, items, groupsCount, expandedInfo, path, isCustomLoading, isLastGroupExpanded) {
let i;
let item;
let groupInfo;
let isExpanded;

expandedInfo.items = expandedInfo.items || [];
Expand All @@ -29,15 +26,15 @@ exports.GroupingHelper = GroupingHelper.inherit((function() {

if(!groupsCount) return;

for(i = 0; i < items.length; i++) {
item = items[i];
for(let i = 0; i < items.length; i++) {
const item = items[i];
if(item.items !== undefined) {
path.push(item.key);

if(isCustomLoading) {
isExpanded = true;
} else {
groupInfo = that.findGroupInfo(path);
const groupInfo = that.findGroupInfo(path);
isExpanded = groupInfo && groupInfo.isExpanded;
}
if(!isExpanded) {
Expand Down Expand Up @@ -85,14 +82,12 @@ exports.GroupingHelper = GroupingHelper.inherit((function() {
};

var updateGroupInfos = function(that, options, items, loadedGroupCount, groupIndex, path, parentIndex) {
let item;
const groupCount = options.group ? options.group.length : 0;
const isLastGroupLevel = groupCount === loadedGroupCount;
const remotePaging = options.remoteOperations.paging;
let offset = 0;
let totalCount = 0;
let count;
let i;

groupIndex = groupIndex || 0;
path = path || [];
Expand All @@ -103,8 +98,8 @@ exports.GroupingHelper = GroupingHelper.inherit((function() {

if(groupIndex >= loadedGroupCount) return items.length;

for(i = 0; i < items.length; i++) {
item = items[i];
for(let i = 0; i < items.length; i++) {
const item = items[i];
if(item) {
path.push(item.key);

Expand All @@ -130,11 +125,10 @@ exports.GroupingHelper = GroupingHelper.inherit((function() {
};

const getTotalOffset = function(groupInfos, pageSize, offset) {
let groupIndex;
let groupSize;
let totalOffset = offset;

for(groupIndex = 0; groupIndex < groupInfos.length; groupIndex++) {
for(let groupIndex = 0; groupIndex < groupInfos.length; groupIndex++) {
groupSize = groupInfos[groupIndex].offset + 1;
if(groupIndex > 0) {
groupSize += groupInfos[groupIndex - 1].childrenTotalCount;
Expand Down
Loading

0 comments on commit a20e6f1

Please sign in to comment.