Commit 21d3de03 authored by Igor.Zotov's avatar Igor.Zotov Committed by Alexander.Trofimov

оптимизация и рефакторинг а/ф(форматированных таблицы)

переписаны основные функции
отказался от кэша

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@62449 954022d7-b5bf-4e40-9824-e11837661b57
parent 80449ca9
......@@ -162,6 +162,7 @@
this.comments = [];
this.isLocked = false;
this.isFormatTable = false; // Нужен для disable возможности делать merge
this.tableStyleName = false;
this.styleName = null;
this.numFormatType = null;
this.angle = null;
......@@ -187,6 +188,7 @@
asc_getComments: function(){ return this.comments; },
asc_getLocked: function(){ return this.isLocked; },
asc_getIsFormatTable: function () { return this.isFormatTable; },
asc_getTableStyleName: function () { return this.tableStyleName; },
asc_getStyleName: function () { return this.styleName; },
asc_getNumFormatType: function(){ return this.numFormatType; },
asc_getAngle: function () { return this.angle; },
......@@ -212,6 +214,7 @@
prot["asc_getComments"] = prot.asc_getComments;
prot["asc_getLocked"] = prot.asc_getLocked;
prot["asc_getIsFormatTable"] = prot.asc_getIsFormatTable;
prot["asc_tableStyleName"] = prot.asc_tableStyleName;
prot["asc_getStyleName"] = prot.asc_getStyleName;
prot["asc_getNumFormatType"] = prot.asc_getNumFormatType;
prot["asc_getAngle"] = prot.asc_getAngle;
......
......@@ -97,7 +97,9 @@ var historyitem_AutoFilter_Empty = 3;
var historyitem_AutoFilter_ApplyDF = 4;
var historyitem_AutoFilter_ApplyMF = 5;
var historyitem_AutoFilter_Move = 6;
var historyitem_AutoFilter_CleanAutoFilter = 7;
var historyitem_AutoFilter_CleanAutoFilter = 7;
var historyitem_AutoFilter_Delete = 8;
var historyitem_AutoFilter_ChangeTableStyle = 9;
function CHistory(workbook)
......
......@@ -1119,8 +1119,8 @@
var oThis = this;
if(null != filters.Values)
{
for(var i = 0, length = filters.Values.length; i < length; ++i)
this.bs.WriteItem(c_oSer_FilterColumn.Filter, function(){oThis.WriteFilter(filters.Values[i]);});
for(var i in filters.Values)
this.bs.WriteItem(c_oSer_FilterColumn.Filter, function(){oThis.WriteFilter(i);});
}
if(null != filters.Dates)
{
......@@ -1301,7 +1301,7 @@
{
this.memory.WriteByte(c_oSer_SortState.ConditionRef);
this.memory.WriteByte(c_oSerPropLenType.Variable);
this.memory.WriteString2(sortCondition.Ref);
this.memory.WriteString2(sortCondition.Ref.getName());
}
if(null != sortCondition.ConditionSortBy)
{
......@@ -3772,6 +3772,15 @@
res = this.bcr.Read1(length, function(t,l){
return oThis.ReadFilters(t,l, oFilterColumn.Filters);
});
//sort dates
if(oFilterColumn.Filters && oFilterColumn.Filters.Dates && oFilterColumn.Filters.Dates.length)
{
oFilterColumn.Filters.Dates.sort (function sortArr(a, b)
{
return a.start - b.start;
})
}
}
else if ( c_oSer_FilterColumn.CustomFilters == type )
{
......@@ -3819,7 +3828,7 @@
return oThis.ReadFilter(t,l, oFilterVal);
});
if(null != oFilterVal.Val)
oFilters.Values.push(oFilterVal.Val);
oFilters.Values[oFilterVal.Val] = 1;
}
else if ( c_oSer_FilterColumn.DateGroupItem == type )
{
......@@ -3827,7 +3836,55 @@
res = this.bcr.Read2Spreadsheet(length, function(t,l){
return oThis.ReadDateGroupItem(t,l, oDateGroupItem);
});
oFilters.Dates.push(oDateGroupItem);
var startDate, endDate, date;
switch(oDateGroupItem.DateTimeGrouping)
{
case 1://day
{
date = new Date(Date.UTC( oDateGroupItem.Year, oDateGroupItem.Month - 1, oDateGroupItem.Day));
startDate = date.getExcelDateWithTime();
date.addDays(1)
endDate = date.getExcelDateWithTime();
break;
}
case 2://hour
{
startDate = new Date(Date.UTC( oDateGroupItem.Year, oDateGroupItem.Month - 1, oDateGroupItem.Day, oDateGroupItem.Hour, 1)).getExcelDateWithTime();
endDate = new Date(Date.UTC( oDateGroupItem.Year, oDateGroupItem.Month - 1, oDateGroupItem.Day, oDateGroupItem.Hour, 59)).getExcelDateWithTime();
break;
}
case 3://minute
{
startDate = new Date(Date.UTC( oDateGroupItem.Year, oDateGroupItem.Month - 1, oDateGroupItem.Day, oDateGroupItem.Hour, oDateGroupItem.Minute, 1)).getExcelDateWithTime();
endDate = new Date(Date.UTC( oDateGroupItem.Year, oDateGroupItem.Month - 1, oDateGroupItem.Day, oDateGroupItem.Hour, oDateGroupItem.Minute, 59)).getExcelDateWithTime();
break;
}
case 4://month
{
date = new Date(Date.UTC( oDateGroupItem.Year, oDateGroupItem.Month - 1, 1));
startDate = date.getExcelDateWithTime();
date.addMonths(1)
endDate = date.getExcelDateWithTime();
break;
}
case 5://second
{
startDate = new Date(Date.UTC( oDateGroupItem.Year, oDateGroupItem.Month - 1, oDateGroupItem.Day, oDateGroupItem.Hour, oDateGroupItem.Second)).getExcelDateWithTime();
endDate = new Date(Date.UTC( oDateGroupItem.Year, oDateGroupItem.Month - 1, oDateGroupItem.Day, oDateGroupItem.Hour, oDateGroupItem.Second )).getExcelDateWithTime();
break;
}
case 6://year
{
date = new Date(Date.UTC( oDateGroupItem.Year, 0));
startDate = date.getExcelDateWithTime();
date.addYears(1)
endDate = date.getExcelDateWithTime();
break;
}
}
oFilters.Dates.push(new dateElem(startDate, endDate, oDateGroupItem.DateTimeGrouping));
}
else if ( c_oSer_FilterColumn.FiltersBlank == type )
oFilters.Blank = this.stream.GetBool();
......@@ -3955,7 +4012,7 @@
{
var res = c_oSerConstants.ReadOk;
if ( c_oSer_SortState.ConditionRef == type )
oSortCondition.Ref = this.stream.GetString2LE(length);
oSortCondition.Ref = Asc.g_oRangeCache.getAscRange(this.stream.GetString2LE(length));
else if ( c_oSer_SortState.ConditionSortBy == type )
oSortCondition.ConditionSortBy = this.stream.GetUChar();
else if ( c_oSer_SortState.ConditionDescending == type )
......
......@@ -3121,7 +3121,8 @@ UndoRedoWoorksheet.prototype = {
row.setHeightProp(Data.oOldVal);
else
row.setHeightProp(Data.oNewVal);
//TODO проверить без этой перерисовки и убрать!!!
var workSheetView = this.wb.oApi.wb.getWorksheetById(nSheetId);
workSheetView.autoFilters.reDrawFilter(null, index);
}
......@@ -3343,7 +3344,7 @@ UndoRedoWoorksheet.prototype = {
worksheetView = this.wb.oApi.wb.getWorksheetById(nSheetId);
if(bUndo)//если на Undo перемещается диапазон из форматированной таблицы - стиль форматированной таблицы не должен цепляться
{
worksheetView.autoFilters._clearFormatTableStyle(to);
worksheetView.autoFilters._cleanStyleTable(to);
}
if(g_oUndoRedoAutoFiltersMoveData)
{
......
......@@ -4375,6 +4375,16 @@ AutoFilter.prototype.clone = function() {
return res;
};
AutoFilter.prototype.addFilterColumn = function() {
if(this.FilterColumns === null)
this.FilterColumns = [];
var oNewElem = new FilterColumn();
this.FilterColumns.push(oNewElem);
return oNewElem;
}
function FilterColumns() {
this.ColId = null;
this.CustomFiltersObj = null;
......@@ -4473,15 +4483,49 @@ FilterColumn.prototype.clone = function() {
res.ShowButton = this.ShowButton;
return res;
};
FilterColumn.prototype.isHideValue = function(val, isDateTimeFormat) {
var res = false;
if(this.Filters)
res = this.Filters.isHideValue(val, isDateTimeFormat);
else if(this.CustomFiltersObj)
res = this.CustomFiltersObj.isHideValue(val);
return res;
};
FilterColumn.prototype.clean = function(val) {
this.Filters = null;
this.CustomFiltersObj = null;
this.DynamicFilter = null;
this.ColorFilter = null;
this.Top10 = null;
};
FilterColumn.prototype.createFilter = function(obj) {
var allFilterOpenElements = false;
var newFilter;
if(obj.result && obj.result.length)
{
newFilter = new Filters();
this.Filters = newFilter;
}
else
{
newFilter = new CustomFilters();
this.CustomFiltersObj = newFilter
}
allFilterOpenElements = newFilter.create(obj);
return allFilterOpenElements;
};
/** @constructor */
function Filters() {
this.Values = [];
this.Values = {};
this.Dates = [];
this.Blank = null;
}
Filters.prototype.clone = function() {
var i, res = new Filters();
res.Values = this.Values.slice();
for(var i in this.Values)
res.Values[i] = this.Values[i];
if (this.Dates) {
for (i = 0; i < this.Dates.length; ++i)
res.Dates.push(this.Dates[i].clone());
......@@ -4489,6 +4533,60 @@ Filters.prototype.clone = function() {
res.Blank = this.Blank;
return res;
};
Filters.prototype.create = function(obj) {
var allFilterOpenElements = true;
for(var i = 0; i < obj.result.length; i++)
{
if(obj.result[i].visible)
this.Values[obj.result[i].val] = true;
else
allFilterOpenElements = false;
}
return allFilterOpenElements;
};
Filters.prototype.isHideValue = function(val, isDateTimeFormat) {
var res = false;
if(isDateTimeFormat && this.Dates)
res = this.binarySearch(val, this.Dates) !== -1 ? false : true;
else if(this.Values)
res = !this.Values[val] ? true : false;
return res;
};
Filters.prototype.binarySearch = function(val, array) {
var i = 0, j = array.length - 1, k;
val = parseFloat(val);
while (i <= j)
{
k = Math.floor((i + j) / 2);
if (val >= array[k].start && val < array[k].end)
return k;
else if (val < array[k].start)
j = k - 1;
else
i = k + 1;
}
return -1;
};
Filters.prototype.linearSearch = function(val, array) {
var n = array.length, i = 0;
val = parseFloat(val);
while (i <= n && !(array[i] && val >= array[i].start && val < array[i].end))
i++;
if (i < n)
return i;
else
return -1;
};
/** @constructor */
function Filter() {
this.Val = null;
......@@ -4529,10 +4627,27 @@ CustomFilters.prototype.clone = function() {
}
return res;
};
CustomFilters.prototype.create = function(obj) {
this.And = !obj.isChecked;
this.CustomFilters = [];
if(obj.filter1 != undefined)
this.CustomFilters[0] = new CustomFilter(obj.filter1, obj.valFilter1);
if(obj.filter2 != undefined)
this.CustomFilters[1] = new CustomFilter(obj.filter2, obj.valFilter2);
};
CustomFilters.prototype.isHideValue = function(val){
var res = false;
var filterRes1 = this.CustomFilters[0] ? this.CustomFilters[0].isHideValue(val) : true;
var filterRes2 = this.CustomFilters[1] ? this.CustomFilters[1].isHideValue(val) : true;
return this.And ? (filterRes1 && filterRes2) : (filterRes1 || filterRes2);
};
/** @constructor */
function CustomFilter() {
this.Operator = null;
this.Val = null;
function CustomFilter(operator, val) {
this.Operator = operator != undefined ? operator : null;
this.Val = val != undefined ? val : null;
}
CustomFilter.prototype.clone = function() {
var res = new CustomFilter();
......@@ -4540,6 +4655,123 @@ CustomFilter.prototype.clone = function() {
res.Val = this.Val;
return res;
};
CustomFilter.prototype.create = function(operator, val) {
this.Operator = operator;
this.Val = val;
};
CustomFilter.prototype.isHideValue = function(val) {
var result = false;
var checkComplexSymbols = null;
var filterVal;
if(checkComplexSymbols != null)
result = checkComplexSymbols;
else
{
if(this.Operator == c_oAscCustomAutoFilter.equals || this.Operator == c_oAscCustomAutoFilter.doesNotEqual)//общие для числа и текста
{
if (this.Operator == c_oAscCustomAutoFilter.equals)//equals
{
if(val == this.Val/* || valWithFormat == this.Val*/)
result = true;
}
else if (this.Operator == c_oAscCustomAutoFilter.doesNotEqual)//doesNotEqual
{
if(val != this.Val/* || valWithFormat != this.Val*/)
result = true;
}
}
else if(this.Operator == c_oAscCustomAutoFilter.isGreaterThan ||this.Operator == c_oAscCustomAutoFilter.isGreaterThanOrEqualTo || this.Operator == c_oAscCustomAutoFilter.isLessThan || this.Operator == c_oAscCustomAutoFilter.isLessThanOrEqualTo)//только для чисел
{
filterVal = parseFloat(this.Val);
val = parseFloat(val);
if(isNaN(filterVal))
filterVal = '';
switch (this.Operator)
{
case c_oAscCustomAutoFilter.isGreaterThan:
if(val > filterVal)//isGreaterThan
result = true;
break;
case c_oAscCustomAutoFilter.isGreaterThanOrEqualTo:
if(val >= filterVal)//isGreaterThanOrEqualTo
result = true;
break;
case c_oAscCustomAutoFilter.isLessThan:
if(val < filterVal)//isLessThan
result = true;
break;
case c_oAscCustomAutoFilter.isLessThanOrEqualTo:
if(val <= filterVal)//isLessThanOrEqualTo
result = true;
break;
}
}
else if(this.Operator == c_oAscCustomAutoFilter.beginsWith || this.Operator == c_oAscCustomAutoFilter.doesNotBeginWith || this.Operator == c_oAscCustomAutoFilter.endsWith || this.Operator == c_oAscCustomAutoFilter.doesNotEndWith || this.Operator == c_oAscCustomAutoFilter.contains || this.Operator == c_oAscCustomAutoFilter.doesNotContain)//только для текста
{
filterVal = this.Val;
switch (this.Operator)
{
case c_oAscCustomAutoFilter.beginsWith:
if(type == 1)
{
if(val.search(filterVal) == 0)//beginsWith
result = true;
}
break;
case c_oAscCustomAutoFilter.doesNotBeginWith:
if(type == 1)
{
if(val.search(filterVal) != 0)//doesNotBeginWith
result = true;
}
else
result = true;
break;
case c_oAscCustomAutoFilter.endsWith:
position = val.length - filterVal.length;
if(type == 1)
{
if(val.lastIndexOf(filterVal) == position && position > 0)//endsWith
result = true;
}
break;
case c_oAscCustomAutoFilter.doesNotEndWith:
position = val.length - filterVal.length;
if(type == 1)
{
if(val.lastIndexOf(filterVal) != position && position > 0)//doesNotEndWith
result = true;
}
else
result = true;
break;
case c_oAscCustomAutoFilter.contains:
if(type == 1)
{
if(val.search(filterVal) != -1)//contains
result = true;
}
break;
case c_oAscCustomAutoFilter.doesNotContain:
if(type == 1)
{
if(val.search(filterVal) == -1)//doesNotContain
result = true;
}
else
result = true;
break
}
}
}
return !result;
};
/** @constructor */
function DynamicFilter() {
this.Type = null;
......@@ -4598,25 +4830,16 @@ SortCondition.prototype.clone = function() {
return res;
};
function Result() {
this.x = null;
this.y = null;
this.width = null;
this.height = null;
this.id = null;
this.idNext = null;
this.hiddenRows = null;
}
Result.prototype.clone = function() {
var res = new Result();
res.x = this.x;
res.y = this.y;
res.width = this.width;
res.height = this.height;
res.id = this.id;
res.idNext = this.idNext;
res.hiddenRows = this.hiddenRows;
res.showButton = this.showButton;
function dateElem(start, end, dateTimeGrouping) {
this.start = start;
this.end = end;
this.dateTimeGrouping = dateTimeGrouping;
}
dateElem.prototype.clone = function() {
var res = new dateElem();
res.start = this.start;
this.end = this.end;
this.dateTimeGrouping = this.dateTimeGrouping;
return res;
};
This diff is collapsed.
......@@ -5845,10 +5845,6 @@
var xWithOffset = x + offsetX;
var yWithOffset = y + offsetY;
var autoFilterInfo = this.autoFilters.checkCursor(x, y, offsetX, offsetY, {cFrozen: cFrozen, rFrozen: rFrozen});
if (autoFilterInfo && !isViewerMode)
return {cursor: kCurAutoFilter, target: c_oTargetType.FilterObject, col: -1, row: -1, idFilter: autoFilterInfo.id};
isSelGraphicObject = this.objectRender.selectedGraphicObjectsExists();
if (!isViewerMode && !isSelGraphicObject) {
// Эпсилон для fillHandle
......@@ -5957,7 +5953,11 @@
}
}
}
var autoFilterInfo = this.autoFilters.checkCursor(x, y, offsetX, offsetY, {cFrozen: cFrozen, rFrozen: rFrozen}, r, c);
if (autoFilterInfo && !isViewerMode)
return {cursor: kCurAutoFilter, target: c_oTargetType.FilterObject, col: -1, row: -1, idFilter: autoFilterInfo.id};
// Проверим есть ли комменты
var comments = this.cellCommentator.asc_getComments(c.col, r.row);
var coords = undefined;
......@@ -6557,6 +6557,7 @@
var checkApplyFilterOrSort;
var tablePartsOptions = this.autoFilters.searchRangeInTableParts(activeCell);
cell_info.tableStyleName = tablePartsOptions !== -1 && tablePartsOptions !== -2 && this.model.TableParts && this.model.TableParts[tablePartsOptions].TableStyleInfo ? this.model.TableParts[tablePartsOptions].TableStyleInfo.Name : null;
cell_info.isFormatTable = (-1 !== tablePartsOptions);
if (-2 === tablePartsOptions) {
cell_info.isAutoFilter = null;
......@@ -8250,9 +8251,9 @@
range = t.model.getRange3(aFilters[aF].range.r1 + selectionRange.r1, aFilters[aF].range.c1 + selectionRange.c1, aFilters[aF].range.r2 + selectionRange.r1, aFilters[aF].range.c2 + selectionRange.c1);
if(aFilters[aF].style)
range.cleanFormat();
t.autoFilters.addAutoFilter(aFilters[aF].style, range.bbox, null, null, true);
t.autoFilters.addAutoFilter(aFilters[aF].style, range.bbox, true);
if(!aFilters[aF].autoFilter)
t.autoFilters.addAutoFilter(null, range.bbox, null, null, true);
t.autoFilters.addAutoFilter(null, range.bbox, true);
}
}
else if(isLocal === 'binary' && val.TableParts && val.TableParts.length)
......@@ -8277,7 +8278,7 @@
if(!aFilters[aF].AutoFilter)
bWithoutFilter = true;
t.autoFilters.addAutoFilter(aFilters[aF].TableStyleInfo.Name, range.bbox, null, null, true, bWithoutFilter);
t.autoFilters.addAutoFilter(aFilters[aF].TableStyleInfo.Name, range.bbox, true);
}
}
......@@ -10791,7 +10792,7 @@
this.arrActiveFormulaRanges = [];
};
WorksheetView.prototype.addAutoFilter = function (lTable, addFormatTableOptionsObj) {
WorksheetView.prototype.addAutoFilter = function (lTable, addFormatTableOptionsObj, isApplyAutoFilter, isApplyFormatTable) {
// Проверка глобального лока
if (this.collaborativeEditing.getGlobalLock())
return;
......@@ -10804,10 +10805,27 @@
t.handlers.trigger("selectionChanged", t.getSelectionInfo());
return;
}
t.autoFilters.addAutoFilter(lTable, ar, undefined, false, addFormatTableOptionsObj);
//TODO брать info из меню
var info = t._getSelectionInfoCell();
isApplyAutoFilter = info.isAutoFilter;
isApplyFormatTable = info.tableStyleName;
if(!lTable && isApplyAutoFilter)//delete filter in AutoFilter or TablePart
t.autoFilters.deleteAutoFilter(ar);
else if(!lTable && !isApplyAutoFilter)//add autoFilter
t.autoFilters.addAutoFilter(lTable, ar);
else if(lTable && !isApplyFormatTable && !isApplyAutoFilter)//add TablePart
t.autoFilters.addAutoFilter(lTable, ar, addFormatTableOptionsObj);
else if(lTable && isApplyFormatTable)//change TablePart
t.autoFilters.changeTableStyleInfo(lTable, ar);
else if(lTable && !isApplyFormatTable && isApplyAutoFilter)//change AutoFilter to TablePart
t.autoFilters.changeAutoFilterToTablePart(lTable, ar, addFormatTableOptionsObj);
};
this._isLockedAll(onChangeAutoFilterCallback);
if(t.autoFilters.checkAddAutoFilter(ar, lTable) === true)
this._isLockedAll (onChangeAutoFilterCallback);
};
WorksheetView.prototype.applyAutoFilter = function (type, autoFilterObject) {
......@@ -10817,7 +10835,7 @@
if (false === isSuccess)
return;
t.autoFilters.applyAutoFilter(type, autoFilterObject, ar);
t.autoFilters.applyAutoFilter(autoFilterObject, ar);
};
this._isLockedAll(onChangeAutoFilterCallback);
};
......
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