From e73edb7d4c7dae975a0a6f34a04a50f2c9d26727 Mon Sep 17 00:00:00 2001 From: Igor Zotov Date: Sat, 21 Jan 2023 16:26:56 +0300 Subject: [PATCH] Fix/reference data (#3246) * [se] Update external references for desktop --- cell/model/WorkbookElems.js | 6 +- cell/view/WorkbookView.js | 122 +++++++++++++++++++++--------------- cell/view/WorksheetView.js | 28 +++++---- 3 files changed, 92 insertions(+), 64 deletions(-) diff --git a/cell/model/WorkbookElems.js b/cell/model/WorkbookElems.js index 066f37436a..661b1b4379 100644 --- a/cell/model/WorkbookElems.js +++ b/cell/model/WorkbookElems.js @@ -13969,11 +13969,11 @@ QueryTableField.prototype.clone = function() { OleSizeSelectionRange.prototype.getFirstFromLocalHistory = function () { return this.localHistory[0].clone(); - } + }; OleSizeSelectionRange.prototype.getLastFromLocalHistory = function () { return this.localHistory[this.localHistory.length - 1].clone(); - } + }; OleSizeSelectionRange.prototype.resetHistory = function () { this.localHistory = []; @@ -13993,7 +13993,7 @@ QueryTableField.prototype.clone = function() { this.ranges = [oRange.clone()]; this.activeCellId = 0; this.activeCell = new AscCommon.CellBase(oRange.r1, oRange.c1); - } + }; OleSizeSelectionRange.prototype.clean = function () { this.ranges = [new Asc.Range(0, 0, 10, 10)]; diff --git a/cell/view/WorkbookView.js b/cell/view/WorkbookView.js index 545c5cce07..3d26b3eb9a 100644 --- a/cell/view/WorkbookView.js +++ b/cell/view/WorkbookView.js @@ -5053,36 +5053,39 @@ this.model.handlers.trigger("asc_onStartUpdateExternalReference", true); + let doPromise = function (data) { + //создаём запросы + var arrAfterPromise = []; + + var aRequests = []; + t._getPromiseRequestsArr(data, aRequests, externalReferences, function (_stream, externalReferenceId, oData) { + arrAfterPromise.push({stream: _stream, externalReferenceId: externalReferenceId, data: oData}); + if (aRequests.length === arrAfterPromise.length) { + doUpdateData(arrAfterPromise); + } + }); + + if (!aRequests.length) { + t.model.handlers.trigger("asc_onStartUpdateExternalReference", false); + return; + } + + var _promise = Promise.resolve(); + for (let i in aRequests) { + _promise = _promise.then(aRequests[i]); + } + }; + if (window["AscDesktopEditor"]) { //TODO для декстопа необходима функция получения файлов + при копипасте нужно записывать путь файла(и знать путь текущего файла, чтобы вычислить относительный) //десктоп //var arrAfterPromise = getFilesContent(externalReferences); //doUpdateData(arrAfterPromise); + doPromise(); } else { //портал //получаем ссылку на файл через asc_onUpdateExternalReference от портала - t._getExternalReferenceData(externalReferences, function (data) { - //создаём запросы - var arrAfterPromise = []; - - var aRequests = []; - t._getPromiseRequestsArr(data, aRequests, externalReferences, function (_stream, externalReferenceId, oData) { - arrAfterPromise.push({stream: _stream, externalReferenceId: externalReferenceId, data: oData}); - if (aRequests.length === arrAfterPromise.length) { - doUpdateData(arrAfterPromise); - } - }); - - if (!aRequests.length) { - t.model.handlers.trigger("asc_onStartUpdateExternalReference", false); - return; - } - - var _promise = Promise.resolve(); - for (let i in aRequests) { - _promise = _promise.then(aRequests[i]); - } - }); + t._getExternalReferenceData(externalReferences, doPromise); } } }; @@ -5106,13 +5109,6 @@ return function () { return new Promise(function (resolve) { - let sFileUrl = oData && !oData["error"] ? oData["url"] : null; - let isExternalLink = eR.isExternalLink(); - - //если ссылка на внешний источник, пробуем получить контент - if (!sFileUrl && oData["error"] && isExternalLink) { - sFileUrl = eR.data; - } let resolveStream = function (stream) { resolve(_resolve(stream, eR.externalReference.Id, oData)); @@ -5131,32 +5127,58 @@ }, "arraybuffer"); }; - //если открыть на клиенте не можем, то запрашиваем бинарник - let isXlsx = eR.externalReference && eR.externalReference.isXlsx(); - let outputFormat = t.Api["asc_isSupportFeature"]("ooxml") ? Asc.c_oAscFileType.XLSX : Asc.c_oAscFileType.XLSY; - let fileType = oData["fileType"]; - let token = oData["token"]; - let directUrl = oData["directUrl"]; - - //если внешняя ссылка, то конвертируем в xlsx - if (sFileUrl && (isExternalLink || !isXlsx) || !t.Api["asc_isSupportFeature"]("ooxml")) { - t.Api._getFileFromUrl(sFileUrl, fileType, token, outputFormat, - function (fileUrlAfterConvert) { - if (fileUrlAfterConvert) { - successfulLoadFileMap[sFileUrl] = 1; - loadFile(fileUrlAfterConvert); - } else if (!successfulLoadFileMap[sFileUrl]) { - resolve(_resolve(null, eR.externalReference.Id, oData)); + + let sFileUrl = window["AscDesktopEditor"] ? eR.externalReference && eR.externalReference.Id : (oData && !oData["error"] ? oData["url"] : null); + let isExternalLink = eR.isExternalLink(); + + if (window["AscDesktopEditor"]) { + //TODO isExternalLink + if (sFileUrl) { + //resolveStream(stream); + window["AscDesktopEditor"]["convertFile"](sFileUrl, 0x2002, function (_file) { + let stream = null; + if (_file) { + stream = _file["get"](/*Editor.bin*/); } - }); - } else { - if (directUrl || sFileUrl) { - t.Api._downloadOriginalFile(directUrl, sFileUrl, fileType, token, function(stream){ resolveStream(stream); }); + } else { resolve(_resolve(null, eR.externalReference.Id, oData)); } + } else { + //если ссылка на внешний источник, пробуем получить контент + if (!sFileUrl && oData["error"] && isExternalLink) { + sFileUrl = eR.data; + } + + //если открыть на клиенте не можем, то запрашиваем бинарник + let isXlsx = eR.externalReference && eR.externalReference.isXlsx(); + let outputFormat = t.Api["asc_isSupportFeature"]("ooxml") ? Asc.c_oAscFileType.XLSX : Asc.c_oAscFileType.XLSY; + let fileType = oData["fileType"]; + let token = oData["token"]; + let directUrl = oData["directUrl"]; + + //если внешняя ссылка, то конвертируем в xlsx + if (sFileUrl && (isExternalLink || !isXlsx) || !t.Api["asc_isSupportFeature"]("ooxml")) { + t.Api._getFileFromUrl(sFileUrl, fileType, token, outputFormat, + function (fileUrlAfterConvert) { + if (fileUrlAfterConvert) { + successfulLoadFileMap[sFileUrl] = 1; + loadFile(fileUrlAfterConvert); + } else if (!successfulLoadFileMap[sFileUrl]) { + resolve(_resolve(null, eR.externalReference.Id, oData)); + } + }); + } else { + if (directUrl || sFileUrl) { + t.Api._downloadOriginalFile(directUrl, sFileUrl, fileType, token, function(stream){ + resolveStream(stream); + }); + } else { + resolve(_resolve(null, eR.externalReference.Id, oData)); + } + } } }); } @@ -5168,7 +5190,7 @@ let _oData = data && data[i]; let _eR = externalReferences[i]; - if (_oData && _eR && (_eR.isExternalLink() || !_oData["error"])) { + if (window["AscDesktopEditor"] || (_oData && _eR && (_eR.isExternalLink() || !_oData["error"]))) { requests.push(getPromise(_oData, _eR, resolveFunc)); } } diff --git a/cell/view/WorksheetView.js b/cell/view/WorksheetView.js index 3289de7d38..75536a9556 100644 --- a/cell/view/WorksheetView.js +++ b/cell/view/WorksheetView.js @@ -17035,17 +17035,23 @@ } } - var bRes = t._saveCellValueAfterEdit(c, val, flags, /*isNotHistory*/false, /*lockDraw*/false); - - var tempCell; - c._foreachNoEmpty(function (cell) { - tempCell = cell; - }); - if (tempCell) { + let _compare = function (_oldReferenceIds, _newReferenceIds) { + if (_oldReferenceIds && _newReferenceIds && _oldReferenceIds.length === _newReferenceIds.length) { + for (let i = 0; i < _newReferenceIds.length; i++) { + if (_oldReferenceIds[i] !== _newReferenceIds[i]) { + return false; + } + } + return true; + } + return false; + }; - } + let beforeExternalReferences = t.getExternalReferencesByCell(c, null, true); + let bRes = t._saveCellValueAfterEdit(c, val, flags, /*isNotHistory*/false, /*lockDraw*/false); - if (t.getExternalReferencesByCell(c, true)) { + let afterExternalReferences = t.getExternalReferencesByCell(c, true, true); + if (afterExternalReferences && !_compare(afterExternalReferences, beforeExternalReferences)) { t.model.workbook.handlers.trigger("asc_onNeedUpdateExternalReference"); } @@ -24282,7 +24288,7 @@ this.workbook.doUpdateExternalReference(externalReferences); }; - WorksheetView.prototype.getExternalReferencesByCell = function (c, initStructure) { + WorksheetView.prototype.getExternalReferencesByCell = function (c, initStructure, opt_get_only_ids) { let t = this; let externalReferences = []; t.model._getCell(c.bbox.r1, c.bbox.c1, function (cell) { @@ -24293,7 +24299,7 @@ if ((AscCommonExcel.cElementType.cellsRange3D === fP.outStack[i].type || AscCommonExcel.cElementType.cell3D === fP.outStack[i].type) && fP.outStack[i].externalLink) { let eR = t.model.workbook.getExternalWorksheet(fP.outStack[i].externalLink); if (eR) { - externalReferences.push(eR.getAscLink()); + externalReferences.push(opt_get_only_ids ? eR.Id : eR.getAscLink()); if (initStructure) { eR.initRows(fP.outStack[i].getRange()); }