web: get all thoughts, user page

This commit is contained in:
nau
2016-07-17 20:44:45 +02:00
parent 1ba5d059e1
commit 0278360eeb
57 changed files with 284 additions and 6 deletions

View File

@@ -2,13 +2,53 @@
var mongoose = require('mongoose'); var mongoose = require('mongoose');
var thoughtModel = mongoose.model('thoughtModel'); var thoughtModel = mongoose.model('thoughtModel');
var userModel = mongoose.model('userModel');
//GET - Return all tvshows in the DB //GET - Return all tvshows in the DB
exports.findAllThoughts = function(req, res) { exports.findAllThoughts = function(req, res) {
thoughtModel.find(function(err, thoughts) { 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('GET /thoughts');
res.status(200).jsonp(thoughts); console.log(array);
res.status(200).jsonp(array);
}
});
});
}); });
}; };

View File

@@ -22,7 +22,7 @@ exports.findAllUsers = function(req, res) {
//GET - Return a TVShow with specified ID //GET - Return a TVShow with specified ID
exports.findById = function(req, res) { 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); if(err) return res.send(500, err.message);
console.log('GET /users/' + req.params.id); 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 //POST - Insert a new TVShow in the DB
exports.addUser = function(req, res) { exports.addUser = function(req, res) {

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

64
web/index.html Normal file
View 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
View 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
View File

@@ -0,0 +1 @@

62
web/userpage.html Normal file
View 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>