From 8d8e399aac9ee9549954de3b1c2d9d09398d04e9 Mon Sep 17 00:00:00 2001 From: catarak Date: Fri, 15 Jul 2016 13:36:33 -0400 Subject: [PATCH] add cloning of projects --- client/components/Nav.js | 3 ++- client/modules/IDE/actions/project.js | 24 +++++++++++++++++++++++- client/modules/IDE/pages/IDEView.js | 4 +++- server/controllers/project.controller.js | 4 ++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/client/components/Nav.js b/client/components/Nav.js index 26068f49..a9b015df 100644 --- a/client/components/Nav.js +++ b/client/components/Nav.js @@ -33,7 +33,7 @@ function Nav(props) { Export (zip) -
  • +
  • Clone @@ -53,6 +53,7 @@ Nav.propTypes = { createProject: PropTypes.func.isRequired, saveProject: PropTypes.func.isRequired, exportProjectAsZip: PropTypes.func.isRequired, + cloneProject: 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 a26d2e2f..804963b8 100644 --- a/client/modules/IDE/actions/project.js +++ b/client/modules/IDE/actions/project.js @@ -83,7 +83,6 @@ export function createProject() { return (dispatch) => { axios.post(`${ROOT_URL}/projects`, {}, { withCredentials: true }) .then(response => { - console.log(response.data); browserHistory.push(`/projects/${response.data.id}`); dispatch({ type: ActionTypes.NEW_PROJECT, @@ -116,3 +115,26 @@ export function exportProjectAsZip() { }; } +export function cloneProject() { + return (dispatch, getState) => { + const state = getState(); + const formParams = Object.assign({}, { name: state.project.name }, { files: state.files }); + axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true }) + .then(response => { + browserHistory.push(`/projects/${response.data.id}`); + dispatch({ + type: ActionTypes.NEW_PROJECT, + name: response.data.name, + id: response.data.id, + owner: response.data.user, + selectedFile: response.data.selectedFile, + files: response.data.files + }); + }) + .catch(response => dispatch({ + type: ActionTypes.PROJECT_SAVE_FAIL, + error: response.data + })); + }; +} + diff --git a/client/modules/IDE/pages/IDEView.js b/client/modules/IDE/pages/IDEView.js index ec3842a6..6987b726 100644 --- a/client/modules/IDE/pages/IDEView.js +++ b/client/modules/IDE/pages/IDEView.js @@ -30,6 +30,7 @@ class IDEView extends React.Component { createProject={this.props.createProject} saveProject={this.props.saveProject} exportProjectAsZip={this.props.exportProjectAsZip} + cloneProject={this.props.cloneProject} /> { if (err) { return res.json({ success: false }); }