Browse Source

web: get all thoughts, user page

master
nau 8 years ago
parent
commit
0278360eeb
57 changed files with 283 additions and 5 deletions
  1. +43
    -3
      controllers/thoughtController.js
  2. +20
    -1
      controllers/userController.js
  3. +4
    -1
      server.js
  4. BIN
      web/img/icons/animals/anteater.png
  5. BIN
      web/img/icons/animals/bat.png
  6. BIN
      web/img/icons/animals/beetle.png
  7. BIN
      web/img/icons/animals/bulldog.png
  8. BIN
      web/img/icons/animals/butterfly.png
  9. BIN
      web/img/icons/animals/camel.png
  10. BIN
      web/img/icons/animals/cat.png
  11. BIN
      web/img/icons/animals/chameleon.png
  12. BIN
      web/img/icons/animals/clown-fish.png
  13. BIN
      web/img/icons/animals/cobra.png
  14. BIN
      web/img/icons/animals/cow.png
  15. BIN
      web/img/icons/animals/crab.png
  16. BIN
      web/img/icons/animals/crocodile.png
  17. BIN
      web/img/icons/animals/duck.png
  18. BIN
      web/img/icons/animals/elephant.png
  19. BIN
      web/img/icons/animals/frog.png
  20. BIN
      web/img/icons/animals/giraffe.png
  21. BIN
      web/img/icons/animals/hen.png
  22. BIN
      web/img/icons/animals/hippopotamus.png
  23. BIN
      web/img/icons/animals/kangaroo.png
  24. BIN
      web/img/icons/animals/lion.png
  25. BIN
      web/img/icons/animals/llama.png
  26. BIN
      web/img/icons/animals/macaw.png
  27. BIN
      web/img/icons/animals/monkey.png
  28. BIN
      web/img/icons/animals/moose.png
  29. BIN
      web/img/icons/animals/mouse.png
  30. BIN
      web/img/icons/animals/octopus.png
  31. BIN
      web/img/icons/animals/ostrich.png
  32. BIN
      web/img/icons/animals/owl.png
  33. BIN
      web/img/icons/animals/panda.png
  34. BIN
      web/img/icons/animals/pelican.png
  35. BIN
      web/img/icons/animals/penguin.png
  36. BIN
      web/img/icons/animals/pig.png
  37. BIN
      web/img/icons/animals/rabbit.png
  38. BIN
      web/img/icons/animals/racoon.png
  39. BIN
      web/img/icons/animals/ray.png
  40. BIN
      web/img/icons/animals/rhinoceros.png
  41. BIN
      web/img/icons/animals/sea-cow.png
  42. BIN
      web/img/icons/animals/shark.png
  43. BIN
      web/img/icons/animals/sheep.png
  44. BIN
      web/img/icons/animals/siberian-husky.png
  45. BIN
      web/img/icons/animals/sloth.png
  46. BIN
      web/img/icons/animals/snake.png
  47. BIN
      web/img/icons/animals/spider.png
  48. BIN
      web/img/icons/animals/squirrel.png
  49. BIN
      web/img/icons/animals/swan.png
  50. BIN
      web/img/icons/animals/tiger.png
  51. BIN
      web/img/icons/animals/toucan.png
  52. BIN
      web/img/icons/animals/turtle.png
  53. BIN
      web/img/icons/animals/whale.png
  54. +64
    -0
      web/index.html
  55. +89
    -0
      web/index.js
  56. +1
    -0
      web/own.css
  57. +62
    -0
      web/userpage.html

+ 43
- 3
controllers/thoughtController.js

@ -2,13 +2,53 @@
var mongoose = require('mongoose');
var thoughtModel = mongoose.model('thoughtModel');
var userModel = mongoose.model('userModel');
//GET - Return all tvshows in the DB
exports.findAllThoughts = function(req, res) {
thoughtModel.find(function(err, thoughts) {
if(err) res.send(500, err.message);
if(err) res.send(500, err.message);
console.log(thoughts.length);
thoughts=JSON.parse(JSON.stringify(thoughts));
thoughts.forEach(function(thought, index, array){
array=JSON.parse(JSON.stringify(array));
userModel.find({
username: thought.authorname
}, function(err, user) {
if (err) throw err;
if (!user) {
} else if (user) {
/*console.log(thought);
console.log(user);*/
array[index].usericon=user[0].icon;
console.log("icon: " + array[index].usericon);
//thought.set('icon', user.icon);
//console.log(thought);
}
if(index === array.length-1)
{
console.log('GET /thoughts');
console.log(array);
res.status(200).jsonp(array);
}
});
});
console.log('GET /thoughts');
res.status(200).jsonp(thoughts);
});
};

+ 20
- 1
controllers/userController.js

@ -22,7 +22,7 @@ exports.findAllUsers = function(req, res) {
//GET - Return a TVShow with specified ID
exports.findById = function(req, res) {
ActivityModel.findById(req.params.id, function(err, user) {
userModel.findById(req.params.id, function(err, user) {
if(err) return res.send(500, err.message);
console.log('GET /users/' + req.params.id);
@ -30,6 +30,25 @@ exports.findById = function(req, res) {
});
};
exports.findUserByUsername = function(req, res) {
userModel.find({
username: req.params.username
}, function(err, user) {
if (err) throw err;
if (!user) {
res.json({ success: false, message: 'no user found' });
} else if (user) {
console.log(user);
// return the information including token as JSON
res.jsonp(user);
}
});
};
//POST - Insert a new TVShow in the DB
exports.addUser = function(req, res) {

+ 4
- 1
server.js

@ -46,6 +46,10 @@ var apiRoutes = express.Router();
apiRoutes.route('/users')
.get(userCtrl.findAllUsers)
.post(userCtrl.addUser);
apiRoutes.route('/users/:id')
.get(userCtrl.findById);
apiRoutes.route('/users/byusername/:username')
.get(userCtrl.findUserByUsername);
apiRoutes.route('/thoughts/user/:userid')
.get(thoughtCtrl.findAllThoughtsFromUsername);
@ -91,7 +95,6 @@ apiRoutes.use(function(req, res, next) {
});
apiRoutes.route('/users/:id')
.get(userCtrl.findById)
.put(userCtrl.updateActivity)
.delete(userCtrl.deleteActivity);

BIN
web/img/icons/animals/anteater.png

Before After
Width: 512  |  Height: 512  |  Size: 8.1 KiB

BIN
web/img/icons/animals/bat.png

Before After
Width: 512  |  Height: 512  |  Size: 10 KiB

BIN
web/img/icons/animals/beetle.png

Before After
Width: 512  |  Height: 512  |  Size: 16 KiB

BIN
web/img/icons/animals/bulldog.png

Before After
Width: 512  |  Height: 512  |  Size: 17 KiB

BIN
web/img/icons/animals/butterfly.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
web/img/icons/animals/camel.png

Before After
Width: 512  |  Height: 512  |  Size: 13 KiB

BIN
web/img/icons/animals/cat.png

Before After
Width: 512  |  Height: 512  |  Size: 17 KiB

BIN
web/img/icons/animals/chameleon.png

Before After
Width: 512  |  Height: 512  |  Size: 15 KiB

BIN
web/img/icons/animals/clown-fish.png

Before After
Width: 512  |  Height: 512  |  Size: 21 KiB

BIN
web/img/icons/animals/cobra.png

Before After
Width: 512  |  Height: 512  |  Size: 17 KiB

BIN
web/img/icons/animals/cow.png

Before After
Width: 512  |  Height: 512  |  Size: 21 KiB

BIN
web/img/icons/animals/crab.png

Before After
Width: 512  |  Height: 512  |  Size: 17 KiB

BIN
web/img/icons/animals/crocodile.png

Before After
Width: 512  |  Height: 512  |  Size: 8.7 KiB

BIN
web/img/icons/animals/duck.png

Before After
Width: 512  |  Height: 512  |  Size: 9.6 KiB

BIN
web/img/icons/animals/elephant.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
web/img/icons/animals/frog.png

Before After
Width: 512  |  Height: 512  |  Size: 15 KiB

BIN
web/img/icons/animals/giraffe.png

Before After
Width: 512  |  Height: 512  |  Size: 17 KiB

BIN
web/img/icons/animals/hen.png

Before After
Width: 512  |  Height: 512  |  Size: 12 KiB

BIN
web/img/icons/animals/hippopotamus.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
web/img/icons/animals/kangaroo.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
web/img/icons/animals/lion.png

Before After
Width: 512  |  Height: 512  |  Size: 17 KiB

BIN
web/img/icons/animals/llama.png

Before After
Width: 512  |  Height: 512  |  Size: 8.4 KiB

BIN
web/img/icons/animals/macaw.png

Before After
Width: 512  |  Height: 512  |  Size: 14 KiB

BIN
web/img/icons/animals/monkey.png

Before After
Width: 512  |  Height: 512  |  Size: 16 KiB

BIN
web/img/icons/animals/moose.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
web/img/icons/animals/mouse.png

Before After
Width: 512  |  Height: 512  |  Size: 10 KiB

BIN
web/img/icons/animals/octopus.png

Before After
Width: 512  |  Height: 512  |  Size: 21 KiB

BIN
web/img/icons/animals/ostrich.png

Before After
Width: 512  |  Height: 512  |  Size: 12 KiB

BIN
web/img/icons/animals/owl.png

Before After
Width: 512  |  Height: 512  |  Size: 15 KiB

BIN
web/img/icons/animals/panda.png

Before After
Width: 512  |  Height: 512  |  Size: 12 KiB

BIN
web/img/icons/animals/pelican.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
web/img/icons/animals/penguin.png

Before After
Width: 512  |  Height: 512  |  Size: 14 KiB

BIN
web/img/icons/animals/pig.png

Before After
Width: 512  |  Height: 512  |  Size: 13 KiB

BIN
web/img/icons/animals/rabbit.png

Before After
Width: 512  |  Height: 512  |  Size: 12 KiB

BIN
web/img/icons/animals/racoon.png

Before After
Width: 512  |  Height: 512  |  Size: 13 KiB

BIN
web/img/icons/animals/ray.png

Before After
Width: 512  |  Height: 512  |  Size: 12 KiB

BIN
web/img/icons/animals/rhinoceros.png

Before After
Width: 512  |  Height: 512  |  Size: 10 KiB

BIN
web/img/icons/animals/sea-cow.png

Before After
Width: 512  |  Height: 512  |  Size: 7.5 KiB

BIN
web/img/icons/animals/shark.png

Before After
Width: 512  |  Height: 512  |  Size: 9.5 KiB

BIN
web/img/icons/animals/sheep.png

Before After
Width: 512  |  Height: 512  |  Size: 10 KiB

BIN
web/img/icons/animals/siberian-husky.png

Before After
Width: 512  |  Height: 512  |  Size: 19 KiB

BIN
web/img/icons/animals/sloth.png

Before After
Width: 512  |  Height: 512  |  Size: 15 KiB

BIN
web/img/icons/animals/snake.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
web/img/icons/animals/spider.png

Before After
Width: 512  |  Height: 512  |  Size: 20 KiB

BIN
web/img/icons/animals/squirrel.png

Before After
Width: 512  |  Height: 512  |  Size: 14 KiB

BIN
web/img/icons/animals/swan.png

Before After
Width: 512  |  Height: 512  |  Size: 12 KiB

BIN
web/img/icons/animals/tiger.png

Before After
Width: 512  |  Height: 512  |  Size: 22 KiB

BIN
web/img/icons/animals/toucan.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
web/img/icons/animals/turtle.png

Before After
Width: 512  |  Height: 512  |  Size: 20 KiB

BIN
web/img/icons/animals/whale.png

Before After
Width: 512  |  Height: 512  |  Size: 9.2 KiB

+ 64
- 0
web/index.html

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>thoughts - main</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="own.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body onload='OnLoadIndex()'>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Thoughts</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="crearActivity.html">Users</a></li>
<li><a href="editActivities.html">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</div>
</nav>
<div class='container'>
<div id='listThoughtsHtml'></div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="index.js"></script>
</body>
</html>

+ 89
- 0
web/index.js

@ -0,0 +1,89 @@
var listThoughts;
var urlapi = "http://localhost:3000/api";
function OnLoadIndex(){
listThoughts=getAllThoughts();
}
function getAllThoughts(){
$.ajax({
type: "GET",
dataType: "json",
url: urlapi + "/thoughts",
success: function(data){
listThoughts=data;
document.getElementById('listThoughtsHtml').innerHTML=generateHtmlListThoughts();
}
});
}
function generateHtmlListThoughts(){
var html="";
html+="<div class='list'>";
html+="</div>";
html+="<ul class='list-group'>";
for(var i=0; i<listThoughts.length; i++)
{
html+=" <li class='list-group-item'>";
html+="<img src='"+listThoughts[i].usericon+"' width='30px' />";
html+="<a href='/userpage.html?value="+listThoughts[i].authorname+"'>" + listThoughts[i].authorname + ":</a>";
html+="<br>";
html+= listThoughts[i].content;
html+="</li>";
}
html+="</ul>";
return(html);
}
/*
##############################
userpage.html
##############################
*/
function OnLoadUserPage(){
var username=window.location.href.split("?value=")[1];
$.ajax({
type: "GET",
dataType: "json",
url: urlapi + "/users/byusername/" + username,
success: function(data){
document.getElementById('userpagehtml').innerHTML=generateHtmlUserPage(data[0]);
}
});
}
function generateHtmlUserPage(user){
var html="";
html+="<div class='well'>";
html+="<h3>" + user.username + "</h3>";
html+="description: " + user.description;
html+="<br>mail: " + user.mail;
html+="";
html+="";
html+="";
html+="</div>";
return(html);
}

+ 1
- 0
web/own.css

@ -0,0 +1 @@

+ 62
- 0
web/userpage.html

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>thoughts - main</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="own.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body onload='OnLoadUserPage()'>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Thoughts</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="index.html">Home</a></li>
<li><a href="crearActivity.html">Users</a></li>
<li><a href="editActivities.html">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</div>
</nav>
<div class='container'>
<div id='userpagehtml'></div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="index.js"></script>
</body>
</html>

Loading…
Cancel
Save