Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Create a 'fetch from remote' flow #26

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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
};

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];
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function(el) {
return simplyApp.actions.syncRemoteComponent(editor.pageData.component.remote);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<details class="sb-component">
<summary title="Remote API URL to fetch this component from">
Remote API URL
</summary>
<input placeholder="https://..." data-simply-field="component.remote.url">
<select data-simply-field="component.remote.type">
<option value="base-component">Base component</option>
<option value="component">Component</option>
<option value="page-frame">Page frame</option>
<option value="page">Page</option>
</select>
<input placeholder="component path" data-simply-field="component.remote.component"><br>
<button class="sb-button" data-simply-command="syncRemoteComponent">Sync from remote</button>
</details>
1 change: 1 addition & 0 deletions www/api/data/components/component-remote/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":"component-remote","description":"","remoteURL":"","remote":{"url":"","type":"base-component","component":""}}
59 changes: 59 additions & 0 deletions www/api/data/generated.html
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,42 @@
return 'name';
}
},
"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
};

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) {
Expand Down Expand Up @@ -1691,6 +1727,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({});
},
Expand Down Expand Up @@ -2959,6 +2998,22 @@
</div>
</details>
</template>
<template id="componentRemote">
<details class="sb-component">
<summary title="Remote API URL to fetch this component from">
Remote API URL
</summary>
<input placeholder="https://..." data-simply-field="component.remote.url">
<select data-simply-field="component.remote.type">
<option value="base-component">Base component</option>
<option value="component">Component</option>
<option value="page-frame">Page frame</option>
<option value="page">Page</option>
</select>
<input placeholder="component path" data-simply-field="component.remote.component"><br>
<button class="sb-button" data-simply-command="syncRemoteComponent">Sync from remote</button>
</details>
</template>
<template id="componentRoutes">
<details class="sb-component">
<summary data-simply-command="initEditors" title="Routes provide a translation from a URL to something the app should do. Routes make use of actions to fetch or store data">
Expand Down Expand Up @@ -3153,6 +3208,7 @@ <h1>Edit base component: <span data-simply-field="component.id"></span></h1>
<button class="sb-button" data-simply-command="deleteBaseComponent">Delete</button>
</div>
</div>
<div is="simply-component" rel="componentRemote"></div>
<div is="simply-component" rel="componentDescription"></div>
<div is="simply-component" rel="componentHeadHtml"></div>
<div is="simply-component" rel="componentBodyHtml"></div>
Expand Down Expand Up @@ -3201,6 +3257,7 @@ <h1>Edit component: <span data-simply-field="component.id"></span></h1>
<button class="sb-button" data-simply-command="deleteComponent">Delete</button>
</div>
</div>
<div is="simply-component" rel="componentRemote"></div>
<div is="simply-component" rel="componentDescription"></div>
<div is="simply-component" rel="componentComponentTemplate"></div>
<div is="simply-component" rel="componentComponentCss"></div>
Expand Down Expand Up @@ -3252,6 +3309,7 @@ <h1>Edit page: <span data-simply-field="component.id"></span></h1>
<button class="sb-button" data-simply-command="deletePage">Delete</button>
</div>
</div>
<div is="simply-component" rel="componentRemote"></div>
<div is="simply-component" rel="componentDescription"></div>
<div is="simply-component" rel="componentPageTemplate"></div>
<div is="simply-component" rel="componentPageCss"></div>
Expand All @@ -3272,6 +3330,7 @@ <h1>Edit page frame</h1>
<button class="sb-button" data-simply-command="savePageFrame">Save</button>
</div>
</div>
<div is="simply-component" rel="componentRemote"></div>
<div is="simply-component" rel="componentDescription"></div>
<div is="simply-component" rel="componentPageFrame"></div>
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h1>Edit base component: <span data-simply-field="component.id"></span></h1>
<button class="sb-button" data-simply-command="deleteBaseComponent">Delete</button>
</div>
</div>
<div is="simply-component" rel="componentRemote"></div>
<div is="simply-component" rel="componentDescription"></div>
<div is="simply-component" rel="componentHeadHtml"></div>
<div is="simply-component" rel="componentBodyHtml"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h1>Edit component: <span data-simply-field="component.id"></span></h1>
<button class="sb-button" data-simply-command="deleteComponent">Delete</button>
</div>
</div>
<div is="simply-component" rel="componentRemote"></div>
<div is="simply-component" rel="componentDescription"></div>
<div is="simply-component" rel="componentComponentTemplate"></div>
<div is="simply-component" rel="componentComponentCss"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ <h1>Edit page frame</h1>
<button class="sb-button" data-simply-command="savePageFrame">Save</button>
</div>
</div>
<div is="simply-component" rel="componentRemote"></div>
<div is="simply-component" rel="componentDescription"></div>
<div is="simply-component" rel="componentPageFrame"></div>
</main>
1 change: 1 addition & 0 deletions www/api/data/pages/page/pageTemplates/Edit page.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h1>Edit page: <span data-simply-field="component.id"></span></h1>
<button class="sb-button" data-simply-command="deletePage">Delete</button>
</div>
</div>
<div is="simply-component" rel="componentRemote"></div>
<div is="simply-component" rel="componentDescription"></div>
<div is="simply-component" rel="componentPageTemplate"></div>
<div is="simply-component" rel="componentPageCss"></div>
Expand Down
Loading