diff --git a/client/constants.js b/client/constants.js
index 29d9f701..b69e22b2 100644
--- a/client/constants.js
+++ b/client/constants.js
@@ -1,4 +1,4 @@
-export const UPDATE_FILE = 'UPDATE_FILE';
+export const UPDATE_FILE_CONTENT = 'UPDATE_FILE_CONTENT';
export const TOGGLE_SKETCH = 'TOGGLE_SKETCH';
export const START_SKETCH = 'START_SKETCH';
diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js
index 3ceca1e1..f7ebd8f3 100644
--- a/client/modules/IDE/actions/files.js
+++ b/client/modules/IDE/actions/files.js
@@ -1,8 +1,8 @@
import * as ActionTypes from '../../../constants';
-export function updateFile(name, content) {
+export function updateFileContent(name, content) {
return {
- type: ActionTypes.UPDATE_FILE,
+ type: ActionTypes.UPDATE_FILE_CONTENT,
name,
content
};
diff --git a/client/modules/IDE/components/Editor.js b/client/modules/IDE/components/Editor.js
index e7cb8647..b028d705 100644
--- a/client/modules/IDE/components/Editor.js
+++ b/client/modules/IDE/components/Editor.js
@@ -14,7 +14,7 @@ class Editor extends React.Component {
mode: 'javascript'
});
this._cm.on('change', () => { // eslint-disable-line
- this.props.updateFile('sketch.js', this._cm.getValue());
+ this.props.updateFileContent('sketch.js', this._cm.getValue());
});
this._cm.getWrapperElement().style['font-size'] = `${this.props.fontSize}px`;
}
@@ -42,7 +42,7 @@ class Editor extends React.Component {
Editor.propTypes = {
content: PropTypes.string.isRequired,
- updateFile: PropTypes.func.isRequired,
+ updateFileContent: PropTypes.func.isRequired,
fontSize: PropTypes.number.isRequired
};
diff --git a/client/modules/IDE/components/Sidebar.js b/client/modules/IDE/components/Sidebar.js
index bcf11473..3c5d0fe6 100644
--- a/client/modules/IDE/components/Sidebar.js
+++ b/client/modules/IDE/components/Sidebar.js
@@ -5,7 +5,10 @@ function Sidebar(props) {
{props.files.map(file =>
- - {file.name}
+ - {file.name}
)}
diff --git a/client/modules/IDE/pages/IDEView.js b/client/modules/IDE/pages/IDEView.js
index 6b74c737..2278a095 100644
--- a/client/modules/IDE/pages/IDEView.js
+++ b/client/modules/IDE/pages/IDEView.js
@@ -48,7 +48,7 @@ class IDEView extends React.Component {
{
switch (action.type) {
- case ActionTypes.UPDATE_FILE:
+ case ActionTypes.UPDATE_FILE_CONTENT:
return state.map(file => {
if (file.name !== action.name) {
return file;
}
- return {
- name: file.name,
- content: action.content
- };
+ return Object.assign({}, file, { content: action.content });
});
case ActionTypes.NEW_PROJECT:
return [...action.files];
diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js
index c4a4887a..03baa4e5 100644
--- a/server/controllers/project.controller.js
+++ b/server/controllers/project.controller.js
@@ -10,11 +10,7 @@ export function createProject(req, res) {
Project.create(projectValues, (err, newProject) => {
if (err) { return res.json({ success: false }); }
- return res.json({
- id: newProject._id, // eslint-disable-line no-underscore-dangle
- name: newProject.name,
- files: newProject.files
- });
+ return res.json(newProject);
});
}
@@ -24,11 +20,7 @@ export function updateProject(req, res) {
$set: req.body
}, (err, updatedProject) => {
if (err) { return res.json({ success: false }); }
- return res.json({
- id: updatedProject._id, // eslint-disable-line no-underscore-dangle
- name: updatedProject.name,
- file: updatedProject.files
- });
+ return res.json(updatedProject);
});
}
@@ -38,11 +30,7 @@ export function getProject(req, res) {
return res.status(404).send({ message: 'Project with that id does not exist' });
}
- return res.json({
- id: project._id, // eslint-disable-line no-underscore-dangle
- name: project.name,
- files: project.files
- });
+ return res.json(project);
});
}
diff --git a/server/models/project.js b/server/models/project.js
index 1ad4b4ee..709ea58d 100644
--- a/server/models/project.js
+++ b/server/models/project.js
@@ -28,6 +28,14 @@ const fileSchema = new Schema({
content: { type: String, default: defaultSketch }
}, { timestamps: true, _id: true });
+fileSchema.virtual('id').get(function(){
+ return this._id.toHexString();
+});
+
+fileSchema.set('toJSON', {
+ virtuals: true
+});
+
const projectSchema = new Schema({
name: { type: String, default: "Hello p5.js, it's the server" },
user: { type: Schema.Types.ObjectId, ref: 'User' },
@@ -35,4 +43,12 @@ const projectSchema = new Schema({
_id: { type: String, default: shortid.generate }
}, { timestamps: true });
+projectSchema.virtual('id').get(function(){
+ return this._id;
+});
+
+projectSchema.set('toJSON', {
+ virtuals: true
+});
+
export default mongoose.model('Project', projectSchema);