Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "mongodb-stitch-tutorial",
"name": "msreactcore",
"version": "0.1.0",
"private": true,
"dependencies": {
"mongodb-stitch-browser-sdk": "^4.1.2",
"mongodb-stitch-browser-sdk": "4.8.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.2"
Expand All @@ -22,5 +22,7 @@
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
],
"keywords": [],
"description": ""
}
Binary file modified public/favicon.ico
Binary file not shown.
Binary file modified src/.App.js.swp
Binary file not shown.
109 changes: 68 additions & 41 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,57 @@ class App extends Component {
value: ""
};

this.handleChange = this.handleChange.bind(this);
this.displayTodos = this.displayTodos.bind(this);
this.addTodo = this.addTodo.bind(this);
}

componentDidMount() {
// Initialize the App Client
this.client = Stitch.initializeDefaultAppClient("todotutorial-pchnc");
this.client = Stitch.initializeDefaultAppClient("waeinv-synha");
// Get a MongoDB Service Client, used for logging in and communicating with Stitch
const mongodb = this.client.getServiceClient(
RemoteMongoClient.factory,
"mongodb-atlas"
);
// Get a reference to the todo database
this.db = mongodb.db("todo");

this.db = mongodb.db("coreTec");
this.displayTodosOnLoad();
}

/*displayTodos() {
this.db
.collection("inventory")
.find({}, { limit: 1 })
.asArray()
.then(todos => {
this.setState({
todos
});
var dosc = todos.map(ele => ele.LineCard)
console.log(this.state.todos)
});
}*/

displayTodos() {
const agg = [
{
$project: {
in: "$TrafficIn(Maximum)",
out: "$TrafficOut(Maximum)",
name: "$name",
day: "$day",
month: "$month",
year: "$year"
}
},
{
$sort: {
month: -1
}
}
];
this.db
.collection("item")
.find({}, { limit: 1000 })
.collection("coreInOut")
.aggregate(agg)
.asArray()
.then(todos => {
this.setState({
Expand All @@ -52,44 +80,43 @@ class App extends Component {
.catch(console.error);
}

addTodo(event) {
event.preventDefault();
const { value } = this.state;

this.db
.collection("item")
.insertOne({
owner_id: this.client.auth.user.id,
item: value
})
.then(this.displayTodos);
}

handleChange(event) {
this.setState({ value: event.target.value });
}

render() {
return (
<div className="App">
<h3>This is a todo app</h3>
<h3>Trafico</h3>
<hr />
<p>Add a Todo Item:</p>
<form onSubmit={this.addTodo}>
<label>
<input
type="text"
value={this.state.value}
onChange={this.handleChange}
/>
</label>
<input type="submit" value="Submit" />
</form>
<ul>
{this.state.todos.map(todo => {
return <li>{todo.item}</li>;
})}
</ul>
<table>
<td>
{this.state.todos.map(todo => {
return <tr>{todo.day}</tr>;
})}
</td>
<td>
{this.state.todos.map(todo => {
return <tr>{todo.month}</tr>;
})}
</td>
<td>
{this.state.todos.map(todo => {
return <tr>{todo.year}</tr>;
})}
</td>
<td>
{this.state.todos.map(todo => {
return <tr>{todo.name}</tr>;
})}
</td>
<td>
{this.state.todos.map(todo => {
return <tr>{todo.in / 1000}</tr>;
})}
</td>
<td>
{this.state.todos.map(todo => {
return <tr>{todo.out / 1000}</tr>;
})}
</td>
</table>
</div>
);
}
Expand Down