Skip to content

Commit

Permalink
Merge pull request #14 from joeblas/globalUI
Browse files Browse the repository at this point in the history
Global ui
  • Loading branch information
ethanzander authored Nov 17, 2017
2 parents 3a444f8 + 8a4d38c commit d728ed3
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 73 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions client/main.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<head>
<meta charset="utf-8">
<title>CloudControl</title>
<title>ControlCloud</title>
<meta name="description" content="A description for the application.">
<meta name="viewport" content="initial-scale=1, minimal-ui, maximum-scale=1, minimum-scale=1" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link rel="shortcut icon" type="image/png" href="/favicon.png?v1" sizes="16x16 32x32 64x64">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-precomposed.png">
<link rel="shortcut icon" type="image/png" href="/favicon.png" sizes="16x16 32x32 64x64">
<link rel="apple-touch-icon" sizes="120x120" href="/favicon.png">
</head>

<body>
Expand Down
97 changes: 97 additions & 0 deletions imports/ui/components/DocumentEditor/DocumentEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint-disable max-len, no-return-assign */

import React from 'react';
import PropTypes from 'prop-types';
import { FormGroup, ControlLabel, Button } from 'react-bootstrap';
import { Meteor } from 'meteor/meteor';
import { Bert } from 'meteor/themeteorchef:bert';
import validate from '../../../modules/validate';

class DocumentEditor extends React.Component {
componentDidMount() {
const component = this;
validate(component.form, {
rules: {
title: {
required: true,
},
body: {
required: true,
},
},
messages: {
title: {
required: 'Need a title in here, please.',
},
body: {
required: 'This needs a body, please.',
},
},
submitHandler() { component.handleSubmit(); },
});
}

handleSubmit() {
const { history } = this.props;
const existingDocument = this.props.doc && this.props.doc._id;
const methodToCall = existingDocument ? 'documents.update' : 'documents.insert';
const doc = {
title: this.title.value.trim(),
body: this.body.value.trim(),
};

if (existingDocument) doc._id = existingDocument;

Meteor.call(methodToCall, doc, (error, documentId) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
const confirmation = existingDocument ? 'Document updated!' : 'Document added!';
this.form.reset();
Bert.alert(confirmation, 'success');
history.push(`/documents/${documentId}`);
}
});
}

render() {
const { doc } = this.props;
return (<form ref={form => (this.form = form)} onSubmit={event => event.preventDefault()}>
<FormGroup>
<ControlLabel>Title</ControlLabel>
<input
type="text"
className="form-control"
name="title"
ref={title => (this.title = title)}
defaultValue={doc && doc.title}
placeholder="Oh, The Places You'll Go!"
/>
</FormGroup>
<FormGroup>
<ControlLabel>Body</ControlLabel>
<textarea
className="form-control"
name="body"
ref={body => (this.body = body)}
defaultValue={doc && doc.body}
placeholder="Congratulations! Today is your day. You're off to Great Places! You're off and away!"
/>
</FormGroup>
<Button type="submit" bsStyle="success">
{doc && doc._id ? 'Save Changes' : 'Add Document'}
</Button>
</form>);
}
}

DocumentEditor.defaultProps = {
doc: { title: '', body: '' },
};

DocumentEditor.propTypes = {
doc: PropTypes.object,
history: PropTypes.object.isRequired,
};

export default DocumentEditor;
91 changes: 21 additions & 70 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"bcrypt": "^1.0.3",
"commonmark": "^0.28.1",
"core-js": "^2.5.1",
"es5-shim": "^4.5.9",
"fs": "0.0.1-security",
"handlebars": "^4.0.10",
"html-pdf": "^2.2.0",
Expand Down
Binary file modified public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d728ed3

Please sign in to comment.