userinfo ausgeben

This commit is contained in:
Lukas Nowy 2018-11-20 23:32:20 +01:00
parent 0ba4a11d23
commit 4421f6b307
3 changed files with 44 additions and 25 deletions

View File

@ -1,6 +1,8 @@
$(document).ready(function() {
refresh();
userinfo();
$(document).on("click", ".btn_detail", function() {
window.location.replace("/shoppinglist_json/" + $(this).closest("tr").attr("id"));
});
@ -29,32 +31,44 @@ $(document).ready(function() {
}
});
});
});
function refresh() {
function refresh() {
$("tbody").empty();
$("tbody").empty();
$.ajax({
type: "GET",
url: "/myshoppinglists",
success(data) {
for(let item of data) {
$(".tb_myshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td>"
+ "<td><a class='btn-floating btn-large waves-effect waves-light red btn_delete'><i class='material-icons'>clear</i></a></td></tr>");
}
$.ajax({
type: "GET",
url: "/myshoppinglists",
success(data) {
for(let item of data) {
$(".tb_myshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td>"
+ "<td><a class='btn-floating btn-large waves-effect waves-light red btn_delete'><i class='material-icons'>clear</i></a></td></tr>");
}
});
$.ajax({
type: "GET",
url: "/sharedshoppinglists",
success(data) {
for(let item of data) {
$(".tb_sharedshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td></tr>");
}
}
});
$.ajax({
type: "GET",
url: "/sharedshoppinglists",
success(data) {
for(let item of data) {
$(".tb_sharedshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td></tr>");
}
});
}
});
}
});
}
function userinfo() {
$.ajax({
type: "GET",
url: "/userinfo_json",
success(data) {
$(".userinfo").empty();
$(".userinfo").append("Logged in as: " + data.profile.displayName);
$(".user_img").attr("src", data.profile.photos[0].value);
}
});
}

View File

@ -134,4 +134,8 @@ router.get("/test1", (req, res) => {
res.render("index1");
});
router.get("/userinfo_json", (req, res) => {
res.send(req.session.passport.user);
});
module.exports = router;

View File

@ -12,7 +12,8 @@
<body>
<div class="container">
<p>Logged in as: testuser1</p>
<p class="userinfo">Logged in as: testuser1</p>
<img class="user_img">
<br>
<div class="col s6">
<a href="/logout" class="waves-effect waves-light btn">Logout</a>