web: get all thoughts, user page
@@ -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);
|
||||
|
||||
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');
|
||||
res.status(200).jsonp(thoughts);
|
||||
console.log(array);
|
||||
res.status(200).jsonp(array);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
web/img/icons/animals/bat.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
web/img/icons/animals/beetle.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
web/img/icons/animals/bulldog.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
web/img/icons/animals/butterfly.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
web/img/icons/animals/camel.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
web/img/icons/animals/cat.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
web/img/icons/animals/chameleon.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
web/img/icons/animals/clown-fish.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
web/img/icons/animals/cobra.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
web/img/icons/animals/cow.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
web/img/icons/animals/crab.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
web/img/icons/animals/crocodile.png
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
web/img/icons/animals/duck.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
web/img/icons/animals/elephant.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
web/img/icons/animals/frog.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
web/img/icons/animals/giraffe.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
web/img/icons/animals/hen.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
web/img/icons/animals/hippopotamus.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
web/img/icons/animals/kangaroo.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
web/img/icons/animals/lion.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
web/img/icons/animals/llama.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
web/img/icons/animals/macaw.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
web/img/icons/animals/monkey.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
web/img/icons/animals/moose.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
web/img/icons/animals/mouse.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
web/img/icons/animals/octopus.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
web/img/icons/animals/ostrich.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
web/img/icons/animals/owl.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
web/img/icons/animals/panda.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
web/img/icons/animals/pelican.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
web/img/icons/animals/penguin.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
web/img/icons/animals/pig.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
web/img/icons/animals/rabbit.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
web/img/icons/animals/racoon.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
web/img/icons/animals/ray.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
web/img/icons/animals/rhinoceros.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
web/img/icons/animals/sea-cow.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
web/img/icons/animals/shark.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
web/img/icons/animals/sheep.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
web/img/icons/animals/siberian-husky.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
web/img/icons/animals/sloth.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
web/img/icons/animals/snake.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
web/img/icons/animals/spider.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
web/img/icons/animals/squirrel.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
web/img/icons/animals/swan.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
web/img/icons/animals/tiger.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
web/img/icons/animals/toucan.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
web/img/icons/animals/turtle.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
web/img/icons/animals/whale.png
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
64
web/index.html
Normal file
@@ -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
web/index.js
Normal file
@@ -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
web/own.css
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
62
web/userpage.html
Normal file
@@ -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>
|
||||