add cloning of projects
This commit is contained in:
		
							parent
							
								
									78ed7b4b5f
								
							
						
					
					
						commit
						8d8e399aac
					
				
					 4 changed files with 30 additions and 5 deletions
				
			
		|  | @ -33,7 +33,7 @@ function Nav(props) { | |||
|             Export (zip) | ||||
|           </a> | ||||
|         </li> | ||||
|         <li className="nav__item"> | ||||
|         <li className="nav__item" onClick={props.cloneProject}> | ||||
|           <a className="nav__clone"> | ||||
|             Clone | ||||
|           </a> | ||||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
|       })); | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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} | ||||
|         /> | ||||
|         <Toolbar | ||||
|           className="Toolbar" | ||||
|  | @ -146,7 +147,8 @@ IDEView.propTypes = { | |||
|   closeNewFileModal: PropTypes.func.isRequired, | ||||
|   expandSidebar: PropTypes.func.isRequired, | ||||
|   collapseSidebar: PropTypes.func.isRequired, | ||||
|   exportProjectAsZip: PropTypes.func.isRequired | ||||
|   exportProjectAsZip: PropTypes.func.isRequired, | ||||
|   cloneProject: PropTypes.func.isRequired | ||||
| }; | ||||
| 
 | ||||
| function mapStateToProps(state) { | ||||
|  |  | |||
|  | @ -1,11 +1,11 @@ | |||
| import Project from '../models/project'; | ||||
| 
 | ||||
| export function createProject(req, res) { | ||||
|   const projectValues = { | ||||
|   let projectValues = { | ||||
|     user: req.user ? req.user._id : undefined // eslint-disable-line no-underscore-dangle
 | ||||
|   }; | ||||
| 
 | ||||
|   Object.assign(projectValues, req.body); | ||||
|   projectValues = Object.assign(projectValues, req.body); | ||||
| 
 | ||||
|   Project.create(projectValues, (err, newProject) => { | ||||
|     if (err) { return res.json({ success: false }); } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 catarak
						catarak