Commit 6550cfe4 authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

SerializeHistory, DeserializeHistory изменен формат пересылаемых изменений,...

SerializeHistory, DeserializeHistory изменен формат пересылаемых изменений, улучшение для одного человека.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56838 954022d7-b5bf-4e40-9824-e11837661b57
parent 8dc39a3e
...@@ -1328,7 +1328,10 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS"; ...@@ -1328,7 +1328,10 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
_loadFonts: function (fonts, callback) { _loadFonts: function (fonts, callback) {
if (window["NATIVE_EDITOR_ENJINE"]) if (window["NATIVE_EDITOR_ENJINE"])
return callback(); return callback();
var aFonts = [];
for (var i in fonts)
aFonts.push(i);
History.Add(g_oUndoRedoWorkbook, historyitem_Workbook_AddFont, null, null, new UndoRedoData_SingleProperty(aFonts), true);
this.asyncMethodCallback = callback; this.asyncMethodCallback = callback;
var arrLoadFonts = []; var arrLoadFonts = [];
for(var i in fonts) for(var i in fonts)
......
...@@ -7,6 +7,8 @@ var historyitem_Workbook_SheetRemove = 2; ...@@ -7,6 +7,8 @@ var historyitem_Workbook_SheetRemove = 2;
var historyitem_Workbook_SheetMove = 3; var historyitem_Workbook_SheetMove = 3;
var historyitem_Workbook_SheetPositions = 4; var historyitem_Workbook_SheetPositions = 4;
var historyitem_Workbook_ChangeColorScheme = 5; var historyitem_Workbook_ChangeColorScheme = 5;
var historyitem_Workbook_AddFont = 6;
var historyitem_Workbook_AddFont2 = 7;
var historyitem_Worksheet_RemoveCell = 1; var historyitem_Worksheet_RemoveCell = 1;
var historyitem_Worksheet_RemoveRows = 2; var historyitem_Worksheet_RemoveRows = 2;
...@@ -929,25 +931,21 @@ CHistory.prototype = ...@@ -929,25 +931,21 @@ CHistory.prototype =
}, },
GetSerializeArray : function() GetSerializeArray : function()
{ {
var aRes = []; var aRes = [];
for(var i = 0; i <= this.Index; ++i) this._checkCurPoint();
var i = 0;
if (null != this.SavedIndex)
i = this.SavedIndex + 1;
for(; i <= this.Index; ++i)
{ {
var point = this.Points[i]; var point = this.Points[i];
var aPointChanges = [];
for(var j = 0, length2 = point.Items.length; j < length2; ++j) for(var j = 0, length2 = point.Items.length; j < length2; ++j)
{ {
var elem = point.Items[j]; var elem = point.Items[j];
if(true != elem.LocalChange) aPointChanges.push(new UndoRedoItemSerializable(elem.Class, elem.Type, elem.SheetId, elem.Range, elem.Data, elem.LocalChange));
aRes.push(new UndoRedoItemSerializable(elem.Class, elem.Type, elem.SheetId, elem.Range, elem.Data));
}
}
if(null != this.CurPoint)
{
for(var j = 0, length2 = this.CurPoint.Items.length; j < length2; ++j)
{
var elem = this.CurPoint.Items[j];
if(true != elem.LocalChange)
aRes.push(new UndoRedoItemSerializable(elem.Class, elem.Type, elem.SheetId, elem.Range, elem.Data));
} }
aRes.push(aPointChanges);
} }
return aRes; return aRes;
}, },
......
...@@ -22,13 +22,14 @@ function DrawingCollaborativeData() ...@@ -22,13 +22,14 @@ function DrawingCollaborativeData()
this.isDrawingCollaborativeData = true; this.isDrawingCollaborativeData = true;
} }
//главный обьект для пересылки изменений //главный обьект для пересылки изменений
function UndoRedoItemSerializable(oClass, nActionType, nSheetId, oRange, oData) function UndoRedoItemSerializable(oClass, nActionType, nSheetId, oRange, oData, LocalChange)
{ {
this.oClass = oClass; this.oClass = oClass;
this.nActionType = nActionType; this.nActionType = nActionType;
this.nSheetId = nSheetId; this.nSheetId = nSheetId;
this.oRange = oRange; this.oRange = oRange;
this.oData = oData; this.oData = oData;
this.LocalChange = LocalChange;
} }
UndoRedoItemSerializable.prototype = { UndoRedoItemSerializable.prototype = {
Serialize : function(oBinaryWriter, collaborativeEditing) Serialize : function(oBinaryWriter, collaborativeEditing)
......
...@@ -1663,6 +1663,16 @@ Workbook.prototype.recalcDependency = function(f,bad,notRecalc){ ...@@ -1663,6 +1663,16 @@ Workbook.prototype.recalcDependency = function(f,bad,notRecalc){
return sr; return sr;
} }
}; };
Workbook.prototype._SerializeHistoryBase64 = function (oMemory, item, aPointChangesBase64) {
if (!item.LocalChange) {
var nPosStart = oMemory.GetCurPosition();
item.Serialize(oMemory, this.oApi.collaborativeEditing);
var nPosEnd = oMemory.GetCurPosition();
var nLen = nPosEnd - nPosStart;
if (nLen > 0)
aPointChangesBase64.push(nLen + ";" + oMemory.GetBase64Memory2(nPosStart, nLen));
}
}
Workbook.prototype.SerializeHistory = function(){ Workbook.prototype.SerializeHistory = function(){
var aRes = []; var aRes = [];
//соединяем изменения, которые были до приема данных с теми, что получились после. //соединяем изменения, которые были до приема данных с теми, что получились после.
...@@ -1677,23 +1687,42 @@ Workbook.prototype.SerializeHistory = function(){ ...@@ -1677,23 +1687,42 @@ Workbook.prototype.SerializeHistory = function(){
{ {
var oMemory = new CMemory(); var oMemory = new CMemory();
var oThis = this; var oThis = this;
//создаем еще один элемент в undo/redo - взаимное расположение Sheet, чтобы не запутываться в add, move событиях var oFontMap = {};
var oSheetPlaceData = []; var bChangeSheetPlace = false;
for(var i = 0, length = this.aWorksheets.length; i < length; ++i) var aPointChangesBase64;
oSheetPlaceData.push(this.aWorksheets[i].getId());
aActions.push(new UndoRedoItemSerializable(g_oUndoRedoWorkbook, historyitem_Workbook_SheetPositions, null, null, new UndoRedoData_SheetPositions(oSheetPlaceData)));
for(var i = 0, length = aActions.length; i < length; ++i) for(var i = 0, length = aActions.length; i < length; ++i)
{ {
var nPosStart = oMemory.GetCurPosition(); var aPointChanges = aActions[i];
var item = aActions[i]; aPointChangesBase64 = [];
item.Serialize(oMemory, this.oApi.collaborativeEditing); for (var j = 0, length2 = aPointChanges.length; j < length2; ++j) {
var nPosEnd = oMemory.GetCurPosition(); var item = aPointChanges[j];
var nLen = nPosEnd - nPosStart; if (g_oUndoRedoWorkbook == item.oClass) {
if(nLen > 0) if (historyitem_Workbook_AddFont == item.nActionType) {
aRes.push(nLen + ";" + oMemory.GetBase64Memory2(nPosStart, nLen)); for (var k = 0, length3 = item.oData.elem.length; k < length3; ++k)
} oFontMap[item.oData.elem[k]] = 1;
//добавляем элемент, который содержит все используемые шрифты, чтобы их можно было загрузить в начале }
aRes.push("0;fontmap" + this.generateFontMap().join(",")); else if (historyitem_Workbook_SheetAdd == item.nActionType || historyitem_Workbook_SheetRemove == item.nActionType || historyitem_Workbook_SheetMove == item.nActionType)
bChangeSheetPlace = true;
}
this._SerializeHistoryBase64(oMemory, item, aPointChangesBase64);
}
aRes.push(aPointChangesBase64);
}
aPointChangesBase64 = [];
var aFonts = [];
for (var i in oFontMap)
aFonts.push(i);
if (aFonts.length > 0)
this._SerializeHistoryBase64(oMemory, new UndoRedoItemSerializable(g_oUndoRedoWorkbook, historyitem_Workbook_AddFont2, null, null, new UndoRedoData_SingleProperty(aFonts)), aPointChangesBase64);
if (bChangeSheetPlace) {
//создаем еще один элемент в undo/redo - взаимное расположение Sheet, чтобы не запутываться в add, move событиях
var oSheetPlaceData = [];
for (var i = 0, length = this.aWorksheets.length; i < length; ++i)
oSheetPlaceData.push(this.aWorksheets[i].getId());
this._SerializeHistoryBase64(oMemory, new UndoRedoItemSerializable(g_oUndoRedoWorkbook, historyitem_Workbook_SheetPositions, null, null, new UndoRedoData_SheetPositions(oSheetPlaceData)), aPointChangesBase64);
}
if (aPointChangesBase64.length > 0)
aRes.push(aPointChangesBase64);
this.aCollaborativeActions = []; this.aCollaborativeActions = [];
} }
return aRes; return aRes;
...@@ -1710,14 +1739,18 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){ ...@@ -1710,14 +1739,18 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
var aIndexes = []; var aIndexes = [];
for(var i = 0, length = aChanges.length;i < length; ++i) for(var i = 0, length = aChanges.length;i < length; ++i)
{ {
var sChange = aChanges[i]; var aPointChanges = aChanges[i];
var nIndex = sChange.indexOf(";"); var aIndexesPoint = [];
if(-1 != nIndex) for (var j = 0, length2 = aPointChanges.length; j < length2; ++j) {
{ var sChange = aPointChanges[j];
dstLen += parseInt(sChange.substring(0, nIndex)); var nIndex = sChange.indexOf(";");
nIndex++; if (-1 != nIndex) {
} dstLen += parseInt(sChange.substring(0, nIndex));
aIndexes.push(nIndex); nIndex++;
}
aIndexesPoint.push(nIndex);
}
aIndexes.push(aIndexesPoint);
} }
var pointer = g_memory.Alloc(dstLen); var pointer = g_memory.Alloc(dstLen);
var stream = new FT_Stream2(pointer.data, dstLen); var stream = new FT_Stream2(pointer.data, dstLen);
...@@ -1725,19 +1758,23 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){ ...@@ -1725,19 +1758,23 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
var nCurOffset = 0; var nCurOffset = 0;
//пробегаемся первый раз чтобы заполнить oFontMap //пробегаемся первый раз чтобы заполнить oFontMap
var oFontMap = {};//собираем все шрифтры со всех изменений var oFontMap = {};//собираем все шрифтры со всех изменений
var sFontMapString = "0;fontmap"; var aUndoRedoElems = [];
for(var i = 0, length = aChanges.length; i < length; ++i) for (var i = 0, length = aChanges.length; i < length; ++i) {
{ var aPointChanges = aChanges[i];
var sChange = aChanges[i]; var aIndexesPoint = aIndexes[i];
if(sFontMapString == sChange.substring(0, sFontMapString.length)) for (var j = 0, length2 = aPointChanges.length; j < length2; ++j) {
{ var sChange = aPointChanges[j];
var sFonts = sChange.substring(sFontMapString.length); var oBinaryFileReader = new Asc.BinaryFileReader();
var aFonts = sFonts.split(","); nCurOffset = oBinaryFileReader.getbase64DecodedData2(sChange, aIndexesPoint[j], stream, nCurOffset);
for(var j = 0, length2 = aFonts.length; j < length2; ++j) var item = new UndoRedoItemSerializable();
oFontMap[aFonts[j]] = 1; item.Deserialize(stream);
} if (g_oUndoRedoWorkbook == item.oClass && historyitem_Workbook_AddFont2 == item.nActionType) {
for (var k = 0, length3 = item.oData.elem.length; k < length3; ++k)
oFontMap[item.oData.elem[k]] = 1;
}
aUndoRedoElems.push(item);
}
} }
window["Asc"]["editor"]._loadFonts(oFontMap, function(){ window["Asc"]["editor"]._loadFonts(oFontMap, function(){
History.Clear(); History.Clear();
History.Create_NewPoint(); History.Create_NewPoint();
...@@ -1746,27 +1783,18 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){ ...@@ -1746,27 +1783,18 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
var oHistoryPositions = null;//нужен самый последний historyitem_Workbook_SheetPositions var oHistoryPositions = null;//нужен самый последний historyitem_Workbook_SheetPositions
var oRedoObjectParam = new Asc.RedoObjectParam(); var oRedoObjectParam = new Asc.RedoObjectParam();
History.UndoRedoPrepare(oRedoObjectParam, false); History.UndoRedoPrepare(oRedoObjectParam, false);
for(var i = 0, length = aChanges.length; i < length; ++i) for (var i = 0, length = aUndoRedoElems.length; i < length; ++i)
{ {
var sChange = aChanges[i]; var item = aUndoRedoElems[i];
if(sFontMapString != sChange.substring(0, sFontMapString.length)) if (null != item.oClass && null != item.nActionType) {
{ if (g_oUndoRedoWorkbook == item.oClass && historyitem_Workbook_SheetPositions == item.nActionType)
var oBinaryFileReader = new Asc.BinaryFileReader(); oHistoryPositions = item;
nCurOffset = oBinaryFileReader.getbase64DecodedData2(sChange, aIndexes[i], stream, nCurOffset); else {
var item = new UndoRedoItemSerializable(); // TODO if(g_oUndoRedoGraphicObjects == item.oClass && item.oData.drawingData)
item.Deserialize(stream); // item.oData.drawingData.bCollaborativeChanges = true;
if(null != item.oClass && null != item.nActionType) History.RedoAdd(oRedoObjectParam, item.oClass, item.nActionType, item.nSheetId, item.oRange, item.oData);
{ }
if(g_oUndoRedoWorkbook == item.oClass && historyitem_Workbook_SheetPositions == item.nActionType) }
oHistoryPositions = item;
else
{
// TODO if(g_oUndoRedoGraphicObjects == item.oClass && item.oData.drawingData)
// item.oData.drawingData.bCollaborativeChanges = true;
History.RedoAdd(oRedoObjectParam, item.oClass, item.nActionType, item.nSheetId, item.oRange, item.oData);
}
}
}
} }
if(null != oHistoryPositions) if(null != oHistoryPositions)
History.RedoAdd(oRedoObjectParam, oHistoryPositions.oClass, oHistoryPositions.nActionType, oHistoryPositions.nSheetId, oHistoryPositions.oRange, oHistoryPositions.oData); History.RedoAdd(oRedoObjectParam, oHistoryPositions.oClass, oHistoryPositions.nActionType, oHistoryPositions.nSheetId, oHistoryPositions.oRange, oHistoryPositions.oData);
......
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