Commit 625a0904 authored by konovalovsergey's avatar konovalovsergey

apply changes to input formulas before sending changes

parent 784cbd15
......@@ -3726,12 +3726,12 @@ function parserFormula( formula, parent, _ws ) {
if (!this.isDirty) {
this.isDirty = true;
if (this.parent && this.parent.onFormulaEvent) {
this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.Change);
this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.Change, eventData);
}
}
} else if (AscCommon.c_oNotifyType.Changed === data.type) {
if (this.parent && this.parent.onFormulaEvent) {
this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.Change);
this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.Change, eventData);
}
} else {
var assembleType = AscCommon.c_oNotifyParentAssemble.Normal;
......
......@@ -169,6 +169,7 @@ function CHistory()
// Параметры для специального сохранения для локальной версии редактора
this.UserSaveMode = false;
this.UserSavedIndex = null; // Номер точки, на которой произошло последнее сохранение пользователем (не автосохранение)
this.changesFormula = {};
}
CHistory.prototype.init = function(workbook) {
this.workbook = workbook;
......@@ -904,6 +905,37 @@ CHistory.prototype._CheckCanNotAddChanges = function () {
} catch (e) {
}
};
CHistory.prototype.changesFormulaAdd = function(formula) {
this.changesFormula[formula.getListenerId()] = formula;
};
CHistory.prototype.changesFormulaBuildDep = function() {
for (var listenerId in this.changesFormula) {
this.changesFormula[listenerId].buildDependencies();
}
};
CHistory.prototype.changesFormulaRemoveDep = function() {
for (var listenerId in this.changesFormula) {
this.changesFormula[listenerId].removeDependencies();
}
this.changesFormula = {};
};
CHistory.prototype.onFormulaEvent = function(type, eventData) {
if (AscCommon.c_oNotifyParentType.CanDo === type) {
return true;
} else if (AscCommon.c_oNotifyParentType.Change === type) {
eventData.formula.setIsDirty(false);
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
if (eventData.isRebuild) {
delete this.changesFormula[eventData.formula.getListenerId()];
eventData.formula = new AscCommonExcel.parserFormula(eventData.assemble, this, eventData.formula.ws);
eventData.formula.parse();
this.addFormula(eventData.formula);
} else {
eventData.formula.Formula = eventData.assemble;
}
eventData.formula.buildDependencies();
}
};
//------------------------------------------------------------export--------------------------------------------------
window['AscCommon'] = window['AscCommon'] || {};
......
......@@ -555,7 +555,12 @@ UndoRedoData_CellSimpleData.prototype = {
{
case this.Properties.Row: return this.nRow;break;
case this.Properties.Col: return this.nCol;break;
case this.Properties.NewVal: return this.oNewVal;break;
case this.Properties.NewVal:
if (this.oNewVal && this.sFormula) {
this.oNewVal.formula = this.sFormula.assemble(true);
}
return this.oNewVal;
break;
}
return null;
},
......@@ -1692,10 +1697,11 @@ var g_oUndoRedoData_DefinedNamesChangeProperties = {
oldName: 0,
newName:1
};
function UndoRedoData_DefinedNamesChange(oldName, newName){
function UndoRedoData_DefinedNamesChange(oldName, newName, formula){
this.Properties = g_oUndoRedoData_DefinedNamesChangeProperties;
this.oldName = oldName?new UndoRedoData_DefinedNames(oldName.Name, oldName.Ref, oldName.LocalSheetId, oldName.isTable, null):undefined;
this.newName = newName?new UndoRedoData_DefinedNames(newName.Name, newName.Ref, newName.LocalSheetId, newName.isTable, null):undefined;
this.formula = formula;
}
UndoRedoData_DefinedNamesChange.prototype = {
getType : function()
......@@ -1711,7 +1717,12 @@ UndoRedoData_DefinedNamesChange.prototype = {
switch(nType)
{
case this.Properties.oldName: return this.oldName;break;
case this.Properties.newName: return this.newName;break;
case this.Properties.newName:
if (this.newName && this.formula) {
this.newName.Ref = this.formula.assemble(true);
}
return this.newName;
break;
}
return null;
},
......
......@@ -153,7 +153,7 @@ function getRangeType(oBBox){
function getDefNameIndex(name) {
//можно создавать имена в разном регистре, но уникальность проверяется независимо от регистра
return name.toLowerCase();
return name ? name.toLowerCase() : name;
}
function getDefNameId(sheetId, name) {
......@@ -572,7 +572,7 @@ function getRangeType(oBBox){
if (oldAscName) {
res = this.getDefNameByName(oldAscName.Name, this.wb.getSheetIdByIndex(oldAscName.LocalSheetId));
} else {
res = this.addDefNameOpen(newAscName.Name, newAscName.Ref, newAscName.LocalSheetId, newAscName.Hidden,
res = this.addDefName(newAscName.Name, newAscName.Ref, newAscName.LocalSheetId, newAscName.Hidden,
false);
}
History.Create_NewPoint();
......@@ -592,8 +592,19 @@ function getRangeType(oBBox){
res.setAscCDefName(newAscName);
}
}
if(History.Is_On()){
var changesFormula = null;
if (!oldAscName) {
if (newAscName.Ref) {
changesFormula = new parserFormula(newAscName.Ref, History, AscCommonExcel.g_DefNameWorksheet);
changesFormula.parse();
History.changesFormulaAdd(changesFormula);
}
}
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_DefinedNamesChange, null, null,
new UndoRedoData_DefinedNamesChange(oldAscName, newAscName));
new UndoRedoData_DefinedNamesChange(oldAscName, newAscName, changesFormula));
}
return res;
},
checkDefName: function (name, sheetIndex) {
......@@ -1757,7 +1768,7 @@ Workbook.prototype._SerializeHistoryBase64 = function (oMemory, item, aPointChan
Workbook.prototype.SerializeHistory = function(){
var aRes = [];
//соединяем изменения, которые были до приема данных с теми, что получились после.
History.changesFormulaRemoveDep();
var worksheets = this.aWorksheets, t, j, length2;
for(t = 0; t < worksheets.length; ++t)
{
......@@ -1802,6 +1813,7 @@ Workbook.prototype.SerializeHistory = function(){
};
Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
var oThis = this;
History.changesFormulaBuildDep();
//сохраняем те изменения, которые были до приема данных, потому что дальше undo/redo будет очищено
this.aCollaborativeActions = this.aCollaborativeActions.concat(History.GetSerializeArray());
if(aChanges.length > 0)
......@@ -4376,9 +4388,14 @@ Cell.prototype.setValue=function(val,callback, isCopyPaste) {
DataNew = this.getValueData();
}
if (History.Is_On() && false == DataOld.isEqual(DataNew)) {
var changesFormula = null;
if (this.formulaParsed) {
changesFormula = this.formulaParsed.clone(null, History, ws);
History.changesFormulaAdd(changesFormula);
}
History.Add(AscCommonExcel.g_oUndoRedoCell, AscCH.historyitem_Cell_ChangeValue, this.ws.getId(),
new Asc.Range(this.nCol, this.nRow, this.nCol, this.nRow),
new UndoRedoData_CellSimpleData(this.nRow, this.nCol, DataOld, DataNew));
new UndoRedoData_CellSimpleData(this.nRow, this.nCol, DataOld, DataNew, changesFormula));
}
//sortDependency вызывается ниже History.Add(AscCH.historyitem_Cell_ChangeValue, потому что в ней может быть выставлен формат ячейки(если это текстовый, то принимая изменения формула станет текстом)
this.ws.workbook.sortDependency();
......@@ -4427,8 +4444,17 @@ Cell.prototype.setValue2=function(array){
if (History.Is_On()) {
DataNew = this.getValueData();
if (false == DataOld.isEqual(DataNew))
History.Add(AscCommonExcel.g_oUndoRedoCell, AscCH.historyitem_Cell_ChangeValue, this.ws.getId(), new Asc.Range(this.nCol, this.nRow, this.nCol, this.nRow), new UndoRedoData_CellSimpleData(this.nRow, this.nCol, DataOld, DataNew));
if (false == DataOld.isEqual(DataNew)) {
var changesFormula = null;
if (this.formulaParsed) {
changesFormula = new parserFormula(formula, History, this.ws);
changesFormula.parse();
History.changesFormulaAdd(changesFormula);
}
History.Add(AscCommonExcel.g_oUndoRedoCell, AscCH.historyitem_Cell_ChangeValue, this.ws.getId(),
new Asc.Range(this.nCol, this.nRow, this.nCol, this.nRow),
new UndoRedoData_CellSimpleData(this.nRow, this.nCol, DataOld, DataNew, changesFormula));
}
}
};
Cell.prototype.removeDependencies = function() {
......
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