Commit eb055bd0 authored by Alexander.Trofimov's avatar Alexander.Trofimov

refactoring

parent 2e41bddd
...@@ -2676,11 +2676,11 @@ CT_pivotTableDefinition.prototype.getRowFieldsCount = function (compact) { ...@@ -2676,11 +2676,11 @@ CT_pivotTableDefinition.prototype.getRowFieldsCount = function (compact) {
CT_pivotTableDefinition.prototype.getField = function (arrFields, callback) { CT_pivotTableDefinition.prototype.getField = function (arrFields, callback) {
return arrFields && arrFields.map(callback, this); return arrFields && arrFields.map(callback, this);
}; };
CT_pivotTableDefinition.prototype.forEachColItems = function (callback, thisArg) { CT_pivotTableDefinition.prototype.getRowItems = function () {
return this.colItems && this.colItems.i.forEach(callback, thisArg); return this.rowItems && this.rowItems.i;
}; };
CT_pivotTableDefinition.prototype.forEachRowItems = function (callback, thisArg) { CT_pivotTableDefinition.prototype.getColItems = function () {
return this.rowItems && this.rowItems.i.forEach(callback, thisArg); return this.colItems && this.colItems.i;
}; };
CT_pivotTableDefinition.prototype.asc_getName = function () { CT_pivotTableDefinition.prototype.asc_getName = function () {
return this.name; return this.name;
......
...@@ -4884,7 +4884,7 @@ ...@@ -4884,7 +4884,7 @@
pivotTable.init(); pivotTable.init();
var cleanRanges = []; var cleanRanges = [];
var pos, cells, bWarning, pivotRange; var pos, cells, bWarning, pivotRange;
var l = pivotTable.pageFieldsPositions.length; var i, l = pivotTable.pageFieldsPositions.length;
pos = 0 < l && pivotTable.pageFieldsPositions[0]; pos = 0 < l && pivotTable.pageFieldsPositions[0];
if (pos && 0 > pos.row) { if (pos && 0 > pos.row) {
// ToDo add check exist data in cells // ToDo add check exist data in cells
...@@ -4897,15 +4897,16 @@ ...@@ -4897,15 +4897,16 @@
}); });
cleanRanges.push(cells); cleanRanges.push(cells);
} }
pivotTable.pageFieldsPositions.forEach(function (pageFieldPos) { for (i = 0; i < pivotTable.pageFieldsPositions.length; ++i) {
cells = this.getRange3(pageFieldPos.row, pageFieldPos.col, pageFieldPos.row, pageFieldPos.col + 1); pos = pivotTable.pageFieldsPositions[i];
cells = this.getRange3(pos.row, pos.col, pos.row, pos.col + 1);
if (!bWarning) { if (!bWarning) {
cells._foreachNoEmpty(function (cell) { cells._foreachNoEmpty(function (cell) {
return (bWarning = !cell.isEmptyText()) ? null : cell; return (bWarning = !cell.isEmptyText()) ? null : cell;
}); });
} }
cleanRanges.push(cells); cleanRanges.push(cells);
}, this); }
var t = this; var t = this;
function callback(res) { function callback(res) {
if (res) { if (res) {
...@@ -4920,10 +4921,10 @@ ...@@ -4920,10 +4921,10 @@
} }
}; };
Worksheet.prototype._updatePivotTable = function (pivotTable, cleanRanges) { Worksheet.prototype._updatePivotTable = function (pivotTable, cleanRanges) {
cleanRanges.forEach(function (element) { var pos, cells, index, i, j, v, indexField, cacheIndex, sharedItem;
element.cleanAll(); for (i = 0; i < cleanRanges.length; ++i) {
}); cleanRanges[i].cleanAll();
var pos, cells, index, i; }
var pivotRange = pivotTable.getRange(); var pivotRange = pivotTable.getRange();
var cacheFields = pivotTable.asc_getCacheFields(); var cacheFields = pivotTable.asc_getCacheFields();
var pivotFields = pivotTable.asc_getPivotFields(); var pivotFields = pivotTable.asc_getPivotFields();
...@@ -4947,26 +4948,29 @@ ...@@ -4947,26 +4948,29 @@
cells = this.getRange3(start, c1, start, c1); cells = this.getRange3(start, c1, start, c1);
cells.setValue('Row Labels'); cells.setValue('Row Labels');
++start; ++start;
pivotTable.forEachRowItems(function (rowItem, rIndex) { var rowItem, rowItems = pivotTable.getRowItems();
rowItem.x.forEach(function (x, i) { if (rowItems) {
var v; for (i = 0; i < rowItems.length; ++i) {
rowItem = rowItems[i];
for (j = 0; j < rowItem.x.length; ++j) {
if (AscCommonExcel.c_oAscItemType.Grand === rowItem.t) { if (AscCommonExcel.c_oAscItemType.Grand === rowItem.t) {
v = 'Grand Total'; v = 'Grand Total';
} else { } else {
var indexField = rowFields[rowItem.getR()].asc_getIndex(); indexField = rowFields[rowItem.getR()].asc_getIndex();
var cacheIndex = pivotFields[indexField].getItem(x.getV()); cacheIndex = pivotFields[indexField].getItem(rowItem.x[j].getV());
var sharedItem = cacheFields[indexField].getSharedItem(cacheIndex.x); sharedItem = cacheFields[indexField].getSharedItem(cacheIndex.x);
v = sharedItem.v; v = sharedItem.v;
} }
cells = this.getRange3(start + rIndex, c1 + i, start + rIndex, c1 + i); cells = this.getRange3(start + i, c1 + j, start + i, c1 + j);
cells.setValue(v); cells.setValue(v);
}, this); }
}, this); }
}
}; };
Worksheet.prototype.updatePivotTablesStyle = function (range) { Worksheet.prototype.updatePivotTablesStyle = function (range) {
var pivotTable, pivotRange, styleInfo, style, wholeStyle, cells, j, pos, countC, countR, stripe1, stripe2, var pivotTable, pivotRange, styleInfo, style, wholeStyle, cells, j, r, pos, countC, countR, stripe1, stripe2,
start = 0, emptyStripe = new Asc.CTableStyleElement(); items, item, start = 0, emptyStripe = new Asc.CTableStyleElement();
var dxf, dxfLabels, dxfValues; var dxf, dxfLabels, dxfValues;
for (var i = 0; i < this.pivotTables.length; ++i) { for (var i = 0; i < this.pivotTables.length; ++i) {
pivotTable = this.pivotTables[i]; pivotTable = this.pivotTables[i];
...@@ -5055,56 +5059,59 @@ ...@@ -5055,56 +5059,59 @@
cells.setTableStyle(dxf); cells.setTableStyle(dxf);
} }
pivotTable.forEachColItems((function (thisArg, _pivotRange, _style, _styleInfo, _countC, startCol) { items = pivotTable.getColItems();
return function (item, index) { if (items) {
var _dxf, _cells, r, _col; start = pivotRange.c1 + Math.max(1, countR);
if (AscCommonExcel.c_oAscItemType.Grand === item.t || 0 === _countC) { for (j = 0; j < items.length; ++j) {
_dxf = _style.lastColumn; item = items[j];
if (AscCommonExcel.c_oAscItemType.Grand === item.t || 0 === countC) {
dxf = style.lastColumn;
} else { } else {
r = item.getR(); r = item.getR();
if (r + 1 !== _countC) { if (r + 1 !== countC) {
if (0 === r) { if (0 === r) {
_dxf = item.t ? _style.firstSubtotalColumn : _style.firstColumnSubheading; dxf = item.t ? style.firstSubtotalColumn : style.firstColumnSubheading;
} else if (1 === r % 2) { } else if (1 === r % 2) {
_dxf = item.t ? _style.secondSubtotalColumn : _style.secondColumnSubheading; dxf = item.t ? style.secondSubtotalColumn : style.secondColumnSubheading;
} else { } else {
_dxf = item.t ? _style.thirdSubtotalColumn : _style.thirdColumnSubheading; dxf = item.t ? style.thirdSubtotalColumn : style.thirdColumnSubheading;
} }
} }
} }
_dxf = _dxf && _dxf.dxf; dxf = dxf && dxf.dxf;
if (_dxf) { if (dxf) {
_col = startCol + index; cells = this.getRange3(pivotRange.r1 + 1, start + j, pivotRange.r2, start + j);
_cells = thisArg.getRange3(_pivotRange.r1 + 1, _col, _pivotRange.r2, _col); cells.setTableStyle(dxf);
_cells.setTableStyle(_dxf);
} }
}; }
})(this, pivotRange, style, styleInfo, countC, pivotRange.c1 + Math.max(1, countR))); }
pivotTable.forEachRowItems((function (thisArg, _pivotRange, _style, _styleInfo, _countR, startRow) { items = pivotTable.getRowItems();
return function (item, index) { if (items) {
var _dxf, _cells, r, _row; start = pivotRange.r1 + countC + 1;
if (AscCommonExcel.c_oAscItemType.Grand === item.t || 0 === _countR) { countR = pivotTable.getRowFieldsCount();
_dxf = _style.totalRow; for (j = 0; j < items.length; ++j) {
} else if (_styleInfo.showRowHeaders) { item = items[j];
if (AscCommonExcel.c_oAscItemType.Grand === item.t || 0 === countR) {
dxf = style.totalRow;
} else if (styleInfo.showRowHeaders) {
r = item.getR(); r = item.getR();
if (r + 1 !== _countR) { if (r + 1 !== countR) {
if (0 === r) { if (0 === r) {
_dxf = item.t ? _style.firstSubtotalRow : _style.firstRowSubheading; dxf = item.t ? style.firstSubtotalRow : style.firstRowSubheading;
} else if (1 === r % 2) { } else if (1 === r % 2) {
_dxf = item.t ? _style.secondSubtotalRow : _style.secondRowSubheading; dxf = item.t ? style.secondSubtotalRow : style.secondRowSubheading;
} else { } else {
_dxf = item.t ? _style.thirdSubtotalRow : _style.thirdRowSubheading; dxf = item.t ? style.thirdSubtotalRow : style.thirdRowSubheading;
} }
} }
} }
_dxf = _dxf && _dxf.dxf; dxf = dxf && dxf.dxf;
if (_dxf) { if (dxf) {
_row = startRow + index; cells = this.getRange3(start + j, pivotRange.c1, start + j, pivotRange.c2);
_cells = thisArg.getRange3(_row, _pivotRange.c1, _row, _pivotRange.c2); cells.setTableStyle(dxf);
_cells.setTableStyle(_dxf); }
}
} }
};
})(this, pivotRange, style, styleInfo, pivotTable.getRowFieldsCount(), pivotRange.r1 + countC + 1));
} }
}; };
Worksheet.prototype.inPivotTable = function (range) { Worksheet.prototype.inPivotTable = function (range) {
......
...@@ -1017,13 +1017,13 @@ ...@@ -1017,13 +1017,13 @@
SelectionRange.prototype.getUnion = function () { SelectionRange.prototype.getUnion = function () {
var result = new SelectionRange(); var result = new SelectionRange();
var unionRanges = function (ranges, res) { var unionRanges = function (ranges, res) {
ranges.forEach(function (item, i) { for (var i = 0; i < ranges.length; ++i) {
if (0 === i) { if (0 === i) {
res.assign2(item); res.assign2(ranges[i]);
} else { } else {
res.union(item); res.union(ranges[i]);
}
} }
});
}; };
unionRanges(this.ranges, result); unionRanges(this.ranges, result);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment