{"action":"opened","issue":{"url":"https://api.github.com/repos/substance/texture/issues/457","repository_url":"https://api.github.com/repos/substance/texture","labels_url":"https://api.github.com/repos/substance/texture/issues/457/labels{/name}","comments_url":"https://api.github.com/repos/substance/texture/issues/457/comments","events_url":"https://api.github.com/repos/substance/texture/issues/457/events","html_url":"https://github.com/substance/texture/issues/457","id":308653698,"number":457,"title":"texture integration with OTS","user":{"login":"kaschioudi","id":4896270,"avatar_url":"https://avatars0.githubusercontent.com/u/4896270?v=4","gravatar_id":"","url":"https://api.github.com/users/kaschioudi","html_url":"https://github.com/kaschioudi","followers_url":"https://api.github.com/users/kaschioudi/followers","following_url":"https://api.github.com/users/kaschioudi/following{/other_user}","gists_url":"https://api.github.com/users/kaschioudi/gists{/gist_id}","starred_url":"https://api.github.com/users/kaschioudi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaschioudi/subscriptions","organizations_url":"https://api.github.com/users/kaschioudi/orgs","repos_url":"https://api.github.com/users/kaschioudi/repos","events_url":"https://api.github.com/users/kaschioudi/events{/privacy}","received_events_url":"https://api.github.com/users/kaschioudi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-26T16:54:19Z","updated_at":"2018-03-26T16:54:19Z","closed_at":null,"author_association":"NONE","body":"Hi Guys,\r\n\r\nI am currently working on integrating OTS with your latest release. i have noticed that the integration is different from the previous integration we performed. Based on the example file from `texture-1.0.0-preview.1-web.zip`, here's what I have done so far. \r\n\r\nI have updated substance and texture CSS and Javascript to their latest version. Then I have created an `editor.js` file in charge of bootstrapping the editor. I have tried to use `substance.HttpStorageClient` as storage but (correct me if I am wrong) it looks like that storage client is expecting JSON response (cf. https://github.com/substance/substance/blob/a10d8cbfcfe168433e7205d2e2b8754e7218c580/dar/HttpStorageClient.js#L22).\r\n\r\nSince on OTS side the URI returning the document return XML directly, I have created `XmlHttpStorageClient` class like this:\r\n\r\n```\r\nclass XmlHttpStorageClient extends substance.HttpStorageClient {\r\n\r\n\t\tconstructor(apiUrl) {\r\n\t\t\tsuper(apiUrl)\r\n\t\t}\r\n\r\n\t\tread(archiveId) {\r\n\t\t\tlet url = this.apiUrl;\r\n\t\t\tif (archiveId) {\r\n\t\t\t\turl = url + '/' + archiveId;\r\n\t\t\t}\r\n\t\t\treturn fetch(url, {\r\n\t\t\t\tcredentials: 'same-origin'\r\n\t\t\t}).then(function(response){\r\n\t\t\t\treturn response.text();\r\n\t\t\t})\r\n\t\t}\r\n\t\t\r\n\t\twrite(archiveId, data) {\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n```\r\n\r\nAt this stage, it looks like Texture is successfully fetching the XML document. Nonetheless I am running into the following error and I am not sure how to do at this point.\r\n```\r\nUncaught (in promise) TypeError: Cannot read property 'manifest.xml' of undefined\r\n    at TextureArchive._ingest (texture.js:9000)\r\n    at Promise.resolve.then.then.then.then (substance.js:35347)\r\n```\r\n\r\nBelow is my full source code so far\r\n\r\n```\r\n(function (global, factory) {\r\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(require('substance'), require('substance-texture')) :\r\n\ttypeof define === 'function' && define.amd ? define(['substance', 'substance-texture'], factory) :\r\n\t(factory(global.window.substance,global.window.texture));\r\n}(this, (function (substance,substanceTexture) { 'use strict';\r\n\r\n\twindow.addEventListener('load', () => {\r\n\t\tsubstance.substanceGlobals.DEBUG_RENDERING = substance.platform.devtools;\r\n\t\tOTSTextureEditor.mount({}, window.document.body);\r\n\t});\r\n\t\r\n\tclass XmlHttpStorageClient extends substance.HttpStorageClient {\r\n\r\n\t\tconstructor(apiUrl) {\r\n\t\t\tsuper(apiUrl)\r\n\t\t}\r\n\r\n\t\tread(archiveId) {\r\n\t\t\tlet url = this.apiUrl;\r\n\t\t\tif (archiveId) {\r\n\t\t\t\turl = url + '/' + archiveId;\r\n\t\t\t}\r\n\t\t\treturn fetch(url, {\r\n\t\t\t\tcredentials: 'same-origin'\r\n\t\t\t}).then(function(response){\r\n\t\t\t\treturn response.text();\r\n\t\t\t})\r\n\t\t}\r\n\t\t\r\n\t\twrite(archiveId, data) {\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass OTSTextureEditor extends substance.Component {\r\n\t\tdidMount() {\r\n\t\t\tthis._init();\r\n\t\t\tsubstance.DefaultDOMElement.getBrowserWindow().on('keydown', this._keyDown, this);\r\n\t\t}\r\n\t\t\r\n\t\tdispose() {\r\n\t\t\tsubstance.DefaultDOMElement.getBrowserWindow().off(this);\r\n\t\t}\r\n\t\t\r\n\t\tgetInitialState() {\r\n\t\t\treturn {\r\n\t\t\t\tarchive: undefined,\r\n\t\t\t\terror: undefined\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t_init() {\r\n\t\t\tlet storageUrl = document.querySelector('meta[name=jobId').getAttribute('content');\r\n\t\t\tlet storage = new XmlHttpStorageClient(storageUrl);\r\n\t\t\tlet buffer = new substance.InMemoryDarBuffer();\r\n\t\t\tlet archive = new substanceTexture.TextureArchive(storage, buffer);\r\n\r\n\t\t\tlet promise = archive.load('')\r\n\t\t\t.then(() => {\r\n\t\t\t\tsetTimeout(() => {\r\n\t\t\t\t\tthis.setState({archive});\r\n\t\t\t\t}, 0);\r\n\t\t\t});\r\n\r\n\t\t\tif (!substance.platform.devtools) {\r\n\t\t\t\tpromise.catch(error => {\r\n\t\t\t\t\tconsole.error(error);\r\n\t\t\t\t\tthis.setState({error});\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t_keyDown(event) {\r\n\t\t\tif ( event.key === 'Dead' ) return\r\n\t\t\t// Handle custom keyboard shortcuts globally\r\n\t\t\tlet archive = this.state.archive;\r\n\t\t\tif (archive) {\r\n\t\t\t\tlet manuscriptSession = archive.getEditorSession('manuscript');\r\n\t\t\t\tlet handled = manuscriptSession.keyboardManager.onKeydown(event);\r\n\t\t\t\tif (!handled) {\r\n\t\t\t\t\tlet key = substance.parseKeyEvent(event);\r\n\t\t\t\t\t// CommandOrControl+S\r\n\t\t\t\t\tif (key === 'META+83' || key === 'CTRL+83') {\r\n\t\t\t\t\t\tthis._save();\r\n\t\t\t\t\t\tevent.preventDefault();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t_save() {\r\n\t\t\tthis.state.archive.save().then(() => {\r\n\t\t\t\tconsole.info('successfully saved');\r\n\t\t\t}).catch(err => {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t});\r\n\t\t}\r\n\t\t\r\n\t\trender($$) {\r\n\t\t\tlet el = $$('div').addClass('sc-app');\r\n\t\t\tlet archive = this.state.archive;\r\n\t\t\tlet err = this.state.error;\r\n\r\n\t\t\tif (archive) {\r\n\t\t\t\tel.append(\r\n\t\t\t\t\t$$(substanceTexture.Texture, {archive})\r\n\t\t\t\t);\r\n\t\t\t} else if (err) {\r\n\t\t\t\tif (err.type === 'jats-import-error') {\r\n\t\t\t\t\tel.append(\r\n\t\t\t\t\t\t\t$$(substanceTexture.JATSImportDialog, { errors: err.detail })\r\n\t\t\t\t\t);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tel.append(\r\n\t\t\t\t\t\t'ERROR:',\r\n\t\t\t\t\t\terr.message\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t// LOADING...\r\n\t\t\t}\r\n\t\t\treturn el\r\n\t\t}\r\n\t}\r\n\r\n})));\r\n```"}}
{"actor":{"display_login":"kaschioudi"}}