Skip to content

Commit 5aedbdf

Browse files
updated url
1 parent ba3b837 commit 5aedbdf

File tree

6 files changed

+92
-10
lines changed

6 files changed

+92
-10
lines changed

app/config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
PORT: process.env.PORT || 5000,
2+
PORT: process.env.PORT || 8080,
33
HTTP_STATUS_CODES: {
44
OK: 200,
55
CREATED: 201,
@@ -10,7 +10,8 @@ module.exports = {
1010
INTERNAL_SERVER_ERROR: 500,
1111
},
1212

13-
MONGO_URL: process.env.MONGO_URL || 'mongodb://ds237932.mlab.com:37932/fit-journal',
13+
MONGO_URL: process.env.MONGO_URL || 'mongodb://localhost:27017/fit-journal',
14+
// MONGO_URL: process.env.MONGO_URL || 'mongodb://ds237932.mlab.com:37932/fit-journal',
1415
TEST_MONGO_URL: process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test-fit-journal',
1516
JWT_SECRET: process.env.JWT_SECRET || 'default',
1617
JWT_EXPIRY: process.env.JWT_EXPIRY || '7d',

public/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ <h4 class="add-ex js-addEx"><a href="/search.html">Add Exercise</a></h4>
7373

7474
<script src="/utilities/http.module.js"></script>
7575
<script src="/utilities/index.js"></script>
76-
7776
<script src="/dashboard.page.js"></script>
7877
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>
78+
<script src="/home.js"></script>
7979

8080

8181

public/home.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
$(document).ready(onPageLoadHome);
2+
3+
function onPageLoadHome() {
4+
updateAuthenticatedUI();
5+
6+
// if (STATE.authUser) {
7+
// HTTP.getUserworkouts({
8+
// jwtToken: STATE.authUser.jwtToken,
9+
// onSuccess: console.log("User Authenticated")
10+
// // RENDER.renderWorkoutsList
11+
// });
12+
// }
13+
{ /* <nav class="nav-login"><a id="logout-btn" href="">Log Out</a> </nav> */ }
14+
15+
// $('#workout-list').on('click', '#delete-workout-btn', onDeleteWorkoutBtnClick);
16+
// $('#workout-list').on('click', '#workout-card', onWorkoutCardClick);
17+
}
18+
19+
20+
function onLogoutBtnClick(event) {
21+
event.preventDefault();
22+
23+
try {
24+
CACHE.deleteAuthenticatedUserFromCache();
25+
window.open('/index.html', '_self')
26+
} catch {
27+
console.error(error);
28+
}
29+
}
30+
31+
// Handle opening Workout details
32+
function onWorkoutCardClick(event) {
33+
const workoutId = $(event.currentTarget).attr('data-workout-id');
34+
window.open(`Workout/details.html?id=${workoutId}`, '_self');
35+
}
36+
37+
// Handle deleting Workouts
38+
function onDeleteWorkoutBtnClick(event) {
39+
/**
40+
* Because "onWorkoutDeleteClick" and "onWorkoutClick" both are listening for clicks inside of
41+
* #Workout-card element, we need to call event.stopImmediatePropagation to avoid both
42+
* event listeners firing when we click on the delete button inside #Workout-card.
43+
*/
44+
event.stopImmediatePropagation();
45+
// Step 1: Get the Workout id to delete from it's parent.
46+
const workoutId = $(event.currentTarget)
47+
.closest('#workout-card')
48+
.attr('data-workout-id');
49+
// Step 2: Verify use is sure of deletion
50+
const userSaidYes = confirm('Are you sure you want to delete this workout?');
51+
if (userSaidYes) {
52+
// Step 3: Make ajax call to delete workout
53+
HTTP.deleteWorkout({
54+
workoutId: workoutId,
55+
jwtToken: STATE.authUser.jwtToken,
56+
onSuccess: () => {
57+
// Step 4: If succesful, reload the workouts list
58+
alert('Workout deleted succesfully, reloading results ...');
59+
HTTP.getUserWorkouts({
60+
jwtToken: STATE.authUser.jwtToken,
61+
onSuccess: RENDER.renderWorkoutsList
62+
});
63+
}
64+
});
65+
}
66+
}
67+
68+
function updateAuthenticatedUI() {
69+
const authUser = CACHE.getAuthenticatedUserFromCache();
70+
if (authUser) {
71+
STATE.authUser = authUser;
72+
$('#nav-greeting').html(`Welcome, ${authUser.name}`);
73+
$('#auth-menu').removeAttr('hidden');
74+
} else {
75+
$('#default-menu').removeAttr('hidden');
76+
}
77+
}

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ <h3>Coming Soon</h3>
7373
<script src="/utilities/cache.module.js"></script>
7474
<script src="/utilities/http.module.js"></script>
7575
<script src="/utilities/index.js"></script>
76+
<script src="/home.js"></script>
7677

7778

7879

public/login.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ <h1>Sign into your account</h1>
5353
<script src="/utilities/index.js"></script>
5454
<script src="/auth.page.js"></script>
5555
<script src="/search.js"></script>
56+
<script src="/home.js"></script>
5657

5758
</body>
5859

public/signup.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
<section class="container js-container">
2020
<div class="login-page">
2121
<h1 class="log-logo">
22-
<a href="/">Fit-Journal</a>
22+
<a href="/">Fit-Journal</a>
2323
</h1>
2424
<div class="form">
2525

2626
<h1>Create Free Account</h1>
27-
<form id="sign-up-form" class="signup-form" action="/api/user" method="POST">
28-
27+
<form id="sign-up-form" class="signup-form" action="/api/user" method="POST">
28+
2929
<input class="item" id="name-txt" type="text" placeholder="name" name="name" autocomplete="off" required/>
3030
<input class="item" id="username-txt" type="text" placeholder="username" name="username" autocomplete="off" required/>
31-
<input class="item" id="password-txt" type="password" placeholder="password" name="password" autocomplete="off" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters" required/>
31+
<input class="item" id="password-txt" type="password" placeholder="password" name="password" autocomplete="off" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters"
32+
required/>
3233
<input class="item" id="email-txt" type="text" placeholder="email address" name="email" autocomplete="off" />
3334
<button class="login-btn" type="submit">Register</button>
3435
<p class="message">Already registered? <a href="./login.html">Sign In</a></p>
@@ -37,10 +38,10 @@ <h1>Create Free Account</h1>
3738
</div>
3839
</section>
3940
</main>
40-
<footer>
41+
<footer>
4142
<div class="foot-col">
4243
<p>Fit-Journal website created by Ernest L. Phillips &copy; 2019 </p>
43-
44+
4445
</div>
4546
</footer>
4647
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
@@ -52,7 +53,8 @@ <h1>Create Free Account</h1>
5253
<script src="/utilities/index.js"></script>
5354
<script src="/dashboard.page.js"></script>
5455
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>
55-
56+
<script src="/home.js"></script>
57+
5658
</body>
5759

5860
</html>

0 commit comments

Comments
 (0)