From 78ed7b4b5f23f6da0d0312dfb24bc674287dafc1 Mon Sep 17 00:00:00 2001
From: catarak
Date: Fri, 15 Jul 2016 13:11:50 -0400
Subject: [PATCH] add download as zip
---
client/components/Nav.js | 11 +++++++++++
client/modules/IDE/actions/project.js | 18 ++++++++++++++++++
client/modules/IDE/components/Toolbar.js | 4 +++-
client/modules/IDE/pages/IDEView.js | 4 +++-
client/styles/base/_base.scss | 1 +
package.json | 2 ++
6 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/client/components/Nav.js b/client/components/Nav.js
index 85c82bb2..26068f49 100644
--- a/client/components/Nav.js
+++ b/client/components/Nav.js
@@ -28,6 +28,16 @@ function Nav(props) {
+
+
+ Export (zip)
+
+
+
+
+ Clone
+
+
-
@@ -42,6 +52,7 @@ function Nav(props) {
Nav.propTypes = {
createProject: PropTypes.func.isRequired,
saveProject: PropTypes.func.isRequired,
+ exportProjectAsZip: PropTypes.func.isRequired,
user: PropTypes.shape({
authenticated: PropTypes.bool.isRequired,
username: PropTypes.string
diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js
index 913d979e..a26d2e2f 100644
--- a/client/modules/IDE/actions/project.js
+++ b/client/modules/IDE/actions/project.js
@@ -1,6 +1,8 @@
import * as ActionTypes from '../../../constants';
import { browserHistory } from 'react-router';
import axios from 'axios';
+import JSZip from 'jszip';
+import { saveAs } from 'file-saver';
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
@@ -98,3 +100,19 @@ export function createProject() {
}));
};
}
+
+export function exportProjectAsZip() {
+ return (dispatch, getState) => {
+ console.log('exporting project!');
+ const state = getState();
+ const zip = new JSZip();
+ state.files.forEach(file => {
+ zip.file(file.name, file.content);
+ });
+
+ zip.generateAsync({ type: 'blob' }).then((content) => {
+ saveAs(content, `${state.project.name}.zip`);
+ });
+ };
+}
+
diff --git a/client/modules/IDE/components/Toolbar.js b/client/modules/IDE/components/Toolbar.js
index 1d4a66c7..4d3d00bd 100644
--- a/client/modules/IDE/components/Toolbar.js
+++ b/client/modules/IDE/components/Toolbar.js
@@ -63,7 +63,9 @@ Toolbar.propTypes = {
setProjectName: PropTypes.func.isRequired,
projectName: PropTypes.string.isRequired,
openPreferences: PropTypes.func.isRequired,
- owner: PropTypes.string.isRequired
+ owner: PropTypes.shape({
+ username: PropTypes.string
+ })
};
export default Toolbar;
diff --git a/client/modules/IDE/pages/IDEView.js b/client/modules/IDE/pages/IDEView.js
index d186d375..ec3842a6 100644
--- a/client/modules/IDE/pages/IDEView.js
+++ b/client/modules/IDE/pages/IDEView.js
@@ -29,6 +29,7 @@ class IDEView extends React.Component {
user={this.props.user}
createProject={this.props.createProject}
saveProject={this.props.saveProject}
+ exportProjectAsZip={this.props.exportProjectAsZip}
/>