Skip to content

Commit

Permalink
Merge pull request 'feature/refresh-file' (#366) from feature/refresh…
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Nov 29, 2024
2 parents 5e8f285 + 70b4ca4 commit 395bcf8
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 72 deletions.
29 changes: 27 additions & 2 deletions cell/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var editor;

this.asyncMethodCallback = undefined;

this.IsInitControl = false;//single canvas creation
// Переменная отвечает, загрузились ли фонты
this.FontLoadWaitComplete = false;
//текущий обьект куда записываются информация для update, когда принимаются изменения в native редакторе
Expand Down Expand Up @@ -1739,6 +1740,7 @@ var editor;
this.openingEnd = {bin: false, xlsxStart: false, xlsx: false, data: null};
this.isApplyChangesOnOpenEnabled = true;
this.isDocumentLoadComplete = false;
this.FontLoadWaitComplete = false;
this.turnOffSpecialModes();

//удаляю весь handlersList, добавленный при инициализации wbView
Expand Down Expand Up @@ -3226,6 +3228,27 @@ var editor;
previousVersionZoom = this.wb && this.wb.getZoom();
}

if (!this.IsInitControl) {
// todo Create HtmlPage like other editors
// add style
let _head = document.getElementsByTagName('head')[0];
let style0 = document.createElement('style');
style0.type = 'text/css';
style0.innerHTML = ".block_elem { position:absolute;padding:0;margin:0; }";
_head.appendChild(style0);

this.HtmlElement.innerHTML = '<div id="ws-canvas-outer">\
<canvas id="ws-canvas" style="touch-action:none;-ms-touch-action: none;-webkit-user-select: none;"></canvas>\
<canvas id="ws-canvas-overlay" style="touch-action:none;-ms-touch-action: none;-webkit-user-select: none;"></canvas>\
<canvas id="ws-canvas-graphic" style="touch-action:none;-ms-touch-action: none;-webkit-user-select: none;"></canvas>\
<canvas id="ws-canvas-graphic-overlay" style="touch-action:none;-ms-touch-action: none;-webkit-user-select: none;"></canvas>\
<div id="id_target_cursor" class="block_elem" width="1" height="1"\
style="width:2px;height:13px;display:none;z-index:9;"></div>\
</div>';

this.IsInitControl = true;
}

this.wb = new AscCommonExcel.WorkbookView(this.wbModel, this.controller, this.handlers, this.HtmlElement,
this.topLineEditorElement, this, this.collaborativeEditing, this.fontRenderingMode);

Expand Down Expand Up @@ -3297,13 +3320,15 @@ var editor;
if (previousVersionZoom) {
this.asc_setZoom(previousVersionZoom);
}
this.asc_Resize();
}

if (this.canEdit() && this.asc_getExternalReferences()) {
this.handlers.trigger("asc_onNeedUpdateExternalReferenceOnOpen");
}
//this.asc_Resize(); // Убрал, т.к. сверху приходит resize (http://bugzilla.onlyoffice.com/show_bug.cgi?id=14680)
this.onUpdateDocumentModified(this.isDocumentModified());//line moved from onDocumentContentReady
//раньше вызов был закомментирован, потому при при открытии вызывается в Viewport.js(asc_Resize) и Main.js(asc_showComments)
//но рассчитывать на внешние вызовы ненадежно и вызовов нет при VersionHistory и refreshFile
this.asc_Resize();

this.initBroadcastChannel();
this.initBroadcastChannelListeners();
Expand Down
21 changes: 3 additions & 18 deletions cell/view/WorkbookView.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,26 +345,8 @@
// Изначально мы инициализируем c_oAscFontRenderingModeType.hintingAndSubpixeling
this.setFontRenderingMode(fontRenderingMode, /*isInit*/true);

// add style
var _head = document.getElementsByTagName('head')[0];
var style0 = document.createElement('style');
style0.type = 'text/css';
style0.innerHTML = ".block_elem { position:absolute;padding:0;margin:0; }";
_head.appendChild(style0);

// create canvas
if (null != this.element) {
if (!this.Api.VersionHistory && !this.Api.isEditOleMode) {
this.element.innerHTML = '<div id="ws-canvas-outer">\
<canvas id="ws-canvas" style="touch-action:none;-ms-touch-action: none;-webkit-user-select: none;"></canvas>\
<canvas id="ws-canvas-overlay" style="touch-action:none;-ms-touch-action: none;-webkit-user-select: none;"></canvas>\
<canvas id="ws-canvas-graphic" style="touch-action:none;-ms-touch-action: none;-webkit-user-select: none;"></canvas>\
<canvas id="ws-canvas-graphic-overlay" style="touch-action:none;-ms-touch-action: none;-webkit-user-select: none;"></canvas>\
<div id="id_target_cursor" class="block_elem" width="1" height="1"\
style="width:2px;height:13px;display:none;z-index:9;"></div>\
</div>';
}

this.canvas = document.getElementById("ws-canvas");
this.canvasOverlay = document.getElementById("ws-canvas-overlay");
this.canvasGraphic = document.getElementById("ws-canvas-graphic");
Expand Down Expand Up @@ -5076,6 +5058,9 @@
WorkbookView.prototype.getCursorInfoBinary = function () {

var oWs = this.getActiveWS();
if (!oWs) {
return "";
}
var id = oWs.getId();
var selection = oWs.getSelection();
var isEdit = this.getCellEditMode();
Expand Down
119 changes: 88 additions & 31 deletions common/apiBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@
{
this.sendEvent("asc_onPrint");
};
baseEditorsApi.prototype._getOpenCmd = function(versionHistory)
baseEditorsApi.prototype._getOpenCmd = function()
{
var rData = null;
if (!(this.DocInfo && this.DocInfo.get_OfflineApp()))
Expand Down Expand Up @@ -1093,30 +1093,21 @@
rData["convertToOrigin"] += Asc.c_sNativeViewerFormats;
}

if (versionHistory)
if (this.VersionHistory)
{
rData["serverVersion"] = versionHistory.serverVersion;
rData["closeonerror"] = versionHistory.isRequested;
rData["tokenHistory"] = versionHistory.token;
//чтобы результат пришел только этому соединению, а не всем кто в документе
rData["userconnectionid"] = this.CoAuthoringApi.getUserConnectionId();
rData["serverVersion"] = this.VersionHistory.serverVersion;
}
}
return rData;
}
// Open
baseEditorsApi.prototype.asc_LoadDocument = function(versionHistory, isRepeat)
baseEditorsApi.prototype.asc_LoadDocument = function(isRepeat)
{
// Меняем тип состояния (на открытие)
this.advancedOptionsAction = AscCommon.c_oAscAdvancedOptionsAction.Open;

let rData = this._getOpenCmd(versionHistory);
if (versionHistory) {
this.CoAuthoringApi.versionHistory(rData);
} else {
//todo auth on connection
this.CoAuthoringApi.auth(this.getViewMode(), rData);
}
//todo auth on connection
this.CoAuthoringApi.auth(this.getViewMode(), this._getOpenCmd());

if (!isRepeat) {
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.Open);
Expand Down Expand Up @@ -1227,10 +1218,6 @@
if (window.g_asc_plugins)
window.g_asc_plugins.onPluginEvent("onDocumentContentReady");

if (c_oEditorId.Spreadsheet === this.editorId) {
this.onUpdateDocumentModified(this.isDocumentModified());
}

if (this.DocInfo)
this["pluginMethod_SetProperties"](this.DocInfo.asc_getOptions());

Expand Down Expand Up @@ -1671,7 +1658,7 @@
t.CoAuthoringApi.auth(t.getViewMode(), undefined, t.isIdle());
} else {
//первый запрос или ответ не дошел надо повторить открытие
t.asc_LoadDocument(undefined, true);
t.asc_LoadDocument(true);
}
}
};
Expand Down Expand Up @@ -1839,6 +1826,9 @@
*/
this.CoAuthoringApi.onDisconnect = function(e, opt_closeCode)
{
if (AscCommon.c_oCloseCode.quiet === opt_closeCode) {
return;
}
if (AscCommon.ConnectionState.None === t.CoAuthoringApi.get_state())
{
t.asyncServerIdEndLoaded();
Expand All @@ -1850,13 +1840,18 @@
t.asc_setRestriction(t.disconnectRestrictions);
t.disconnectRestrictions = null;
}
var error = AscCommon.getDisconnectErrorCode(t.isDocumentLoadComplete, opt_closeCode);
var level = t.isDocumentLoadComplete ? Asc.c_oAscError.Level.NoCritical : Asc.c_oAscError.Level.Critical;
t.setViewModeDisconnect(AscCommon.getEnableDownloadByCloseCode(opt_closeCode));
if (Asc.c_oAscError.ID.UpdateVersion === error && !t.isDocumentModified()) {
t.sendEvent("asc_onDocumentUpdateVersion", function() {});
let allowRefresh = [c_oCloseCode.updateVersion, c_oCloseCode.noCache, c_oCloseCode.restore, c_oCloseCode.quiet];
if (-1 !== allowRefresh.indexOf(opt_closeCode) && !t.isDocumentModified() && t.canRefreshFile()) {
t.onRefreshFile();
} else {
t.sendEvent('asc_onError', error, level);
var error = AscCommon.getDisconnectErrorCode(t.isDocumentLoadComplete, opt_closeCode);
var level = t.isDocumentLoadComplete ? Asc.c_oAscError.Level.NoCritical : Asc.c_oAscError.Level.Critical;
t.setViewModeDisconnect(AscCommon.getEnableDownloadByCloseCode(opt_closeCode));
if (Asc.c_oAscError.ID.UpdateVersion === error && !t.isDocumentModified()) {
t.sendEvent("asc_onDocumentUpdateVersion", function() {});
} else {
t.sendEvent('asc_onError', error, level);
}
}
} else if (null === t.disconnectRestrictions){
t.disconnectRestrictions = t.restrictions;
Expand Down Expand Up @@ -1908,13 +1903,16 @@
if (null != documentUrl) {
if ('ok' === input["status"] || t.getViewMode()) {
t._onOpenCommand(documentUrl);
} else if (t.canRefreshFile()) {
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.Open);
t.onRefreshFile();
} else {
t.sendEvent("asc_onDocumentUpdateVersion", function () {
if (t.isCoAuthoringEnable) {
t.asc_coAuthoringDisconnect();
}
t._onOpenCommand(documentUrl);
})
});
}
} else {
t.sendEvent("asc_onError", c_oAscError.ID.ConvertationOpenError,
Expand Down Expand Up @@ -2669,12 +2667,17 @@
if (bUpdate) {
this.asc_CloseFile();

this.DocInfo.put_Id(this.VersionHistory.docId);
this.DocInfo.put_Url(this.VersionHistory.url);
this.documentUrlChanges = this.VersionHistory.urlChanges;
this.documentTokenChanges = this.VersionHistory.token;
this.asc_setDocInfo(this.DocInfo);
this.asc_LoadDocument(this.VersionHistory);

let newDocInfo = this.DocInfo.clone();
newDocInfo.put_Id(this.VersionHistory.docId);
newDocInfo.put_Url(this.VersionHistory.url);
newDocInfo.put_Mode('view');
newDocInfo.put_CoEditingMode('strict');
newDocInfo.put_Token(this.VersionHistory.token);

this.reopenFileWithReconnection(newDocInfo);
} else if (this.VersionHistory.currentChangeId < newObj.currentChangeId) {
var oApi = Asc.editor || editor;
this.isApplyChangesOnVersionHistory = true;
Expand All @@ -2689,6 +2692,59 @@
{
return this.VersionHistory;
};
baseEditorsApi.prototype.asc_refreshFile = function(docInfo) {
this.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.RefreshFile);
//todo always call asc_CloseFile ?
let isInfinityLoop = this.documentIsWopi
? docInfo.get_Wopi()["Version"] === this.DocInfo.get_Wopi()["Version"]
&& docInfo.get_Wopi()["LastModifiedTime"] === this.DocInfo.get_Wopi()["LastModifiedTime"]
: docInfo.get_Id() === this.DocInfo.get_Id();
if (this.isDocumentLoadComplete) {
this.asc_CloseFile();
} else if (isInfinityLoop) {
//loop protection (need backoff and retry?)
//todo unique error
this.sendEvent("asc_onDocumentUpdateVersion", function() {});
// this.sendEvent('asc_onError', Asc.c_oAscError.ID.UpdateVersion, Asc.c_oAscError.Level.Critical);
return;
}
this.reopenFileWithReconnection(docInfo);
};
baseEditorsApi.prototype.canRefreshFile = function () {
return this.documentIsWopi || this.asc_checkNeedCallback('asc_onRequestRefreshFile');
}
baseEditorsApi.prototype.onRefreshFile = function () {
let t = this;
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.RefreshFile);
if (this.documentIsWopi) {
let callback = function (isTimeout, response) {
if (response) {
//todo event to simulate 'refreshFile' integrator method
let newDocInfo = t.DocInfo.extendWithWopiParams(response);
//send rename event
t.CoAuthoringApi.onMeta({'title': newDocInfo.get_Title()});
t.asc_refreshFile(newDocInfo);
} else {
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
};
if (!this.CoAuthoringApi.callPRC({'type': 'wopi_RefreshFile', 'name': name}, Asc.c_nCommonRequestTime, callback)) {
callback(false, undefined);
}
} else {
this.sendEvent("asc_onRequestRefreshFile");
}
}
baseEditorsApi.prototype.reopenFileWithReconnection = function(docInfo) {
this.asc_setDocInfo(docInfo);

this.isOnLoadLicense = false;
this.ServerIdWaitComplete = false;
this.CoAuthoringApi.disconnect(AscCommon.c_oCloseCode.quiet);
//create new connection because new docId can be on different shard
this.CoAuthoringApi = new AscCommon.CDocsCoApi();
this._coAuthoringInit();
};
baseEditorsApi.prototype.asc_undoAllChanges = function()
{
};
Expand Down Expand Up @@ -5253,6 +5309,7 @@
prot['asc_selectSearchingResults'] = prot.asc_selectSearchingResults;
prot['asc_isSelectSearchingResults'] = prot.asc_isSelectSearchingResults;
prot['asc_showRevision'] = prot.asc_showRevision;
prot['asc_refreshFile'] = prot.asc_refreshFile;
prot['asc_getAdvancedOptions'] = prot.asc_getAdvancedOptions;
prot['asc_Print'] = prot.asc_Print;
prot['asc_GetCurrentColorSchemeName'] = prot.asc_GetCurrentColorSchemeName;
Expand Down
Loading

0 comments on commit 395bcf8

Please sign in to comment.