diff --git a/components/component-remote/actions/syncRemoteComponent.js b/components/component-remote/actions/syncRemoteComponent.js new file mode 100644 index 0000000..f4c8061 --- /dev/null +++ b/components/component-remote/actions/syncRemoteComponent.js @@ -0,0 +1,37 @@ +function(remote) { + let original = { + "url" : simplyRawApi.url, + "headers" : simplyRawApi.headers + }; + simplyRawApi.url = remote.url; + simplyRawApi.headers = { + "accept" : "application/json" + }; + let fetchFunctions = { + "base-component" : simplyDataApi.getBaseComponent, + "component" : simplyDataApi.getComponent, + "page" : simplyDataApi.getPage, + "page-frame" : simplyDataApi.getPageFrame, + "builder" : simplyDataApi.getBuilder + }; + + fetchFunctions[remote.type](remote.component) + .then(function(parts) { + parts.forEach(function(part) { + if (part.id == "meta") { + return; + } + editor.pageData.component.parts[part.id] = JSON.parse(part.contents); + }); + }) + .then(function() { + for (i in original) { + simplyRawApi[i] = original[i]; + } + }) + .catch(function() { + for (i in original) { + simplyRawApi[i] = original[i]; + } + }); +} \ No newline at end of file diff --git a/components/component-remote/commands/syncRemoteComponent.js b/components/component-remote/commands/syncRemoteComponent.js new file mode 100644 index 0000000..2709058 --- /dev/null +++ b/components/component-remote/commands/syncRemoteComponent.js @@ -0,0 +1,3 @@ +function(el) { + return simplyApp.actions.syncRemoteComponent(editor.pageData.component.remote); +} \ No newline at end of file diff --git a/components/component-remote/componentTemplates/componentRemote.html b/components/component-remote/componentTemplates/componentRemote.html new file mode 100644 index 0000000..661d0dd --- /dev/null +++ b/components/component-remote/componentTemplates/componentRemote.html @@ -0,0 +1,15 @@ +
+ + Remote API URL + + + +
+ +
\ No newline at end of file diff --git a/components/component-remote/meta.json b/components/component-remote/meta.json new file mode 100644 index 0000000..6840e1a --- /dev/null +++ b/components/component-remote/meta.json @@ -0,0 +1 @@ +{"id":"component-remote","description":"","remoteURL":"","remote":{"url":"","type":"base-component","component":""}} \ No newline at end of file diff --git a/generated.html b/generated.html index cdd66f7..f7a83d7 100644 --- a/generated.html +++ b/generated.html @@ -2517,6 +2517,43 @@ return build; }, + "syncRemoteComponent" : function(remote) { + let original = { + "url" : simplyRawApi.url, + "headers" : simplyRawApi.headers + }; + simplyRawApi.url = remote.url; + simplyRawApi.headers = { + "accept" : "application/json" + }; + let fetchFunctions = { + "base-component" : simplyDataApi.getBaseComponent, + "component" : simplyDataApi.getComponent, + "page" : simplyDataApi.getPage, + "page-frame" : simplyDataApi.getPageFrame, + "builder" : simplyDataApi.getBuilder + }; + + fetchFunctions[remote.type](remote.component) + .then(function(parts) { + parts.forEach(function(part) { + if (part.id == "meta") { + return; + } + editor.pageData.component.parts[part.id] = JSON.parse(part.contents); + }); + }) + .then(function() { + for (i in original) { + simplyRawApi[i] = original[i]; + } + }) + .catch(function() { + for (i in original) { + simplyRawApi[i] = original[i]; + } + }); + }, "browse" : function(path) { return simplyDataApi.browse(path) .catch(function(error) { @@ -3021,6 +3058,9 @@ "addRawApiMethod" : function(el) { editor.pageData.component.parts.rawApi.push({}); }, + "syncRemoteComponent" : function(el) { + return simplyApp.actions.syncRemoteComponent(editor.pageData.component.remote); + }, "addRoute" : function(el) { editor.pageData.component.parts.routes.push({}); }, @@ -4433,6 +4473,23 @@ +