Collapse all
The document history can be shown using the onRequestHistory function (with the events.onRequestHistory event). Unless you use them, the Version History menu option (Version History button in the Collaboration tab) is not shown in the ONLYOFFICE Docs interface.
Once you call this function in the configuration file (together with the refreshHistory method), the menu option and button are shown and the program will display the existing document versions. The data which is shown in the document version history, can be taken from the document editing service callback.
So the implementation of the document version history display should look like this:
{ "key": "2745492410", "status": 2, "users": ["F89d8069ba2b"], "url": "https://documentserver/url-to-edited-document.docx", "history": { "serverVersion": serverVersion, "changes": changes } }
var onRequestHistory = function() { docEditor.refreshHistory({ "currentVersion": 2, "history": [ { "created": "2019-02-01 3:03 PM", "key": "2745492410", "user": { "id": "F89d8069ba2b", "name": "Kate Cage" }, "version": 1 }, { "changes": changes, "created": "2010-07-07 3:46 PM", "key": "Khirz6zTPdfd7", "serverVersion": serverVersion, "user": { "id": "78e1e841", "name": "John Smith" }, "version": 2 }, ... ] }); }; var docEditor = new DocsAPI.DocEditor("placeholder", { "events": { "onRequestHistory": onRequestHistory, ... }, ... });Where
The document editing service saves all the interim changes of the document into separate files and, once the version is compiled and status 2 is received, the link to the archive with all the changes between the versions is also sent to the callback handler.
So, if you want to additionally show the difference between the versions, you will also have to use the onRequestHistoryData function (with the events.onRequestHistoryData event) which must contain data also returned by the document editing service callback.
In addition to the actions described in the above question you will need to:
{ "changesurl": "https://documentserver/url-to-changes.zip", "key": "2745492410", "status": 2, "users": ["F89d8069ba2b"], "url": "https://documentserver/url-to-edited-document.docx", "history": { "serverVersion": serverVersion, "changes": changes } }
var onRequestHistoryData = function(event) { var version = event.data; docEditor.setHistoryData({ "changesUrl": "https://example.com/url-to-changes.zip", "key": "2745492410", "previous": { "key": "af86C7e71Ca8", "url": "https://example.com/url-to-the-previous-version-of-the-document.docx" }, "url": "https://documentserver/url-to-edited-document.docx", "version": version }) }; var docEditor = new DocsAPI.DocEditor("placeholder", { "events": { "onRequestHistoryData": onRequestHistoryData, ... }, ... });The object containing the valid links to the current document version (url) and to the previous document version (previous.url) as well as the IDs (key and previous.key) must be passed to the configuration file. changesUrl archive file must be also available and downloadable from the browser to be able to display the changes.
ONLYOFFICE Docs highlights the changes made from the beginning of the current document session, not from the beginning of the document version. And even if several document versions are created during one session, all changes from this session will be highlighted. Therefore, you cannot see the document versions created with the force saving option in the document history.