Skip to content
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
39 changes: 37 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ const userRoutes = require('./routes/users'),
const app = express();
userStore = require('./user-reader');



var likeStore;

fs.readFile('likes.json', function (err, data) {
if (err) return console.error(err);
likeStore = (JSON.parse(data));
});


app.use(express.static('public'));

app.set('view engine', 'pug');

app.use(express.static('./public'));

app.use(morgan('dev'));

app.use(bodyParser.urlencoded({ extended: false }));
Expand All @@ -36,6 +44,33 @@ app.get('/api/search/*', (req, res) => {
res.json(results);
});

app.post('/like', (request, response) => {
if(!likeStore.clicked){
likeStore.likeCount = likeStore.likeCount + 1;
likeStore.clicked = true;
}

response.json(likeStore);

fs.writeFile('likes.json', JSON.stringify(likeStore), (error, data) => {
if (error) {
throw error;
}

console.log('new likeCount added to likes.json');
});
});

app.get('/:lastname', (req, res) => {
show1 = userStore.searchUsers(req.params.lastname);
console.log('did this part run?');
console.log(show1[0]);
console.log(show1[0].lastname);
res.render('show-1-user', {user: show1[0]});
//res.redirect('/'+ show1[0].lastname);

});


app.listen(3000, function() {
console.log('Web server started on port 3000');
Expand Down
1 change: 1 addition & 0 deletions likes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"likeCount":1,"clicked":true}
22 changes: 20 additions & 2 deletions public/js/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
$('.jl-like-button').on('click', function() {
$.post('/like', function(data) {
$('.jl-like-button').text('LIKES: ' + data.likeCount);
console.log(data.likeCount);
console.log('like finsihed');

});
});

$('#search-button input').on('keyup', function() {
var query = $('#search-button input').val();
Expand All @@ -9,10 +16,21 @@ $('#search-button input').on('keyup', function() {
console.log(data);
$(".jl-app-search-results").html('');
data.forEach(function(element) {
console.log (element);
$(".jl-app-search-results").append(
$("<li>" + element.firstname + ' ' + element.lastname + '</li>')
);
$("<li data-surname="+"'"+element.lastname+"'"+">"+element.firstname + ' ' + element.lastname + "</li>")
);
});
});
}
});

console.log("YESSSSAPPENED!");

$(".jl-app-search-results").click(function(e) {
var lastname = (e.target).getAttribute("data-surname");

$.get('/'+lastname, function(data) {
window.location.href = '/'+ lastname;
});
});
7 changes: 6 additions & 1 deletion user-reader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const fs = require('fs');

const users = JSON.parse(fs.readFileSync('users.json'));
var users;

fs.readFile('users.json', function (err, data) {
if (err) return console.error(err);
users = (JSON.parse(data));
});

module.exports = {

Expand Down
2 changes: 1 addition & 1 deletion users.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"firstname":"Alexandre","lastname":"Marjan","email":"a.marjan@gmail.com"},{"firstname":"Ulysses","lastname":"Silvio","email":"silverspoon87@gmail.com"},{"firstname":"Viktor","lastname":"Gul","email":"viktor.rose@gmail.com"},{"firstname":"Kamalani","lastname":"Georgy","email":"georgy.porgy@gmail.com"},{"firstname":"Jessica","lastname":"Leach","emailAddress":"jessicamaryleach@gmail.com"},{"firstname":"johny","lastname":"falco","emailAddress":"j_falco@yahoo.com"},{"firstname":"Kelvedon ","lastname":"Packard","emailAddress":"K.Packard@PrivateInvestigations.biz"},{"firstname":"JIMBO","lastname":"Hoskins","emailAddress":"jh@yahoo.org"},{"firstname":"pete","lastname":"grimes","emailAddress":"p-man@thestudio.io"},{"firstname":"emily","lastname":"waggley","email":"em_W@hotmail.com"}]
[{"firstname":"Alexandre","lastname":"Marjan","email":"a.marjan@gmail.com"},{"firstname":"Ulysses","lastname":"Silvio","email":"silverspoon87@gmail.com"},{"firstname":"Jan","lastname":"Van der boot","email":"j.vdboot@gmail.com"},{"firstname":"Viktor","lastname":"Gul","email":"viktor.rose@gmail.com"},{"firstname":"Kamalani","lastname":"Georgy","email":"georgy.porgy@gmail.com"},{"firstname":"Jessica","lastname":"Leach","emailAddress":"jessicamaryleach@gmail.com"},{"firstname":"johny","lastname":"falco","emailAddress":"j_falco@yahoo.com"},{"firstname":"Kelvedon ","lastname":"Packard","emailAddress":"K.Packard@PrivateInvestigations.biz"},{"firstname":"JIMBO","lastname":"Hoskins","emailAddress":"jh@yahoo.org"},{"firstname":"pete","lastname":"grimes","emailAddress":"p-man@thestudio.io"},{"firstname":"emily","lastname":"waggley","email":"em_W@hotmail.com"},{"firstname":"","lastname":"","email":""},{"firstname":"sonia","lastname":"leach","email":"s.leach40@ntlworld.com"}]
1 change: 1 addition & 0 deletions views/application.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ html
body
nav(class="navbar navbar-light bg-faded")
a(class="navbar-brand" href="/") User Information Application
button(type="button" class="btn btn-success jl-like-button") Like this app
ul.nav.navbar-nav.float-xs-right
li.nav-item
a(class="navbar-text" href="/add-user") NEW USER
Expand Down
3 changes: 2 additions & 1 deletion views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ block content
hr
each user in users
.card.card-block
h4(class="card-title")= user.firstname + " " + user.lastname
a(href="/" + user.lastname)
h4(class="card-title")= user.firstname + " " + user.lastname
p(class="card-text")= "Email: " + user.email
19 changes: 9 additions & 10 deletions views/search/search-users.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ extends ../application

block content
.container
.container
.row
.col-xs-6.col-xs-offset-3
h1 Search for a user:
.row
.col-xs-6.col-xs-offset-3
h1 Search for a user:

form(action="/search" method="POST" class="form-inline float-xs-right" id="search-button")
.form-group
label(for="search") Search
input(name="query" class="form-control" )
button(type="Submit" class="btn btn-info" style="margin-top: 200px") Submit
ul.jl-app-search-results
form(action="/search" method="POST" id="search-button" autocomplete="off")
.form-group
label(for="search") Search
input(name="query" class="form-control" autocomplete="off")
button(type="Submit" class="btn btn-info" style="margin-top: 200px") Submit
ul.jl-app-search-results
3 changes: 2 additions & 1 deletion views/search/show-results.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ block content
if results
each result in results
.card.card-block
h4(class="card-title")= result.firstname + " " + result.lastname
a(href="/" + result.lastname)
h4(class="card-title")= result.firstname + " " + result.lastname
p(class="card-text")= "Email: " + result.email
else
h4 User is not found
6 changes: 6 additions & 0 deletions views/show-1-user.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends ./application.pug
block content
.container
.card.card-block
h4(class="card-title")= user.firstname + " " + user.lastname
p(class="card-text")= "Email: " + user.email
4 changes: 2 additions & 2 deletions views/users/add-user.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ block content
.form-group
label(for="firstname") Full Name
input(name="firstname" type="text" id="firstname" class="form-control" placeholder="Joanna")
.form-group

label(for="lastname") Full Name
input(name="lastname" type="text" id="lastname" class="form-control" placeholder="Newton")
.form-group

label(for="email") Email address
input(name="email" type="email" id="email" class="form-control" placeholder="joannanewton@yahoo.com")

Expand Down