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

Fixes #861 exercise tracker added #1039

Merged
merged 1 commit into from
Jul 28, 2021
Merged
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
38 changes: 38 additions & 0 deletions Javascript/Exercise Tracker/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
26 changes: 26 additions & 0 deletions Javascript/Exercise Tracker/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { BrowserRouter as Router, Route} from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css";

import Navbar from "./components/navbar.component";
import ExercisesList from "./components/exercises-list.component";
import EditExercise from "./components/edit-exercise.component";
import CreateExercise from "./components/create-exercise.component";
import CreateUser from "./components/create-user.component";

function App() {
return (
<Router>
<div className="container">
<Navbar />
<br/>
<Route path="/" exact component={ExercisesList} />
<Route path="/edit/:id" component={EditExercise} />
<Route path="/create" component={CreateExercise} />
<Route path="/user" component={CreateUser} />
</div>
</Router>
);
}

export default App;
39 changes: 39 additions & 0 deletions Javascript/Exercise Tracker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Exercise Tracker using Javascript

# Introduction

This is a MERN exercise tracker which tracks your daily exercising schedules.

# Third-Party Libraries Required :

React - https://www.javatpoint.com/react-installation
Node - https://phoenixnap.com/kb/install-node-js-npm-on-windows

## Steps to try this

1. Clone/Download this repository

```
git clone clone_path

```

## How to use it:

After Cloning a repository

1. Open the Exercise Tracker folder

2. Run index.html file.

# Output

## Input Image

<img src="images/img (3).jpg">
<img src="images/img (4).jpg">

## Output Image

<img src="images/img (1).jpg">
<img src="images/img (4).jpg">
142 changes: 142 additions & 0 deletions Javascript/Exercise Tracker/create-exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React, { Component } from 'react';
import axios from 'axios';
import DatePicker from 'react-datepicker';
import "react-datepicker/dist/react-datepicker.css";


export default class CreateExercises extends Component {
constructor(props) {
super(props);

this.onChangeUsername = this.onChangeUsername.bind(this);
this.onChangeDescription = this.onChangeDescription.bind(this);
this.onChangeDuration = this.onChangeDuration.bind(this);
this.onChangeDate = this.onChangeDate.bind(this);
this.onSubmit = this.onSubmit.bind(this);

this.state = {
username: '',
description: '',
duration: 0,
date: new Date(),
users: []
}
}

componentDidMount() {
axios.get('http://localhost:5000/users/')
.then(response => {
if (response.data.length > 0) {
this.setState({
users: response.data.map(user => user.username),
username: response.data[0].username
})
}
})
.catch((error) => {
console.log(error);
})

}

onChangeUsername(e) {
this.setState({
username: e.target.value
});
}

onChangeDescription(e) {
this.setState({
description: e.target.value
});
}

onChangeDuration(e) {
this.setState({
duration: e.target.value
});
}

onChangeDate(date) {
this.setState({
date: date
});
}

onSubmit(e) {
e.preventDefault();

const exercise = {
username: this.state.username,
description: this.state.description,
duration: this.state.duration,
date: this.state.date
}

console.log(exercise);

axios.post('http://localhost:5000/exercises/add', exercise)
.then(res => console.log(res.data));

window.location = '/';
}


render() {
return (
<div>
<h3>Create New Exercise Log</h3>
<form onSubmit={this.onSubmit}>
<div className="form-group">
<label>Username: </label>
<select ref="userInput"
required
className="form-control"
value={this.state.username}
onChange={this.onChangeUsername}>
{
this.state.users.map(function(user) {
return <option
key={user}
value={user}>{user}
</option>;
})
}
</select>
</div>
<div className="form-group">
<label>Description: </label>
<input type="text"
required
className="form-control"
value={this.state.description}
onChange={this.onChangeDescription}
/>
</div>
<div className="form-group">
<label>Duration (in minutes): </label>
<input
type="text"
className="form-control"
value={this.state.duration}
onChange={this.onChangeDuration}
/>
</div>
<div className="form-group">
<label>Date: </label>
<div>
<DatePicker
selected={this.state.date}
onChange={this.onChangeDate}
/>
</div>
</div>

<div className="form-group">
<input type="submit" value="Create Exercise Log" className="btn btn-primary" />
</div>
</form>
</div>
)
}
}
77 changes: 77 additions & 0 deletions Javascript/Exercise Tracker/exercise-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import axios from 'axios';

const Exercise = props => (
<tr>
<td>{props.exercise.username}</td>
<td>{props.exercise.description}</td>
<td>{props.exercise.duration}</td>
<td>{props.exercise.date.substring(0,10)}</td>
<td>
<Link to={"/edit/"+props.exercise._id}>edit</Link> | <a href="#" onClick={() => { props.deleteExercise(props.exercise._id) }}>delete</a>
</td>
</tr>
)


export default class ExercisesList extends Component {
constructor(props) {
super(props);

this.deleteExercise = this.deleteExercise.bind(this)

this.state = {exercises: []};
}

componentDidMount() {
axios.get('http://localhost:5000/exercises/')
.then(response => {
this.setState({ exercises: response.data })
})
.catch((error) => {
console.log(error);
})
}

deleteExercise(id) {
axios.delete('http://localhost:5000/exercises/'+id)
.then(response => { console.log(response.data)});

this.setState({
exercises: this.state.exercises.filter(el => el._id !== id)
})
}

exerciseList() {
return this.state.exercises.map(currentexercise => {
return <Exercise exercise={currentexercise} deleteExercise={this.deleteExercise} key={currentexercise._id}/>;
})
}




render() {
return (
<div>
<h3>Logged Exercises</h3>
<table className="table">
<thead className="thead-light">
<tr>
<th>Username</th>
<th>Description</th>
<th>Duration</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{ this.exerciseList() }
</tbody>
</table>
</div>

)
}
}
Binary file added Javascript/Exercise Tracker/images/img (1).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Javascript/Exercise Tracker/images/img (2).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Javascript/Exercise Tracker/images/img (3).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Javascript/Exercise Tracker/images/img (4).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions Javascript/Exercise Tracker/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
23 changes: 23 additions & 0 deletions Javascript/Exercise Tracker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />

<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

<title>Exercise Tracker</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

</body>
</html>
10 changes: 10 additions & 0 deletions Javascript/Exercise Tracker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
Loading