diff --git a/src/api/routes.ts b/src/api/routes.ts
index ed8bc74b..157e31ba 100644
--- a/src/api/routes.ts
+++ b/src/api/routes.ts
@@ -91,8 +91,9 @@ api.post('/notebooks/', requireAuthenticationAPI, async (req, res) => {
try {
const projectID = await createNotebook(projectName, uiSpec, metadata);
res.json({notebook: projectID});
- } catch {
+ } catch (err) {
res.json({error: 'there was an error creating the notebook'});
+ console.log('Error creating notebook', err);
res.status(500).end();
}
} else {
diff --git a/views/notebooks.handlebars b/views/notebooks.handlebars
index 4e29d320..3cec79fd 100644
--- a/views/notebooks.handlebars
+++ b/views/notebooks.handlebars
@@ -6,6 +6,57 @@
+
Notebooks
+
+
+ {{#each notebooks}}
+
+
+ {{this.name}}
+ |
+ {{#if ../developer}}
+
+
+ |
+ {{/if}}
+
+ {{/each}}
+
+
+
+
+
+
+
-Notebooks
-
- {{#each notebooks}}
-
-
- {{this.name}}
- |
- {{#if ../developer}}
-
-
- |
- {{/if}}
-
- {{/each}}
-
-
-
\ No newline at end of file
+ function uploadNotebookHandler(event) {
+ event.preventDefault();
+ const url = '/api/notebooks/';
+ const form = event.target;
+ const name = form.querySelector('[name="name"]').value;
+ const fileInput = form.querySelector('[name="notebook"]');
+ if (fileInput) {
+ // parse the contents of the uploaded file as JSON
+ const reader = new FileReader();
+ const filename = fileInput.files[0];
+ reader.readAsText(filename);
+ reader.onload = (evt) => {
+ try {
+ const data = JSON.parse(evt.target.result);
+ // a little bit of validation
+ if (!data.metadata || !data['ui-specification']) {
+ alert('Invalid notebook file');
+ return;
+ }
+ if (!data.metadata.name) {
+ alert('Invalid notebook file');
+ return;
+ }
+ const body = {
+ metadata: data.metadata,
+ 'ui-specification': data['ui-specification'],
+ name: name || data.metadata.name,
+ }
+ fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(body),
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (data.notebook) {
+ window.location.reload();
+ } else {
+ alert('Error uploading notebook');
+ }
+ });
+ } catch (e) {
+ alert('Invalid notebook file');
+ return;
+ }
+ }
+
+
+
+ }
+ }
+ document.getElementById('upload-notebook-form').onsubmit = uploadNotebookHandler;
+